Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Multiple properties stored in a variable

<<set $Woodensword to ["Wooden Sword",10]>>
Like an array, i know i can store more than one piece of information and i know printing this variable will in fact show "Wooden Sword 10". But i was wonder if could specifically call up the number part, like.
<<set $TestE to 25>> <<print $TestE>>
<<set $TestE to $TestE - $Woodensword>>
$TestE
and that would subtract the 10 from 25 but I don't think that is how it works. I toyed with object class variables in java script but I don't quite know how they work either.
Any suggestions would be great.

Comments

  • edited March 2017
    <<set $TestF = 20>>
    
    <<print $TestF>>
    
    <<set $Weapon = {Name:"Sword", Material:"Wood",Damage:10}>>
    
    <<set $TestF to $TestF - $Weapon.Damage>>
    
    <<print $TestF>>
    

    Figured it out, who knew the solution was so simple.
  • var person = {
        firstname:("John","Pie","Poise")
        lastname:"Doe",
        age:50,
        eyecolor:"blue"
    };
    
    That brings mean to a new problem, How can i have the values inside the var randomized... will post if i figure out.
  • You should always state the story format you're using and its version, because advice will tend to vary based on that information.

    Since you posted this thread to the Help! with 2.0 category, I'm going to assume you're using some version of SugarCube, since it's the only story format available for Twine 2 with that syntax—though that still leaves its version unknown.


    I'm going to assume you're asking about how to pick a random name for the firstname property. You may do so with the either() function:
        firstname: either("John", "Pie", "Poise"),
    
    Or with the <Array>.random() function:
        firstname: ["John", "Pie", "Poise"].random(),
    
  • edited March 2017
    @TheMadExile
    Yeah thanks that definitely answered my Question, and yeah I should be posting versions. (I did that for the first two threads I made and forgot on this one, my bad),
Sign In or Register to comment.