Re) Is it possible to display an attribute value inside an If statement? or to change its value?

http://textadventures.co.uk/forum/squiffy/topic/hjkkcuaazuua6mgiopofba/is-it-possible-to-display-an-attribute-value-inside-an-if-statement-or-to-change

Siddone's codes.

[[start]]:
    var greeting;
    var time = 1
    var message;
    if (time < 10) {
    greeting = "Good morning";
    } else if (time < 20) {
    greeting = "Good day";
    } else {
    greeting = "Good evening";
    }

    squiffy.set("squiffygreeting", greeting);

The output is: {squiffygreeting}<br>
{if squiffygreeting=Good morning:Good Morning indeed.<br> [[Exit 1]](uno).<br>}
{if squiffygreeting=Good day:Good day indeed.<br> [[Exit 2]](due).<br>}
{if squiffygreeting=Good evening:Good Evening indeed.<br> [[Exit 3]](tre).<br>}

[[uno]]:
Good Morning, I said.<br>
[[Ok]](quattro).

[[due]]:
Good Day, I said.<br>
[[Ok]](quattro).

[[tre]]:
Good Evening, I said.<br>
[[Ok]](quattro).

[[quattro]]:
So, let's move on.<br>

if (time < 10) {
message = "lesser than 10";
} else if (time < 20) {
message = "between 10 and 19";
} else {
message = "greater or equal to 20";
    }

squiffy.set("sqmessage", message);
squiffy.set("sqtime", time);

The value of time is {sqmessage}: in fact it is {sqtime}.

Answer 1) minium change to make it work

[[start]]:
    var time = 21
    var greeting;
    set("time",time);
    if (time < 10) {
        greeting = "Good morning";
    } else if (time < 20) {
        greeting = "Good day";
    } else {
        greeting = "Good evening";
    }

    squiffy.set("squiffygreeting", greeting);

The output is: {squiffygreeting}<br>
{if squiffygreeting=Good morning:Good Morning indeed.<br> [[Exit 1]](uno).<br>}
{if squiffygreeting=Good day:Good day indeed.<br> [[Exit 2]](due).<br>}
{if squiffygreeting=Good evening:Good Evening indeed.<br> [[Exit 3]](tre).<br>}

[[uno]]:
Good Morning, I said.<br>
[[Ok]](quattro).

[[due]]:
Good Day, I said.<br>
[[Ok]](quattro).

[[tre]]:
Good Evening, I said.<br>
[[Ok]](quattro).

[[quattro]]:
    var message;
    var time=get("time");
    if (time < 10) {
         message = "lesser than 10";
    } else if (time < 20) {
         message = "between 10 and 19";
    } else {
        message = "greater or equal to 20";
    }

    set("message", message);
    set("time", time);

The value of time is {message}: in fact it is {time}.

Answer 2) Only with nested-if-statement
(bug report!) Only browser version works well. Editor or command line version works wrong.

[[start]]:
@set time=1

{if time<10: Good morning. [[Exit]](uno)}
{else:{if time<20: Good day. [[Exit]](due)}
{else:Good evening [[Exit]](tre)}}

[[uno]]:
[[Ok]](quattro)

[[due]]:
[[Ok]](quattro)

[[tre]]:
[[Ok]](quattro)

[[quattro]]:
So, let's move on.<br>
The value of time is : 
{if time<10:lesser than 10}
{else:{if time<20:between 10 and 19}
{else:greater or equal to 20}}
in fact it is {time}.

This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums