Community
SCI Programming => SCI Syntax Help => Topic started by: claudehuggins on October 28, 2016, 09:27:51 AM
-
(Or as I like to call them, IFFues.... Okay, okay, that was lame.)
I'm flat-out stumped by why this is detected as a problem.
When writing code for a class I want to define, I wanted a method containing an IF/ELSE statement.
I'm not on the correct computer to provide the actual code, so I'll do my best to recreate it as helpfully as possible in a quick pseudocode fashion...
(class MyClass of DCIcon ;for example's sake
(properties)
(method (init)
(var myVariable) ;included in case this was messing it up, but I don't know why it would
(if (condition) ;yadda yadda expression goes there
;thing happens...
)(else
;other thing happens...
) ;end else
) ;end method
) ;end class
(Let me know if this is too vague and I'll try to post my actual code when I get the chance)
The issue with this code is that when compiling, I'm told the line containing "else" should be an expression. Apparently, I can't use "else" there.
....Why not? I may just be missing something obvious, but isn't this the correct usage of "else"?
I'm using Sierra syntax, if that helps.
-
In the Sierra syntax you don't close and reopen the clause before writing the else. Try this:
(if (condition) ;yadda yadda expression goes there
;thing happens...
else
;other thing happens...
) ;end else
see:
http://scicompanion.com/Documentation/Compiler/if.html
-
Hey hey! Thanks :D
I feel like deep down I already knew this...but I had rewritten that particular method from a tutorial/sample that was written in Studio syntax, so I'm guessing I just overlooked it while rewriting it.
I'll make the fix when I'm back on my work computer and see if the script will behave itself now :P
EDIT: I managed to get on my computer and try this out. It fixed the issue, but I discovered numerous other instances where studio>sierra conversion didn't work out quite right, or I missed some weird parenthesis placement, etc.
I fixed all of these and the entire script now works fully as intended :)
Goodness, that was confusing, though. I guess I'm letting myself get out of practice since art is my main focus for games right now, and I haven't used studio syntax at all ever since I was advised to switch to sierra. I don't regret the transition though; sierra syntax is a lot easier for me to parse when skimming code. Keeps the headaches at bay.