Squiffy: How to fix if else error?

0 votes
171 views
asked Apr 27 in Authoring by Natas (17 points)
if ( num1 < num2*0.10) {
     message = "poor" 
} else if ( etc ) { 
     etc 
} else {
    etc 
} 

The following is pseudo code that did not work well in practice. Is there some special way I must put if-else statements in Squiffy?

commented Apr 27 by Alex (486 points)
This needs more detail, what happens when you try it - any error messages? If you can give us an actual full example of a squiffy file that will help.
commented Apr 27 by Natas (17 points)
No the game doesnt load in the scratchpad. Assuming all the variables been globally defined how would I format an if then statement. It could be the number of tabs I am using.
commented Apr 28 by Alex (486 points)
We can't help unless we can see an example. The if statement in your question looks fine to me.
commented Apr 28 by Natas (17 points)
Here is an example of what I tried to enter in the scratchpad that made nothing appear:

 https://gist.githubusercontent.com/anonymous/6533eae86b8e955827ea/raw/55f83abc74fbfbe30343179cc82e47045da23b98/example

1 Answer

0 votes
answered Apr 28 by Alex (486 points)
selected Apr 28 by Natas
 
Best answer

If you run your example and open your browser's developer console, you'll see an error like this:

Uncaught ReferenceError: num1 is not defined

This is because to access Squiffy attributes from JavaScript, you need to use get. To set attributes, use set.

For example:

if ( get("num1") < get("num2")*0.20 ) {
    set("message", "poor");
} else if ( get("num1") < get("num2")*0.30 ) {
    set("message", "average");
} else { 
    set("message", "good");
}
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...