Squiffy: Extracting Data From Objects Variables.

0 votes
139 views
asked Jun 3 in Authoring by Natas (17 points)

I have lately been looking at questions asked by people who have been using Squiffy to create their projects. It seems that Objects are the hot topic of the week. My question can be viewed here. Simply copy and paste into the Squiffy Scratchpad (http://docs.textadventures.co.uk/squiffy/scratchpad/):

    function item(name, amount, type, returnAmount, descri){
        this.name = name;
        this.itemAmount = amount;
        this.type = type; 
        this.returnVaule = returnAmount; 
        this.description = descri; 
    }

    function person(name, hp, dex, str){ 
        this.name = name; 
        this.healthPoints = hp; 
        this.dexPoints = dex;
        this.strPoints = str;
    }

    var self = new person("You", 10, 5, 5)

    var other = new person("Other Guy", 20, 8, 8)

    var healthPotion = new item("Health Potion", 0, "potion", 5, "Heals you for five health points")

    var strengthPotion = new item("Strength Potion", 0, "potion", 3, "Adds three points of Strength for one point of Dexterity")

[Test]

[Test]: 
@clear

Viewing the this.name of self variable: 
[View](V1)

Viewing the this.healthPoints of self variable: 
[View](V2)

Viewing the two variables together: 
[View](V3)

[V1]: 
    alert(self.name)

[V2]: 
    alert(self.healthPoints)

[V3]:
@clear
    alert(self.name + " have " + self.healthPoints + " Health Tokens.")

How can I get self.name to appear here?

1 Answer

0 votes
answered Jun 4 by Alex (486 points)

You need to store data using attributes. In your example, you're only setting local variables. These will be discarded as soon as the script block finishes running.

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.
...