Javascript variables clearing

TangentialFox
Hello! Before I begin, I must say I'm not sure if this problem has been discussed or resolved previously, but to the best of my knowledge, I could not find anything regarding it.

The Problem: When using squiffy and transitioning to more sections, it appears previous javascript variables clear out! I am new to squiffy and its design, so I may be making a mistake.

To prove that its a problem, a simple example:

@start caption1
[[caption1]]:
var a = 1;
var b = 2;
squiffy.set("a",a);
squiffy.story.go("caption2")

[[caption2]]:
Some content text...<br>
[[Continue...]](caption3)

[[caption3]]:
squiffy.set("test","hello");
squiffy.set("b",b);
squiffy.story.go("caption4");

[[caption4]]:
Some text that will never be seen (error in caption3).


When the above code runs, all works fine, squiffy's "a" is set equal to 1, but when you try it again on "b" further down, it errors out, as if the javascript variable b never existed!

Is this intentional by squiffy's design? If so, is there a way to counter it? I'm trying to organize a game that involves objects with properties and methods (most declared upon start up of the game). I keep these variables in javascript for ease, but I know I could simply convert them to a squiffy attribute during the start up and it would resolve the issue.

Thanks in advanced for any help!

Alex
You're confusing JavaScript variables with Squiffy attributes. You have to set the attribute to be able to get it. In your code, in the "caption1" section you're only setting an attribute called "a". Your variable "b" isn't being saved.

TangentialFox
Thank you Alex! If I set the variable "b" equal to the Squiffy attribute "b" where "a" is set, it should work out fine.

The work I'm having problem with involves something such as this:


<!-- Room setup -->
[[setup]]:
function Room(desc, north, east, south, west) {
this.desc = desc;
this.north = north;
this.east = east;
this.south = south;
this.west = west;
}
var home = new Room("Your home is unique, a makeshift house built near the edge of the forest and ocean. Your happy to call it home, it took you a week to build it, fence and all!","Dark Woods","Ghost Town","Meadow","Beach");

var town = new Room("...");

<!-- When you eventually get to your home... -->
[[home]]:
squiffy.set("location","home");
squiffy.set("roomDesc",home.desc);
squiffy.set("roomNorth",home.north);
squiffy.set("roomEast",home.east);
squiffy.set("roomSouth",home.south);
squiffy.set("roomWest",home.west);

{roomDesc}<br>
You can go [[north ({roomNorth})]](travel,direction=north), [[west ({roomWest})]](travel,direction=west), [[south ({roomSouth})]](travel,direction=south), [[east ({roomEast})]](travel,direction=east). You are currently at {location}.

[[location]]:
//code to perform a function of where to travel based on current location and direction chosen.


So, in order to fix this, I'll need to assign var home here instead.


<!-- When you eventually get to your home... -->
[[home]]:
var home = {
desc:"Your home is unique, a makeshift house built near the edge of the forest and ocean. Your happy to call it home, it took you a week to build it, fence and all!",
north:"Dark Woods",
east:"Ghost Town",
south:"Meadow",
west:"Beach"
};

squiffy.set("location","home");
squiffy.set("roomDesc",home.desc);
squiffy.set("roomNorth",home.north);
squiffy.set("roomEast",home.east);
squiffy.set("roomSouth",home.south);
squiffy.set("roomWest",home.west);

You are currently at {location}.
{roomDesc}<br>
You can go [[north ({roomNorth})]](travel,direction=north), [[west ({roomWest})]](travel,direction=west), [[south ({roomSouth})]](travel,direction=south), [[east ({roomEast})]](travel,direction=east).


Thanks again Alex! It works perfectly!

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

Support

Forums