Making an object?

So I know this is a very simple question but I'm really new to this and am having a lot of trouble with the tutorials. They really don't explain it well enough for people like myself. I'm currently making a gamebook and am doing pretty well learning it all, but objects have me totally stumped.


Hi Taru,

There are really only a few 'objects' in gamebooks, namely 'game', 'player' and one or two others that I can't think of at the moment. Depending on what you're trying to accomplish, you can probably use a page as your 'object'. You can give any page and the 'game' object attributes like:
game.d00
game.d20
game.d6
game.GOLD
game.SILVER
game.WATER
game.pricewater
game.priceGOLD
game.priceofsilver
game.goldhigh
game.goldlow
player.alias
player.AGE
player.SEX
player.gender
player.PROFESSION
player.LEVEL
player.startcash
player.NAME (I think this a reserved variable)
player.GOLD
player.cash
player.water
player.food
player.health
player.happiness

weapon.TYPE
weapon.BONUS
wand.TYPE
wand.BONUS

For the last four, I created pages called 'weapon' and 'wand' so that I can have the 'TYPE' and 'BONUS' attributes on them.

You can also use the same attribute on different pages and objects:
game.cash and player.cash are two different variables/attributes.

Also, be aware that capitalization matters, player.cash is different than player.CASH or player.Cash. The same goes for pages. You could have a page for your player's stats called 'Player'. This is a page, where player is the game object, not a page. A better example would b Kitchen vs kitchen. These could be two different pages, both perfectly valid.

Good luck with your gamebooks!


Thank you very much, but how would I make an option for someone to choose their gender?


There are a few different ways to let your player chose gender.

One is to have a page (call it 'gender' - I know, how original), with two links, or as many as you have gender possibilities. If the gender doesn't affect any game attributes, then the links should be to script-type pages that set a gender flag or attribute.

If, however, their choice affects things, like reduced physical strength for females and increased for males, then the links should be to script pages that set or change the affected attributes (player.strength = player.strength - 2, for example). Here's the code for three pages:

    <object name="gender">
      <inherit name="scripttext" />
      <description>Is your character {page:male:male} or {page:female:female}?</description>
      <object name="male">
        <inherit name="script" />
        <script type="script">
          player.STR = GetRandomInt(1,6) + GetRandomInt(1,6) + 4
          player.DEX = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.CON = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.INT = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.WIS = GetRandomInt(1,6) + GetRandomInt(1,6) + 4
          player.CHAR = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          SetFlagOn ("male")
          MovePlayer (profession)
        </script>
      </object>
      <object name="female">
        <inherit name="script" />
        <script type="script">
          player.STR = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.DEX = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.CON = GetRandomInt(1,6) + GetRandomInt(1,6) + 5
          player.INT = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.WIS = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          player.CHAR = GetRandomInt(1,6) + GetRandomInt(1,6) + 6
          SetFlagOff ("male")
          MovePlayer (profession)
        </script>
      </object>
    </object>

You can copy and paste all of it straight into the main 'code view' window of the desktop editor, or break it up into bits for the individual pages. Notice that I used a flag ('male') in the two pages - in case I wanted to reference the gender later on.

A third way is to use one page - again, a script type - that uses a series of nested scripts - for msg prompts, and the like. Sorry I can't provide an example of this, I am not able to use the desktop version, currently. it would look something like player.sex = result. 'result' is one of those reserved words, BTW.

Another way is to set an attribute yourself, based on the player's choice: player.gender = male or player.gender = female. The benefit of this approach is that the player cannot enter nonsense like 'DOnkey69' when they are allowed to type it in.


Hello.

There are many ways to handle attributes, but this is probably the easiest:


Make 2 pages, 'Male' and 'Female', to handle the choice.

image


image


Then, make a page asking the player to choose their gender, with a link to 'Male' and a link to 'Female'.

image


I also made a fourth page, just to show how to link into the main story from either 'Male' or 'Female' (each of those pages have a link to the fourth page).

image


The game's code:

