Adding values to variables in a Gamebook

Hey, 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:
A picture of page one in game:
A picture of page two in game:

Thank you for taking the time to read this! :)

everything 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):



Variable VARIABLES (NO: dot attachment to an Object in code):


the Game Book only has two Objects for holding custom Attribute VARIABLES:

  1. the 'player' Player Object
  2. 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

That worked perfectly, thank you for the assistance.

This topic is now closed. Topics are closed after 60 days of inactivity.