Author Topic: IF/ELSE Issues  (Read 2615 times)

0 Members and 1 Guest are viewing this topic.

Offline claudehuggins

IF/ELSE Issues
« 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...
Code: [Select]
(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.


A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".

Offline troflip

Re: IF/ELSE Issues
« Reply #1 on: October 28, 2016, 11:16:45 AM »
In the Sierra syntax you don't close and reopen the clause before writing the else. Try this:

Code: [Select]
(if (condition) ;yadda yadda expression goes there
;thing happens...
else
;other thing happens...
) ;end else

see:
http://scicompanion.com/Documentation/Compiler/if.html
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline claudehuggins

Re: IF/ELSE Issues
« Reply #2 on: October 28, 2016, 12:13:40 PM »
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.
« Last Edit: October 28, 2016, 01:28:50 PM by claudehuggins »
A while ago, at a block party I found myself socially trapped at, I thought to myself: I need a t-shirt that says, "I'd rather be programming".


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.057 seconds with 22 queries.