Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.31.3
Story Format: Sugarcube 2.34.1
Dear All:
Sorry for the bother.
I am working on a ‘dungeon-crawler’ of a sort using Twine and Sugarcube (v. 2.31.3 and 2.34.1 respectively). I have a procedural generation system that works wonderfully (I think), and the game tracks a player through any of several preset mazes (set via the StoryInit file). As you go through the maze, you have the possibility of running into one of several enemies or encountering any of a number of locked containers - or falling down some very poorly maintained stairs.
During the game, all the information needed for a check is saved to an object. Let’s say that the object looks like this -
$engine_variables {
type: “”,
foe: “”,
dice: 0,
level: 0
}
I want each challenge in the game to be based on a character trait. So, let’s say you are trying to sneak past a goblin. If there is a sneak skill in the game, the current passage would record the engine_variables.type to “sneak.” In the passage that computes skill checks, the passage would then look for the $sneak variable (a numerical value between 0 to 10) and use it to help determine success or failure.
Right now, my code for this (after declaring variables in StoryInit ) looks something like -
<<set $engine_variables to {
type: “”,
foe: “”,
dice: 0,
level: 0
}>>
<<set $sneak to 3>>
…
(During the story - where the current value of engine_variables.type is “sneak”)
<<set _cur_v to $engine_variables.type>>
<<set _cur_b to “$”+_cur_v>>
<<set _value to parseInt(_cur_b)>>
_cur_b
This produces an error - namely [number NaN].
I need to be able to have Twine recognize $engine_variables.type as the name of a variable so that the program can use it to access the integer value of that variable. parseInt() and Number() do not seem to work for this, and I have looked through the internet and the IF forum. Any ideas?