How to format Lua on this forum

I just found something extremely useful that will make pasted lua code much more readable on this forum:

i=1
print("hello"..i)
if (Player_IsAlive(playerIndex) == 1 and Player_HasShipWithBuildQueue(playerIndex) == 0) then
		Player_Kill(playerIndex)
		if playerIndex ~= Universe_CurrentPlayer() then
				local playerNameW = Player_GetName(playerIndex)								
				Sound_SpeechPlay("data:sound\\speech\\missions\\m_15\\47100")
				Player_AddLocalChatMessage("$1231", playerNameW);
		end
end

This is done using

```lua
[Your code]
```
5 Likes
if coolness > 9000 then
      print("Good find!")
else
      :sadface:
end 
5 Likes

Why didn’t your print go blue?

print("this print statement is on its own")

Perhaps because of indentation:

if true then
    print("this print statement is indented")
end

Or 6 character indentation instead of 4:

if true then
      print("this print statement is indented 6 spaces")
end

…or not!

1 Like

It seems to be because of my attempt at an icon, the “:” disrupts the formatting somehow…

2 Likes

Just using the code tags does the same thing.

EG use [code] ... [/code] gives:

i=1
print("hello"..i)
if (Player_IsAlive(playerIndex) == 1 and Player_HasShipWithBuildQueue(playerIndex) == 0) then
		Player_Kill(playerIndex)
		if playerIndex ~= Universe_CurrentPlayer() then
				local playerNameW = Player_GetName(playerIndex)								
				Sound_SpeechPlay("data:sound\\speech\\missions\\m_15\\47100")
				Player_AddLocalChatMessage("$1231", playerNameW);
		end
end
5 Likes