<!--Saved by Quest 5.7.6606.27193-->
<asl version="550">
  <include ref="GamebookCore.aslx" />
  <game name="Attributes Gamebook">
    <gameid>5fe64fea-2cc6-4c30-9e95-1a4c6ce12799</gameid>
    <version>2.0</version>
    <firstpublished>2018</firstpublished>
    <author>Richard Headkid</author>
    <subtitle>The Unexpected Value of Pages</subtitle>
  </game>
  <object name="Page1">
    <description><![CDATA[Please select a gender.<br/><br/>]]></description>
    <options type="stringdictionary">
      <item>
        <key>Male</key>
        <value>Male</value>
      </item>
      <item>
        <key>Female</key>
        <value>Female</value>
      </item>
    </options>
    <object name="player">
      <inherit name="defaultplayer" />
    </object>
  </object>
  <object name="Male">
    <inherit name="scripttext" />
    <description>You selected {player.gender}.</description>
    <script type="script">
      player.gender = "Male"
    </script>
    <options type="stringdictionary">
      <item>
        <key>PlayBegins</key>
        <value>Continue...</value>
      </item>
    </options>
  </object>
  <object name="Female">
    <inherit name="scripttext" />
    <description>You selected {player.gender}.</description>
    <script type="script">
      player.gender = "Female"
    </script>
    <options type="stringdictionary">
      <item>
        <key>PlayBegins</key>
        <value>Continue...</value>
      </item>
    </options>
  </object>
  <object name="PlayBegins">
    <description><![CDATA[<center><h2>YOU HAVE WON THE GAME!</h2></center>]]></description>
  </object>
</asl>

Thank you so much. That was pretty confusing honestly, I severely underestimated how complicated and in-depth this can all get but I made it all and it seems to run fine. All I need now is to find out how the player's choice can change what text does/doesn't show up. For example if you choose female an extra part might show up mentioning something that you wouldn't get if you chose male.


In a text field:

Since you are a {either player.gender="Male":man, I will say this|woman, I will say {i:that}}.

Or you could use a script:

GUI View

image


Code View

switch (player.gender) {
  case ("Male") {
    msg ("Since you are a man, I will display this text.")
  }
  case ("Female") {
    msg ("I see that you are a woman, so I will try to behave myself!")
  }
  default {
    msg ("Something went wrong!  Please restart the story!!!")
  }
}

There are many other ways, too.


Or, if you set a flag for the gender, then you could check that right in the text window:
The following example uses the flag 'male'. You could use anything.

{if male:The little birdie says, "What's cookin' good lookin'?"}{if not male:The little birdie says, "Dude, what is wrong with you?"}

EDIT: Yes, you would put it all on one line. Otherwise, you'd get an extra line break in your output.


What script did you use for that? And what do you mean by set a flag?


here's hopefully some help:

http://docs.textadventures.co.uk/ifanswers/ifanswers.com/1150/gamebook-how-to-include-a-players-attributes-stats.html

if you need any help or got any questions or are confused about anything, let me/us know, and we'll help you with it


here's a more help for you (most of this is for using the 'Text Adventure' version of quest, but the scripting is the same for the Game Book, the only difference is in you access the scripting in the Game Book: 'WHATEVER' Page -> 'Page' Tab -> Page Type: [script] or [script+text] -> set up your scripting/attributes, compared to a Text Adventure):

http://textadventures.co.uk/forum/general/topic/ljjm32av4e2t9ot49k478g/help#710be61e-eae1-4af1-8363-520cc718ba1c

again, ask if you need help with anything and/or are confused or whatever about anything


Data Types:


String Data Type:

String ("text") Values:

a collection (1 or more) of characters (alphabet letters, numbers, and spaces/whitespaces) and/or some (but not all) symbols

(anything in double quotes is a String Value, a String Value MUST be encased within double quotes)

"a"
"abc"
"123"
"abc123"
"abc_123"
"What is your name?"
" " // yes, the 'space' (whitespace) is a character/symbol, just like using "a"

