Gamebook help (Adding to variables)

tinlin

New to Gamebook, very limited knowledge. I've been trying to figure out how to add to a variable all day. Once it's set how do I add to it?


hegemonkhan

you do have Attribute usage, but you can only do so through scripting:

'NAME_OF_PAGE_OBJECT' Page Object -> 'Page' Tab -> Page Type: [script] or [script+text] -> (see below)

add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below, an example)

set variable player.strength = [EXPRESSION] 0

the general structure/pattern/format/syntax is this (in code, which is slightly different from the GUI/Editor's '[EXPRESSION]' scripting syntax):

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
or
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE OPERATOR VALUE_OR_EXPRESSION

in the Game Book, you've only got two Objects to use:

  1. the 'player' Player Object: player
  2. the 'game' Game Settings Object: game

some examples (in code, which is a bit different than the GUI/Editor's '[EXPRESSION]' scripting syntax)

player.strength = 0
game.state = 0
player.alias = "HK"
game.dragon_killed = false
game.dragon_killed = true
game.greeting = "welcome to my game, I hope you enjoy it!"

but, there's a way to 'cheat' to effectively have more Objects:

game.orc_life = 50
game.orc_damage = 10
game.dragon_life = 1000
game.dragon_damage = 500

you can use the 'player' as well (but it usually doesn't make logical sense -- unnerving for us humans, but NO actual errors in terms of/for the computer using it):

player.orc_life = 50
player.orc_damage = 10
player.dragon_life = 1000
player.dragon_damage = 500


to do simple arithmetic simple expressions, some examples (using the GUI/Editor's '[EXPRESSION]' scripting syntax):

Addition:

set variable player.strength = [EXPRESSION] player.strength + 7

Subtraction:

set variable player.strength = [EXPRESSION] player.strength - 20

Multiplication:

set variable player.strength = [EXPRESSION] player.strength * 3

Division:

set variable player.strength = [EXPRESSION] player.strength / 2


Modulus (division, but it finds/gets the REMAINDER): %

Cyclic example:

game.military_hour = game.hour % 24
game.civilian_hour = game.hour % 12

//game.hour = 13
game.military_hour = game.hour % 24
// game.military_hour = game.hour / 24 = 13 / 24 = no division, thus no change (13 - 0): 13
game.civilian_hour = game.hour % 12
// game.military_hour = game.hour / 24 = 13 / 12 = (1, R:1) = R:1 = 1

//game.hour = 60
game.military_hour = game.hour % 24
// game.military_hour = game.hour / 24 = 60 / 24 = (2, R:12) = R:12 = 12
game.civilian_hour = game.hour % 12
// game.military_hour = game.hour / 24 = 60 / 12 = (5, R:0) = R:0 = 0

Even/Odd/Factor-Divisible-X example:

if (game.my_value % 2 = 0) {
  msg ("The value is even")
} else {
  msg ("The value is odd")
}

if (game.my_value % 7 = 0) {
  msg ("The value is divisible by 7, or said another way: 7 is a factor of the value")
} else {
  msg ("The value is not divisible by 7")
}

you can do more complex expressions too, an example:

// set variable player.strength = [EXPRESSION] 75
// set variable player.weapon_damage = [EXPRESSION] 50
set variable player.damage = [EXPRESSION] player.weapon_damage + player.weapon_damage * player.strength / 100
// player.damage = 50 + 50 * 75/100
// player.damage = 50 + 37 = 87


here's a more detailed guide:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

(it's for a text adventure, but the scripting stuff is the same between text adventure and game book, for the most part. Only the means of accessing the scripting differs, and also that the Game Book is much more limited in its functionality than a Text Adventure and its full functionality, as the Game Book was meant merely for non-code-heavy CYOA game making)


tinlin

I tried that but it's not worked yet. I set Money to 0 in game and in a different page tried to add to it in the way you said but it stayed the same. Thanks anyway.


hegemonkhan

you tried:

Page A:

set variable player.money = [EXPRESSION] 0
print [expression] "Money: " + player.money
// output: Money: 0

Page B:

set variable player.money = [EXPRESSION] player.money + 5
print [expression] "Money: " + player.money
// output: Money: 5

or

Page A:

set variable game.money = [EXPRESSION] 0
print [expression] "Money: " + game.money
// output: Money: 0

Page B:

set variable game.money = [EXPRESSION] game.money + 5
print [expression] "Money: " + game.money
// output: Money: 5

and it's not working?


tinlin

Oops yeah it's working now. Must have missed something out. Thanks!


hegemonkhan

unfortunately with programming/coding/game-making... you've got to be 100% error/grammmer/syntax/spelling/typo... FREE! Programming/coding/game-making really helps you become a flawless typer... as you can have everything right, the code works perfectly.. but you got one tiny little spelling/typo mistake... and so the code doesn't work...

more often than not, you've done the coding right.... you just got some stupid small error... to find and fix... rarely does the code itself as a whole/design, not work. People are better coders than they realize... again, if something doesn't work, it's probably just because of some small mistake somewhere.


Log in to post a reply.

Support

Forums