Basically I'm setting monsters race, $npc.race, as either "$race1", "$race2" etc and having the actual $race1 etc being objects that house that race of monsters stats. I need to get to a number that is say, kept in $race1.variable.
So I need to be able to add $npc.race (returns $race1) and .variable together to get at the number kept in $race1.variable.
The only way I am able to figure out how to do this, it gives me strings. I have also tried Number() and parseInt(), but those return blank.
What trick am I missing?
Comments
So based on this fact you could do something like the following:
This is close, but what I am attempting to do is basically go one level deeper. Instead of print $race1.race, I am trying to have print $npc.race, which will have the value of $race1, or $race2, etc etc and using that to add to the property of .strength or any other property.
For instance,
I'll have
<<set $npc to (name:"John",race:$race1)>>
<<set $race1 to (name:"Human",strength:4)>>
<<print $npc.race + ".strength">>
That last line of code works, but the output is a string, not a number... I can tinker with it, but no matter how I try to fiddle with it, the output is always a string, or blank.
I tried setting a temporary $variable to .strength or "strength" but it returns a blank also.
Is there any way to add the output of $npc.race together with .strength to get the number in $race1.strength?
Thanks for your time!
warning:
Each time the Reader navigates from one passage to another the values of all the current story $variables are cloned, and that set of cloned values is what is made available to the next passage.
This means that your $npc.race property will no longer reference the original object stored in $race1 variable, it will instead reference a copy. The $race1 variable will also no longer be referencing the original object, it references a copy as well and that copy is a different one to that now being referenced by $npc.race but all of those new objects will contain the equivalent values.
eg. In the next passage $npc.race !== $race but $npc.race.name and $race.name will both equal "Human".
This is not an issue if you don't plan to change the values stored in the properties of variables like $race1
You've solved the problem I've been trying to solve for two days, thanks a ton!