If you have an if() and a spawn() on the same line, and then the following three lines are an if, an else if, and then either an else or else if, you get an error on the third line. My guess is that if it finds "if(1) spawn()" in a line and the next line is an "if", it treats the first "else" as the end of the conditional statement deal, and doesn't know what to do with the second one.
The workaround is simple. Move the spawn() to its own line, as shown below.
Numbered Steps to Reproduce Problem:
Copy the code from the second code block below into Dream Maker and compile it. You'll get a false "Else without if" error on the first procedure, but not the second.
Code Snippet (if applicable) to Reproduce Problem:
Here's my exact code from my project, but I'm still posting simplified test code that I have proven through testing to do the exact same thing. (Honestly I see no reason to look at this first code block, but if I don't post this, you'll ask for it for some reason.)
mob/var/status = ""
proc/StatusUpdater()
for(var/mob/M in world) if(M.client) spawn()
var/bar = winget(M, "MainWindow.input", "text")
if(bar == "" || bar == "Say \"" || bar == "Emote \"") M.status = ""
else if(findtext(bar,"Say",1,4) || findtext(bar,"Emote",1,6) ) M.status = "Typing..."
else if(1) M.status = "" //This line gives the error" Source.dm: 388: error: else: 'else' clause without preceding 'if' statement."
if(M.client.inactivity >= 6000) M.status = "Idle"
I then stripped out a bunch of stuff and got this, which also gives the same error:
//If I put this whole block into an empty Dream Maker environment and compile, I get a single error on line seven.
proc/SIMPLER_ERROR()
if(1) spawn()
if(1)
else if(2) return
else return //"'else' clause without preceding 'if' statement" error here
//But if I move the spawn() to its own line, the following code will compile without error:
proc/SIMPLER_FINE()
if(1)
spawn()
if(1)
else if(2) return
else return
Expected Results:
Both procedures in the second code block should compile fine and do the exact same thing.
Actual Results:
One of them gives a syntax error when you compile.
Does the problem occur:
Every time? Or how often?
Every time.
In other games?
Untested.
In other user accounts?
Untested.
On other computers?
Untested.
When does the problem NOT occur?
When you put the spawn() on its own line.
Did the problem NOT occur in any earlier versions? If so, what was the last version that worked?
It did it on 481. I updated to make sure it wasn't fixed.
Workarounds:
Put spawn() on its own line, as in SIMPLER_FINE.