How to use variables?

RagnorokX
17 Oct 2016, 04:44So I came fresh out of the tutorial and am trying to use variables in a gamebook. I have it so it sets 4 variables via a function when you enter and then I want to print them to the player. My only question is, I don't know how/it isn't working. I have it set to print message(expression) "Hull: " + Hull(The exact name of the variable I set) and it just reports an error.
Log:
Error running script: Error compiling expression '': SyntaxError: Unexpected end of fileLine: 1, Column: 1
You blast off earth in your self dependant space ship, never to fully return.
Error running script: Error compiling expression '"Hull: "+Hull': Unknown object or variable 'Hull'
Code can be seen here.
Thanks for taking time out of your day to help a newbie.
hegemonkhan
17 Oct 2016, 07:46VARIABLES (keeping this simple):
- Variables: local/temporary: NAME_OF_Variable = VALUE_OR_EXPRESSION
- Attributes: global/permanent: NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
- Parameters: These deal with Functions (and Commands too in the Text Adventure)
You need to use Attributes (Attribute VARIABLES) instead of Variables (Variable VARIABLES) --- as Variables are local/temporary VARIABLES which are deleted once its containing scripting ends). Your Function's scripting ends and your 'Hull', 'Crew', 'Food', and 'forgot' Variables are deleted, which is why quest can't find/use them elsewhere in your game code. But, by using Attributes (game.Hull, game.Crew, Game.Food, Game.Forgot), they are permanent (so long as the Object exists or still exists, of course), as they're 'attached' (the dot/period) to the Object, meaning that they are data contained by and within the Object, Attributes are data units of an Object.
The Game Book only has two Objects for your own custom Attribute usage:
player
~AND~
game
'whatever' Page Object -> 'Page' Tab -> Page Type: [script] or [script+text] -> (see below)
// or: Function -> Add -> Name: 'whatever' -> (see below)
add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below, for examples)
set variable game.hull = {EXPRESSION] 10
~OR~
set variable player.hull = [EXPRESSION] 10 // this doesn't make much conceptual/logical sense though
then to use that Attribute:
player.hull
~OR~
game.hull
for example displaying it's Value (in code):
msg ("Hull: " + game.hull)
// outputs:
// Hull: 10
and an 'if' Script usage of it (in code):
if (game.Hull <= 0) {
msg ("Your ship blows up.")
msg ("GAME OVER")
finish // assuming Game Book has this Function/Script
}
the generic syntax (in code) I use to describe/explain it, is:
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
~OR~
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
for examples (in code):
player.strength = 0
game.state = 0
player.alias = "HK"
player.sex = "male"
game.greeting = "Welcome to my game, I hope you enjoy it!"
game.orc_monster_strength = 0 // while you can't create/add in Objects in the Game Book (like you can in Text Adventure), this is a way around it, to effectively have, in this example, an 'orc' monster. See the few additional below lines as well for more examples of this stuff
game.orc_monster_damage = 10
game.orc_monster_current_life = 10
game.orc_monster_dead = false
game.dragon_monster_strength = 100
game.dragon_monster_damage = 500
game.dragon_monster_current_life = 1000
game.dragon_monster_dead = false
player.flying = false
game.sex_list = split ("male; female", ";")
game.condition_list = split ("normal; poisoned;asleep; confused; stunned; petrified; paralyzed; silenced; blinded", ";")
player.HKs_favorite_color_list = split ("black; red", ";")
player.condition_list = split ("normal", ";") // if you want multiple conditions at same time
player.condition = "normal" // if you only have one condition at a time
if you want a more detailed guide on using Attributes and the 'if' Script:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
the guide is for Text Adventure, but the Attribute and 'if' Script usage is the same, except for how scripting is done in the Game Book (Page Type: [script] or [script+text]), vs in Text Adventure.

RagnorokX
17 Oct 2016, 16:44Thanks! This cleared up a lot. I really didn't think I should of been using object attributes in a gamebook where there is no objects, haha.