Using the Gamebook style game, how do I create game-wide variables to track?

0 votes
161 views
asked Aug 23 in Authoring by ParaVox3 (5 points)

In a Gamebook style game, how do I create game-wide variables to track?

For example, if I want to set a player's gender, but gender doesn't exist in my game yet, how do I make a variable called gender that I can set to be male or female, then check later?

I am using Windows 8, downloadable version of Quest 5.6.1

1 Answer

0 votes
answered Aug 24 by hegemonkhan (161 points)
selected Aug 25 by ParaVox3
 
Best answer

Note:

I'm not that knowledgeable with Gamebook, so I'm not sure if everything I post here applies for it.


To set up Attributes at the beginning of your Gamebook:

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

http://docs.textadventures.co.uk/quest/guides/character_creation.html (for the 'add new scripts' Scripting)

to (create~set, re-set, change-alter, etc) an Attribute:

add new script -> variables -> 'set a variable or attribute' Script -> (see below)

set variable Object-name.Attribute-name = [expression] Value-or-Expression

replace my 'Object-name' with either: 'game' or 'player', Gamebook version is limited to only these two Objects for your use.

replace my 'Attribute-name' with whatever you want to call~name your Attribute

replace my 'Value-or-Expression' with whatever you want, though it is based upon what Attribute Type (String, Integer~int, Boolean, etc) you want it to be and to do. Lastly, NO 'white-spaces' (spaces: the space bar keyboard key) should be used and there's some other symbols you can't use too. See below for examples of Values~Expressions

lastly, do note that there is (MUST BE) a 'dot' that is between the 'Object-name' and 'Attribute-name' (and again: NO spaces between the 'dot' and 'Object~Attribute-names'; aka, no spaces next to the 'dot' ), which connects~attaches the Attribute to the Object (if you were using the Text Adventure version and using its GUI~Editor, this coding, is the equivalent of 'adding an Attribute to a specific Object' )

examples:

Integer (int) Attributes:

set variable player.strength =  [expression] 100

set variable game.strength = [expression] 100

set variable game.state = [expression] 0

set variable player.state = [expression] 0

set variable player.strength =  [expression] player.strength + 5 // this will increase your 'strength' by 5

set variable player.damage = [expression] player.strength + player.endurance

set variable player.damage = [expression] player.damage + player.damage * (player.strength / 100) - (game.orc_defense + game.orc_defense * (game.orc_endurance / 100))

Double Attributes:

// these are just using decimal numbers, but I've never worked with them yet, laughs

String Attributes:

set variable player.alias = [expression] "HK"

set variable player.sex = [expression] "male"

set variable game.sex = [expression] "male"

set variable player.sex = [expression] "female"

set variable game.sex = [expression] "female"

set variable player.race = [expression] "human"

set variable player.race = [expression] "elf"

set variable game.race = [expression] "human"

set variable game.race = [expression] "elf"

set variable player.state = [expression] "0"

set variable game.state = [expression] "0"

set variable player.strength = [expression] "strong"

set variable game.strength = [expression] "strong"

set variable player.strength = [expression] "weak"

set variable game.strength = [expression] "weak"

set variable player.condition = [expression] "normal"

set variable player.condition = [expression] "poisoned"

set variable player.condition = [expression] "paralyzed"

set variable game.condition = [expression] "normal"

set variable game.static_greeting = [expression] "Welcome to this game, HK."

set variable game.dynamic_greeting = [expression] "Welcome to this game, " + player.alias + "."

set variable game.dynamic_greeting = [expression] "Welcome to this game, {player.alias}."

Boolean Attributes:

set variable game.dragon_dead = [expression] false

set variable game.dragon_dead = [expression] true

set variable player.dead = [expression] false

set variable player.dead = [expression] true

set variable player.flying = [expression] false

set variable player.flying = [expression] true

set variable player.poisoned = [expression] false

set variable player.poisoned = [expression] true

set variable game.poisoned = [expression] false

set variable game.poisoned = [expression] true

String List Attributes:

set variable player.race = [expression] split ("human; dwarf; elf", ";")

set variable game.greetings = [expression] split ("Hi, what is your name?;  Hello, what is your name?;  Howdy, what is your name?; Hola, como say llama?", ";")

