Adding values to variables in a Gamebook
McPie
03 May 2017, 13:16Hey, thanks for reading this first of all. I've had a bit of a search around and couldn't find anything so I thought I would post a question.
Now, I'm trying to add a time system into the game book which increases the time every time the reader/player goes to a new page. On the first page, I set variables in the code view as such:
time = 1030
rTime = time%60
msg ("The current time is: "+(time/60)+":"+rTime)
This works fine, and prints the value of 17:10 when in game.
Now, when I go to the next page, and ask it to print the value of time, it instead prints the following error message:
Error running script: Error compiling expression 'time': Unknown object or variable 'time'
Here is a link to the picture of the code in case that helps: http://i.imgur.com/SrRbAJB.png
A picture of page one in game: http://i.imgur.com/DpkR62O.png
A picture of page two in game: http://i.imgur.com/VootaoA.png
Thank you for taking the time to read this! :)
hegemonkhan
03 May 2017, 14:09everything is actually perfect (you're/you've understand/understood VARIABLE usage), but you've made one small mistake:
you used Variable (local/temporary) VARIABLES, which don't exist outside of their scripting/'scope' (they only work within their 'scope', they only work within their scripting)
you need global/"permanent" (so long as the Object containing them, exists or still exists, of course) scope VARIABLES, which are Attribute VARIABLES in quest
Attribute VARIABLES (YES: dot attachment to an Object in code):
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
or
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE OPERATOR VALUE_OR_EXPRESSION
vs
Variable VARIABLES (NO: dot attachment to an Object in code):
NAME_OF_Variable
or
NAME_OF_Variable OPERATOR VALUE_OR_EXPRESSION
the Game Book only has two Objects for holding custom Attribute VARIABLES:
- the 'player' Player Object
- the 'game' Game Settings Object
so, just change your code to this:
game.time = 1030
game.rTime = game.time%60
msg ("The current time is: "+(game.time/60)+":"+game.rTime)
while you're limited to only 'player' and 'game', you can create the effect of having more Objects, for example:
player.minimum_life = 999
player.maximum_life = 999
game.orc_current_life = 100
game.orc_maximum_life = 100
// (you can use 'player' instead of 'game', but that doesn't make logical sense / it's jarring for us humans, but there's absolutely nothing wrong about this code/game-wise, it'll work just fine, for example: player.orc_current_life)
game.ogre_minimum_life = 500
game.ogre_maximum_life = 500
game.dragon_minimum_life = 99999
game.dragon_maximum_life = 99999
McPie
03 May 2017, 22:52That worked perfectly, thank you for the assistance.