Login
Remember
IF Answers
Ask a Question

# 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?

- squiffy
- programming

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

## Related questions

- Squiffy: How to force two variables to equal based off another variable?
- How to compare two variables in Squiffy?
- Squiffy: Interaction between objects
- Random text in Squiffy
- Is there a way to turn Squiffy passage links into a regular link for accessibility purposes?

...