now if you want the person playing the game to decide~select~choose their Attributes' Values ...

there's the 'get input' Script and the 'show menu' Script

(see the 'character creation' link above, but if you still need help, let me know)

commented Aug 24 by ParaVox3 (5 points)
That worked until I selected set variable, then it gave me a picture:

Set variable [empty box] = [expression drop down] [empty box drown down]

Which empty box equals what? Otherwise, it looks as if you really do need to learn to program to use this system.
commented Aug 24 by hegemonkhan (161 points)
edited Aug 24 by hegemonkhan
this is how it should look (type in the missing stuff into the empty boxes, so that it reads the same as below), for example:

set variable player.sex = [expression] "male"

so in the first (left most) text box, type:

player.sex

and for the drop down box, choose:

[expression]

and for the other text box (the right most one), type:

"male"

hopefully, you understand now, so go back to my big answer post, and look at the examples of Attributes I've given on how to write them correctly (syntax~format).

-----

let me know though if you're still confused.

(you're learning to code by learning to write in these Attributes, hehe)

here's how to do an Attribute in scripting (action lines) code, for example:

player.sex = "male"

and here's how it is as a 'creation' tag block in code:

<object name="player">
  <attr name="sex" type="string">male</attr>
</object>

-----

P.S.

I don't like using 'gender' because 'gender' already exists as a built-in Attribute (and if you create your own Attribute named 'gender' it will over-ride all of the built-in programming for the built-in 'gender' Attribute):

http://docs.textadventures.co.uk/quest/attributes/gender.html
http://docs.textadventures.co.uk/quest/attributes/article.html
commented Aug 24 by ParaVox3 (5 points)
Firstly, let me say that I deeply appreciate your help.  I also appreciate the pro-tip regarding gender being pre-defined.

Is there a list of pre-defined attributes somewhere? When I click on the provided link, it explains the gender attribute is a string, etc, but I'd love to find out what else is pre-defined.
commented Aug 24 by hegemonkhan (161 points)
edited Aug 24 by hegemonkhan
you can use 'genderx' if you want, if you don't like 'sex', as 'genderx' is not 'gender', they're two different~separate Attributes.

I personally, like to do 'AttributeName_AttributeType_ElementType', in my naming~labeling of my Attributes or other Elements (though these obviously wouldn't have the 'AttributeType' in it), as it helps me, for example:

player.gender_string_attribute = "male"

game.gender_stringlist_attribute = split ("male;female", ";")

player.strength_string_attribute = "strong"

player.strength_integer_attribute = 100

I can't remember (and am too lazy to look~test) in whether quest is upper~lower case senstive: I'm not sure whether 'gender', 'Gender', 'GENDER', 'gEnDeR', etc (lol),  are seen as two different Attributes or the same Attribute.

as for the pre-built stuff (key~reserved words~commands~names for the Elements, Functions, Attributes, Verbs, etc):

http://docs.textadventures.co.uk/quest/
( at the top of the screen, click on 'Scripts~Functions~Types~Elements', and if need be click on the sub categories~choices within them, to see some of the built-in stuff.

also, if you create a Text Adventure game, in the lower left corner of the GUI~Editor:

Filter -> Show Library Elements -> (have it be toggle on, have the check box checked in)

which will show all of the built-in stuff, in the 'tree of stuff' above, as the newly revealed light-grey text.

unfortunately, the Gamebook game, doesn't have this 'Filter -> Show Library Elements' toggle

or, if you downloaded quest, you can open up the actual files themselves, looking at all the engine code directly (quest is actually a collection of library files, so if you're a good programmer, you can create an entirely new quest engine, if you wanted to).
commented Aug 24 by ParaVox3 (5 points)
From what I understand, Quest is built on or with Java and is case sensitive.

I can't find the linkback to the 'gender' and 'article' page, and top-down from scripts/functions/types doesn't appear to show me how to access gender (and hence any likely list).

However, thanks to your help, I have successfully set the Player.Sex to be both male and female in the correct decision trees. Later on, however, when I attempt to use it (mind, I'm just testing what I did earlier with feedback with in-line code, I'm getting an error:

   player.sex = "female"

Then later:

   {if player.sex = "female": Female!}

But I get this error:

Error running script: Error evaluating expression 'ToString(value) = rhs': Object reference not set to an instance of an object.

Any thoughts?

Thank you again for your patience and help.
commented Aug 24 by hegemonkhan (161 points)
edited Aug 24 by hegemonkhan
Quest uses XML (I like using notepad++), and can use JS too (via in the ' tree of stuff ' -> Advanced -> Javascript -> add), as best as I understand it.

-------

'gender' and 'article' are some of the built-in Attributes for the 'Object' Element:

quest doc page: 'Elements' -> 'Objects' -> 'gender', 'article', etc...

http://docs.textadventures.co.uk/quest/
VVVVVVVVV
http://docs.textadventures.co.uk/quest/elements/
VVVVVVVVV
http://docs.textadventures.co.uk/quest/elements/object.html
VVVVVVVVV
http://docs.textadventures.co.uk/quest/attributes/alias.html
http://docs.textadventures.co.uk/quest/attributes/article.html
etc etc ect
http://docs.textadventures.co.uk/quest/attributes/gender.html
etc etc etc

----------

in quest (XML), it's syntax for using Attributes is like this, an example using a Function and 'show menu' (to assign your choosen value for your 'gender' Attribute) and the 'if' Scripting (all in code ~ I'm lazy):

// I hope there's no pre-built Function called 'gender_function', lol
<function name="gender_function">
  show menu ("Gender?", game.gender_stringlist_attribute, false) {
    // for the 'get input' and 'show menu', the  quest engine automatically (hidden from you) sets the local-temporary Variable:
    // result = your_input_or_selected_choice
    player.gender_string_attribute = ToString (result)
    if (player.gender_string_attribute = "male") {
      msg ("You're a male.")
    } else if (player.gender_string_attribute = "female") {
      msg ("You're a female.")
    }
  }
</function>

and to call~activate~execute~run a Function (in code), you literally jsut type in the Function's name as your code line, for example in Text Adventure:

<game name="xxx">
  <attr name="gender_stringlist_attribute" type="simplestringlist">male;female</attr>
  <attr name="start" type="script">
    gender_function
  </attr>
</game>

or, the equivalent in GameBook:

'Pages' -> 'Page1' -> Page Type: [script] or [script+text] -> (see below)

add new script -> scripts (I think) -> 'call function' Script -> Name: gender_function, (see below about Parameters)

or, using the GUI~Editor:

add new script -> scripts (I think) -> 'call function' Script -> (see below)

Name text box: gender_function
Parameters (add) box: (optional, and you got to know what you're doing, otherwise don't add in any Parameters, leave this box blank)
commented Aug 24 by hegemonkhan (161 points)
edited Aug 24 by hegemonkhan
oh for this attempt of yours (sorry didn't recognize it, what you were trying to do, until now):

{if player.sex = "female": Female!}

this is a text processor command:

http://docs.textadventures.co.uk/quest/text_processor.html

// do note: text processor commands are more limited than the normal 'text+VARIABLE' scripting expressions and~or using 'if' Scripting

and if I remember right (you don't put the double quotes on the 'female' Value of the Attribute when using text processor commands), it should be like this (in code):

msg (" You're a {if player.sex=female: Female!} {if player.sex=male: Male!} ")

or, in the GUI~Editor:

add new script -> output -> 'print a message' Script -> (see below)

print [expression] "You are a {if player.sex=female: Female!} {if player.sex=male: Male!}"
commented Aug 25 by ParaVox3 (5 points)
I need to be able to do this in-line in the book text... isn't that how the text processor works?

I'm getting this error: Error running script: Error evaluating expression 'ToString(value) = rhs': Object reference not set to an instance of an object.

I have no idea what that means or how to resolve it.
commented Aug 26 by hegemonkhan (161 points)
here's the in-line menu (but not sure if it's available for the Gamebook's usage):

http://docs.textadventures.co.uk/quest/functions/showmenu.html

(this, the in-line menu, has no space between 'show and 'menu', while the popup window menu, has a space between the 'show' and 'menu' )

-----------

and sorry about the incorrect syntax example of a text processor command, I learned another thing thanks to your post and Pertex' answer on it: NO spaces (except after the 'if'), and what I previously learned from Jay+Pixie: NO double quotes on the Attribute's Value.
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...