Howdy, Stranger!

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

Object and Property Issue...

I'm using SugarCube 1.0.26. I'm making an IF with RP elements, and I'm having some issues using, printing, and changing properties. Here's my initial "character sheet":

<<set $player= {
name: "you",
age: "young",
height: "average",
build: "average",
hair: "brown",
eyes: "brown",
health: 4,
hygiene: 3,
hunger: 3,
}>>

I can't print (as in, if I added $player.name to the text, it just says "$player.name" instead of "you", or "$player.health" instead of "4"), change, or use conditionals based on those properties. Which at first made me wonder if I was defining them properly, or if the conditional I was using initially was for some reason registering false. Then things get interesting, since I also have this bit of code I added separately:

<<set $player= {
willpower: 50 - $player.health - $player.hygiene - $player.hunger,
}>>

I have it separately since it's a derived stat. This one is working just fine -- I can print, change, and base conditionals on it just fine. If I add $player.willpower to the text, it returns what it should: "40". So, first bit of code must be adding the properties properly. Does anyone have any idea on this one?

Just for added information, the conditional with which I'm having trouble is:

Your head hurts, the world is still spinning around you, and <<nobr>>
<<if $player.health is 4>>
you are certain you will have a large lump on your head.
<<elseif $player.health is 3>>
you are sure you have several bruises on your body.
<<elseif $player.health is 2>>
you are sure you have deep bruises on your body.
<<elseif $player.health is 1>>
you are one giant bruise from head to toe.
<<endif>>
<<endnobr>>

Which, no matter what, just says "Your head hurts, the world is still spinning around you, and ".

Comments

  • Whoop, never mind, figured it out on my own right after posting this.

    So...are there any ways to add properties to an object after it's already made?
  • You may simply assign to the property. For example:
    <<set $player.willpower to 50 - $player.health - $player.hygiene - $player.hunger>>
    
  • ...some things are just so simple they fly under my head. Jeez.

    Thanks.
Sign In or Register to comment.