String Attributes (Attributes are global VARIABLES as they're contained within an Object, and thus can use them anywhere, so long as the Object holding them, exists or still exists, of course) and their String Values, examples:

(in-code scripting examples)
player.alias = "HK"
player.sex = "male"
player.age_string = "adult"
player.race = "human"
player.class = "warrior"

player.strength_string_A = "100" // this is a String ("text") Value due to the double quotes (and thus its a String Attribute as well), it is NOT an AMOUNT Value (AMOUNT: an Integer or a Double), despite being a number Value, so you can NOT do arithmetic (addition: +, subtraction: -, multiplication: *, division: /, and modulus: % --- the 'modulus' operation is a division operation, but it finds/gets/returns the REMAINDER) operations on/with it

player.strength_string_B = "strong"

game.introduction = "Welcome to my game, I hope you enjoy it, muwahaha!"

game.state_string = "0"

player.description = player.alias + " is a " + player.sex + " " + player.age_string + " " + player.race + " " + player.class + "."
// msg (player.description)
// output: HK is a male adult human warrior.

and this is what it looks like as 'creation' tags in code:

<game name="example_game">

  <attr name="state_string" type="string">0</attr>

  <attr name="introduction" type="string">Welcome to my game, I hope you enjoy it, muwahaha!</attr>

</game>

<object name="player">

  <attr name="alias" type="string">HK</attr>
  <attr name="sex" type="string">male</attr>
  <attr name="age_string" type="string">adult</attr>
  <attr name="race" type="string">human</attr>
  <attr name="class" type="string">warrior</attr>

</object>

Integer Data Type:

a non-decimal/non-fractional AMOUNT Value: -9999999, -100, -1, 0, 1, 100, 999999999

IMP0RTANT: AMOUNT (Integer/Double) Values do NOT have double quotes!

Integer Attribute examples

game.A_integer_attribute = 10
game.B_integer_attribute = 40
game.C_integer_attribute = game.A_integer_attribute + game.B_integer_attribute
// game.C_integer_attribute = 50

player.strength = 100
player.endurance = 75
player.life = (player.strength + player.endurance) / 2
// player.life = (100 + 75) / 2 = 175 / 2 = 87.5 ---> truncated (as these are Integer Values/Attributes) ----> 87

player.age_integer = 50

// -------

<game name="example_game">

  <attr name="A_integer_attribute" type="int">10</attr>

</game>

<object name="player">

  <attr name="strength" type="int">100</attr>

  <attr name="age_integer" type="int">50</attr>

</object>

Double Data Type:

decimal/fractional AMOUNTS: -9999999.123, -3.876, 0.0, 1.620000, 9999999999999.9

(lazy)


Boolean Data Types:

Booleans are known as 'flags' --- but, I don't really like 'flags' being used, as technically ALL VARIABLES, as they store data/values, are 'flags/indicators', but this is the term used for 'true/false' Booleans (binary:dualism:opposites outputs: true=yes=on=1 vs false=no=off=0), and thus being 'flagged on: true' or 'flagged off: false', used as: status flags, error flags, toggles, etc etc etc, see/google about: circuitry parts / circuitry programming designs / logic gates / etc etc etc)

Boolean Values:

true
false

these are special reserved Values, as/for being the Boolean Values, so they do NOT have double quotes, and are NOT seen as Object Values by the quest's parser / programming

Boolean Attributes:

orc.dead = false // conceptually: the orc is alive
orc.dead = true // conceptually: the orc is dead
// (you'd pick either 'dead' or 'alive' for this example, whichever you like/prefer or works best for you, as you've no need for both)
orc.alive = true // conceptually: the orc is alive
orc.alive = false // coneptually: the orc is dead

player.flying = true
player.flying = false

(just some example status attributes that are common in RPGS)
player.poisoned = true // poisoned
player.poisoned = false // NOT poisoned
player.asleep = true // asleep
player.asleep = false // NOT asleep
player.confused = true // confused
player.confused = false // NOT confused
player.petrified = true // petrified
player.petrified = false // NOT petrified

tv.turned_on = true // the tv is on
tv.turned_on = false // the tv is off
// (you'd pick either 'turned_on' or 'turned_off' for this example, whichever you like/prefer or works best for you, as you've no need for both)
tv.turned_off = true // the tv is off
tv.turned_off = false // the tv is on

<object name="orc">

  <attr name="dead" type="boolean">false</attr>
  <!-- We want our orc to start out alive, lol -->

  <attr name="undead" type="boolean">false</attr>
  <!-- yep, our orc is NOT undead, lol -->

</object>

<object name="skeleton">

  <attr name="dead" type="boolean">false</attr>
  <!-- We want our skeleton to start out alive, lol -->

  <attr name="undead" type="boolean">true</attr>
  <!-- yep, our skeleton IS undead, lol -->

</object>

Object Data Types:

IMPORTANT: Object (pointer/reference) Values do NOT have double quotes (and they must NOT be any reserved/special Values, such as 'true' and 'false', which are reserved/special for being the Boolean Values)

// create ("katana") // this creates a 'katana' Object
// katana.damage = 50 // an Integer Attribute of (contained within) the 'katana' Object

// create ("dagger") // this creates a 'dagger' Object
// dagger.damage = 1 // an Integer Attribute of (contained within) the 'dagger' Object

player.weapon = katana
// msg (player.weapon.damage)
// output: 50

player.weapon = dagger
// msg (player.weapon.damage)
// output: 1

and there's also these Data Types too:

Scripts --- this is it's own topic: scripting/coding... lol

and

Lists

Dictionaries

but these are a bit more advanced, so won't get into them here/now


while, you can't create custom Objects in a Game Book, you can create the same effect using Attributes, for example:

(using the special 'game' Object for the Attributes, which give the same effect, as if you had custom 'monster' Objects)

game.orc_life = 10
game.orc_damage = 10
game.orc_defense = 10
game.orc_alias = "orc"

game.ogre_life = 100
game.ogre_damage = 100
game.ogre_defense = 100
game.ogre_alias = "ogre"

game.dragon_life = 999999999
game.dragon_damage = 999
game.dragon_defense = 999
game.dragon_alias = "dragon"

Those two links just led to more links which led to more links and I just kinda lost it. All this code is very confusing and I just want a simple, definitive answer with how to show/not show certain text if the player chooses one option. Sorry if I sound picky or whatever but I just don't understand all this.


a simple, definitive answer with how to show/not show certain text if the player chooses one option

Sorry, but we'd need a little more information:

1. Which attribute name will you use?

2. Will that be a string attribute or a boolean attribute?


If you're still trying to do the gender, Jennifer and I provided simple suggestions, but neither of us know the answers to the two questions I just listed, and we need to know that sort of stuff to give you a simple, definitive answer.

If you use the example I posted to set player.gender to a string attribute, which could be either "Male" or "Female", you can put this in a text field:

Since you are a {either player.gender="Male":man, I will say manly things|woman, I will say womanly things}.


If you are using the desktop version of Quest, you can download and open this and see if playing around with it in the editor helps:

Right-click this link and "Save Link As":
Attributes Gamebook.aslx


NOTE: There are at least 6 other ways to work with those same attributes, and that's without even trying to think of all the possible ways to do it.



If you like Jennifer's method better, use her example:

Or, if you set a flag for the gender, then you could check that right in the text window:
The following example uses the flag 'male'. You could use anything.

{if male:The little birdie says, "What's cookin' good lookin'?"}{if not male:The little birdie says, "Dude, what is wrong with you?"}

EDIT: Yes, you would put it all on one line. Otherwise, you'd get an extra line break in your output.


If you'd like to learn how it works, scroll up and read the stuff HK posted.


If you'd rather not do anything that's been suggested, you can try Squiffy instead of Quest.

Here's the Squiffy code:

Please select your gender:

[[male]](start, gender=male)

[[female]](start, gender=female)
    
[[start]]:
You selected {gender}.

[[Continue...]]

[[Continue...]]:
Since you are {if gender=male:man, I will say manly things}{else:woman, I will say womanly things}.


Thank you once again! All that code in the quote boxes really confused me, but I got what you were talking about in the screenshots and it works, I'm so happy! I just tried to read through it all about Boolean and Integer and all that, and while I kind of understand what it meant I really had no idea what to do with that information. Regardless, I was able to change the text that shows up on the screen depending on what option you choose. You've been very helpful, thanks again.


Glad you got it working, and you'll get the hang of it!

Happy gaming!


(filler for getting my edited post, updated/posted)


@ Taru:

while, you seem to have gotten it, thanks to better explain'ers like RH/KV (uses lots of useful screenshots) and JC,

let me try again anyways, lol...


This is really comprehensive/detailed step by step guide/explanation, with many examples, ...hopefully this will greatly help you understand all of this stuff... lol


in the 'Game Book' version of quest, you only have 2 Objects (both of which are required Objects for the quest engine for it to work) that you can use for Attributes:

  1. the (default-named) 'player' Player Object
  2. the special 'game' (Game-wide/Global Settings and publishing public info stuff) Object
<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="player">
  <!-- BLAH Attributes -->
</object>

you do also have all of the various Page Objects, which you can use for Attributes too (I think --- I've not really used the Game Book that much), but the 'player' Player Object and the special 'game' Object, are your two main Objects for Attributes.

<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="player">
  <!-- BLAH Attributes -->
</object>

<object name="Page1">
  <!-- BLAH Attributes -->
</object>

<object name="Page2">
  <!-- BLAH Attributes -->
</object>

<!-- etc etc etc Page Objects -->

unlike the 'Text Adventure' version of quest, you don't have the nice Tabs and options that it has for creating Attributes, so for the 'Game Book' version of quest, you got to use Scripting for creating your Attributes


usually, you want to use your very first Page Object for creating your Attributes, so they exist for use/manipulation for the rest of your game.


the first/starting/initial Page Object is where/what you start your 'Game Book' version of quest playing at/within.

this is controlled/determined by which Page Object has the 'player' Player Object contained within it at the start of your game

you HAVE TO have the 'player' Player Object be contained within a Page Object, this is a requirement by the quest engine.

// this is known as 'nesting' (layering/indenting), which works for containment heirarchy:

// ----------------------

// 'Page1' is your starting page:

<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="Page1">

  <!-- BLAH Attributes -->

  <object name="player">
    <!-- BLAH Attributes -->
  </object>

</object>

<object name="Page99">
  <!-- BLAH Attributes -->
</object>

// ---------------------------------------

// vs, 'Page99' as your starting page:

<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="Page1">
  <!-- BLAH Attributes -->
</object>

<object name="Page99">

  <!-- BLAH Attributes -->

  <object name="player">
  </object>

</object>

alternatively to "nesting", you can do this instead:

the containment heirarchy is actually controlled by the built-in 'parent' Object Attribute

// 'Page1' is your starting page:

<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="player">

  <!-- BLAH Attributes -->

  <attr name="parent" type="object">Page1</attr>

</object>

<object name="Page1">
  <!-- BLAH Attributes -->
</object>

<object name="Page99">
  <!-- BLAH Attributes -->
</object>

// ---------------------------------------

// vs, 'Page99' as your starting page:

<game name="NAME_OF_YOUR_GAME">
  <!-- BLAH Attributes -->
</game>

<object name="player">

  <!-- BLAH Attributes -->

  <attr name="parent" type="object">Page99</attr>

</object>

<object name="Page1">
  <!-- BLAH Attributes -->
</object>

<object name="Page99">
  <!-- BLAH Attributes -->
</object>

on the left side, is the "tree of stuff (OBJECTS: the special 'game' Object, the 'player' Player Object, your various Page Objects, and maybe other stuff like Functions and etc --- not sure of what else a Game Book has, lol)", it might be helpful to think of OBJECTS as like folders, which can contain more/sub OBJECTS within them and/or Attributes within them


alright, now, on how to 'access' the scripting within the Game Gook (this is the only way to access the scripting in a Game Book in its GUI/Editor, aside from working directly in-code):

(the left side's) "tree of stuff" -> Pages -> 'WHATEVER' Page Object -> 'Page' Tab -> Page Type: [SCRIPT] or [SCRIPT + TEXT]

Creating/setting Attributes:

creating the Attribute (so it now exists and can thus then be used elsewhere/anywhere) and setting its initial Value

(the left side's) "tree of stuff" -> Pages -> 'WHATEVER' Page Object -> 'Page' Tab -> Page Type: [SCRIPT] or [SCRIPT + TEXT] -> see below

(run as script) -> add new script -> 'variables' section/category -> 'add a variable or attribute' Script -> see below

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

remember, you only got two Objects (aside from the various Page Objects) to work with for Attribute usage:

1. the special 'game' Object
2. the 'player' (or whatever you renamed it as) Player Object

so, for an example:

set variable player.sex = [EXPRESSION] "male"
// and/or (both can exist at the same time, as they're two different Attributes: a 'sex' Attribute for the 'player' and a 'sex' Attribute for the 'game'. Think of like in terms of people in how both Attributes can exist at the same time: joe.hair_color = "brown", and, jim.hair_color = "brown")
set variable game.sex = [EXPRESSION] "male"

// functionally using 'player' or 'game', are the same, though for 'sex', using 'game.sex' doesn't make much conceptual sense for us humans, lol

// I used 'sex' instead of 'gender', as 'gender' is already a built-in Attribute, (along with 'article'), controlling grammer usage, which I don't want to over-write/over-ride and thus if I did, I'd be losing that built-in grammer usage functionality, which I don't want, lol:

// http://docs.textadventures.co.uk/quest/elements/
// ('Elements' are the OBJECTS/STUFF in quest: Objects/Pages, the special 'game' Object, Player Object/s, Verbs, Commands, Turnscripts, Timers, etc etc etc --- not all of this stuff is available in the limited for-mainly-CYOA-type-of-games 'Game Book' version of quest, unlike the 'Text Adventure' version of quest, it's FULL functionality)

// http://docs.textadventures.co.uk/quest/elements/object.html
// these are the built-in Attributes for Objects in quest, the Game Book's Page Objects may not have all of these Attributes, not sure

// http://docs.textadventures.co.uk/quest/attributes/gender.html
// http://docs.textadventures.co.uk/quest/attributes/article.html

// the break down of it:

(Object Name: player)

Attribute Name: sex

(Attribute Type: string --- due to its Value, which determines the Attribute Type, as quest parses the Value to determine the Attribute Type, Value: "male", which is a String Value, as anything encased within double quotes is a String Value)

Attribute Value: "male"

// and/or:

(Object Name: game)

Attribute Name: sex

(Attribute Type: string --- due to its Value, which determines the Attribute Type, as quest parses the Value to determine the Attribute Type, Value: "male", which is a String Value, as anything encased within double quotes is a String Value)

Attribute Value: "male"

Manipulating/changing/altering/adjusting/re-setting an Attribute's Value:

// now, anywhere afterwards (in the same page where you created the Attribute and set its initial Value, in its following scripting, and/or in another Page that comes after the Page where you created the Attribute and set its initial Value), you can use that Attribute for whatever you wish, including:

// Manipulating/changing/altering/adjusting/re-setting an Attribute's Value:

(the left side's) "tree of stuff" -> Pages -> 'WHATEVER' Page Object -> 'Page' Tab -> Page Type: [SCRIPT] or [SCRIPT + TEXT] -> see below

(run as script) -> add new script -> 'variables' section/category -> 'add a variable or attribute' Script -> see below

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

// so, for an example, let's use our previous example, of: player.sex = "male", and change its Value from 'male' to 'female', shown below:

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

for AMOUNT (Integers/Doubles) Values/Attributes, here's how to do arithemetic operations, examples:

// created Attributes and their setted initial Values:

set variable player.strength = [EXPRESSION] 0
set variable player.endurance = [EXPRESSION] 9

// ---------------------

// Addition: +

// using just a literal/direct Value:
set variable player.strength = [EXPRESSION] player.strength + 5

// conceptually of how it works:
//
// in programming, we're doing an 'Assignment' operation: storing a Value into an Attribute (which obviously is not the same as in math of doing a comparison operation: if/is 'equal to' or not, lol), and also we're of course doing an addition operation too, which if/when done again and again, is increasing the value, which is stored into the Attribute, each time its done again
//
// initial value: player.strength = 0
//
// old value: player.strength = 0
//
// player.strength = player.strength + 5
// player.strength (new: ?) = player.strength (old: 0) + 5
// player.strength (new: ?) = (0) + 5 = 5
//
// new value: player.strength = 5
//
// old value: player.strength = 5
//
// player.strength = player.strength + 5
// player.strength (new: ?) = player.strength (old: 5) + 5
// player.strength (new: ?) = (5) + 5 = 10
//
// new value: player.strength = 10
//
// old value: player.strength = 10
//
// player.strength = player.strength + 5
// player.strength (new: ?) = player.strength (old: 10) + 5
// player.strength (new: ?) = (10) + 5 = 15
//
// new value: player.strength = 15
//
// etc etc etc

// using a VARIABLE (an 'Attribute' VARIABLE, an Attribute):
set variable player.strength = [EXPRESSION] player.strength + player.endurance
// player.strength (new: ?) = player.strength (using the initial value, for this example, old: 0) + player.endurance (9)
// player.strength (new: ?) = (0) + (9) = 9
// if done again:
// player.strength (new: ?) = player.strength (old: 9) + player.endurance (9)
// player.strength (new: ?) = (9) + (9) = 18

// --------------------------

Subtraction: -

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

// --------------------------

Multiplication: *

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

// ------------------------

Division: /

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

// ------------------------

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

set variable player.strength = [EXPRESSION] player.strength % 5

// ------------------------

// example of a more complex expression:

set variable player.damage = [EXPRESSION] 1
set variable player.weapon_damage = [EXPRESSION] 50
set variable player.strength = [EXPRESSION] 100

set variable player.damage = [EXPRESSION] player.weapon_damage + player.weapon_damage * player.strength / 100
// player.damage = (50) + (50) * (100) / 100 = (50) + (50) * 1 = (50) + 50 = 100

// vs

set variable player.damage = [EXPRESSION] 1
set variable player.weapon_damage = [EXPRESSION] 50
set variable player.strength = [EXPRESSION] 0

set variable player.damage = [EXPRESSION] player.weapon_damage + player.weapon_damage * player.strength / 100
// player.damage = (50) + (50) * (0) / 100 = (50) + (50) * 0 = (50) + 0 = 50

// vs

set variable player.damage = [EXPRESSION] 1
set variable player.weapon_damage = [EXPRESSION] 50
set variable player.strength = [EXPRESSION] 75

set variable player.damage = [EXPRESSION] player.weapon_damage + player.weapon_damage * player.strength / 100
// player.damage = (50) + (50) * (75) / 100 = (50) + 1/2 * 75 = (50) + 37 (the 0.5 of 37.5, gets truncated/removed due to being Integer) = 87

// vs

set variable player.damage = [EXPRESSION] 1
set variable player.weapon_damage = [EXPRESSION] 50
set variable player.strength = [EXPRESSION] 25

set variable player.damage = [EXPRESSION] player.weapon_damage + player.weapon_damage * player.strength / 100
// player.damage = (50) + (50) * (25) / 100 = (50) + 1/2 * 25 = (50) + 12 (the 0.5 of 12.5, gets truncated/removed due to being Integer) = 62

now, let's get into using Attributes, the most common usage is conditionally:

the via using the 'if' or 'switch' Scripts:

(the left side's) "tree of stuff" -> Pages -> 'WHATEVER' Page Object -> 'Page' Tab -> Page Type: [SCRIPT] or [SCRIPT + TEXT] -> see below

(run as script) -> add new script -> 'scripts' section/category -> 'if/switch' Scripts -> see below

the 'if' Script block (if, if + else_if/s, or if + else_if/s + else):

if [EXPRESSION] CONDITIONAL_EXPRESSION
-> then -> add new script -> 'WHATEVER' scripting

// optionally (as many 'else ifs' as you want):
add else if -> [EXPRESSION] CONDITIONAL_EXPRESSION
-> then -> add new script -> 'WHATEVER' scripting

// optionally:
add else
-> then add new script -> 'WHATEVER' scripting

// ------------

// the 'switch' (switch + case/s, or, switch + case/s + default) script block (its functionally the same as an 'if' script block, just a different style, so use whichever you prefer, or whichever works better for the scripting you want to do):

// in code, it looks like this (sorry, don't know what it looks like in the GUI/Editor, hopefully you can match it up though):

switch (CONDITIONAL_EXPRESSION) {
  case (POSSIBLE_MATCHING_VALUE_1) {
    // 'WHATEVER' scripting
  }
  // optionally as many more 'cases' as you want
  // optionally:
  default {
    // 'WHATEVER' scripting
  }
}

// hopefully you can kinda see how the 'if' and 'switch' are the same, though an actual example will make more sense and be more clear for you, of course, so see below for some examples:

(in code, as I'm lazy to write out the extra stuff that you see and need to do within the GUI/Editor, lol)

// using the 'if' Script/Function:

game.test_score = GetRandomInt (0, 100)

if (game.test_score > 89) {
  game.test_grade = "A"
}
else if (game.test_score > 79) {
  game.test_grade = "B"
}
else if (game.test_score > 69) {
  game.test_grade = "C"
}
else if (game.test_score > 59) {
  game.test_grade = "D"
}
else {
  game.test_grade = "F"
}

msg ("Test Score: " + game.test_score)
msg ("Test Grade: " + game.test_grade)

// using 'switch' Script/Function:

game.test_score = GetRandomInt (0, 100)

switch (true) {
  case (game.test_score > 89) {
    game.test_grade = "A"
  }
  case (game.test_score > 79) {
    game.test_grade = "B"
  }
  case (game.test_score > 69) {
    game.test_grade = "C"
  }
  case (game.test_score > 59) {
    game.test_grade = "D"
  }
  default {
    game.test_grade = "F"
  }
}

msg ("Test Score: " + game.test_score)
msg ("Test Grade: " + game.test_grade)

// -------

game.orc_alias = "orc"
game.orc_dead = false

// (if/when you got to some Page, you kill the orc: game.orc_dead = true)

// some other Page:
if (game.orc_dead) { // quest knows/parses 'game.orc_dead' to be 'game.orc_dead = true' // if (TRUE)
  msg ("The " + game.orc_alias + " is dead.")
} else { // if (not game.orc_dead) === if (not game.orc_dead = true) === if (game.orc_dead = false) // if (FALSE)
  msg ("The " + game.orc_alias" + is not dead, and it kills you!")
  msg ("GAME OVER")
}

// ----------------

game.sex_stringlist_attribute = NewStringList ()
list add (game.sex_stringlist_attribute, "male")
list add (game.sex_stringlist_attribute, "female")
list add (game.sex_stringlist_attribute, "hermaphrodite")
list add (game.sex_stringlist_attribute, "asexual")

show menu ("Sex?", game.sex_stringlist_attribute, false) {

  // the 'show menu / ShowMenu', 'ask/Ask', 'get input', and maybe some more Functions/Scripts too, automatically (hidden from you) do this:
  // result = YOUR_MENU_CHOSEN_SELECTION_OR_YOUR_TYPED_IN_INPUT

  // using the 'switch' Script/Function:
  //
  switch (result) {
    case ("male") {
      msg ("You are a male")
    }
    case ("female") {
      msg ("You are a female")
    }
    case ("hermaphrodite") {
      msg ("You are a hermaphrodite")
    }
    case ("asexual") {
      msg ("You are asexual")
    }
  }

  // or, using the 'if' Script/Function (choose one, don't use both, of course, lol):

  if (result = "male") {
    msg ("You are a male")
  }
  else if (result = "female") {
    msg ("You are a female")
  }
  else if (result = "hermaphrodite") {
    msg ("You are a hermaphrodite")
  }
  else if (result = "asexual") {
    msg ("You are asexual")
  }

}

// -------------

msg ("Alignment?")
msg ("(Type in a number from '0' to '100')")

handled_boolean_variable = true

get input {

  if (result > 100) {
    player.alignment = 100
  }
  else if (result < 0) {
    player.alignment = 0
  }
  else if (IsInt (result)) {
    player.alignment = ToInt (result)
  }
  else {
    handled_boolean_variable = false
    msg ("Wrong input, try again, typing in a number between '0' and '100', please")
  }

  if (handled_boolean_variable) // if (TRUE)
    msg ("Alignment: " + player.alignment)
  }

}

"in the 'Game Book' version of quest, you only have 2 Objects..."

Sorry, HK, but this is not true. Every page is an object and you can assign attributes to any of them.


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

Support

Forums