**Newbie Question**: How to make player stats that increase and decrease (Gamebook)

ZeroKonD
22 Oct 2016, 21:05

Hey, been coding and have finally come to the place where im stuck at,
which is how i make a system that is like showing your characters name but without the input,
that is player stats that change depending on the player's choices.
If you (the one's reading this) know of anyway, plz write a reply and with possible screenshots on the code or if that isnt possible, a very detailed description for code newbies to understand. Thx :)

                                                                                                                                                                                           - _ZeroKonD_

Anonynn
22 Oct 2016, 21:30

It depends on the stats you want to use. For example, strength? agility? etc.

  1. First, click on the "player object" and then find the "attributes tab" for it.

  2. Next, click "add" on the second column (the top is for types).

  3. Write, strength or whatever stat you want and assign it to be an integer. Create the attribute.

  4. After that, you can assign stat increases and decreases in scripts by adding...

player.strength = player.strength + 1 or...
player.strength = player.strength - 1

  1. If you want to make it so that the stat can't fall below zero, then go back to the "player object", "attribute tab" ...find your "strength integer" and click on it. Afterward, scan across where you found the "add" button and click "change script" ...click it.

  2. Set the "change script" which should be "changedstrength" now to "run script"

  3. Add an "If Script" ...set it to be an "expression" and write in the bar: player.strength<1 then go down to the "then", add "click or add attribute" or hit code view and write player.strength = 1

Hope that helps!


ZeroKonD
23 Oct 2016, 10:33

Sorry to bother but how do you mean "click on the player object", 'cause i can't find anything like that in the gamebook editor, and even less of the attribute tab. It's possible im just being blind/stupid and can't find it but if possible, please explain.

PS. Once again, sorry for the trouble, i'm a real n00b when it's dealing with new programming languages.

PSS. Are we talking about gamebook or text adventure?


hegemonkhan
23 Oct 2016, 18:54

Anonynn was talking about the Text Adventure, as it's the default (has the entire functionality of quest --- the GameBook has less of the functionality of quest, as it is intended mainly for CYOA with limited/simple scripting).

However, the Game Book, also (MUST, like the Text Adventure) has the 'player' Player Object.

look to the left side/pane/window, this is what I call the "tree of stuff", an outline of all of your Elements (OBJECTS of OOP/OOD of/at quest software's/engine's underlying code, not to be confused with the 'Object' Element: http://docs.textadventures.co.uk/quest/elements/object.html , which you can see all the types of OBJECTS/Elements, here: http://docs.textadventures.co.uk/quest/elements/ ) in your game, which you can use/interact with, to select and do stuff with those Elements. The Game Book these types of 'Object' Elements/OBJECTS: the 'player' Player Object, the 'game' Game Object, and the 'PageX' Page Objects.

HK edit: if I remember right (too lazy to look up), you can't do this directly as described below in Game Book:
So, look for the 'player' Player Object in this left side's "tree of stuff", click on it to highlight it, and now you can see its details/options on the right side/window/pane, and then you add Attributes to it.

To create/set/re-set/alter/change/adjust Attributes in the Game Book, you must (as you can only, lol) do so via scripting:

left side's "tree of stuff" -> 'whatever' Page -> 'Page' Tab -> Page Type: [script] or [script+text] -> (see below)

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

(the Game Book only has two Objects for you to add-to-it-your/use-for-it-with-your custom/self-made Attributes: the 'game' Game Object and the 'player' Player Object)

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

and so:

set variable player.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION
~OR~
set variable game.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

examples:

(you'll probably want to decide on whether to use 'player' or 'game' based on which makes more conceptual-logical sense to you --- but you do not actually have to, as it's just for better human understanding/conception, of course)

// Integer Attributes:
set variable player.strength = [EXPRESSION] 100
set variable player.strength = [EXPRESSION] 0
set variable game.orc_monster_strength = [EXPRESSION] 10

// String Attributes:
set variable player.alias = [EXPRESSION] "HK"
set variable player.alias = [EXPRESSION] "ZeroKonD"
set variable game.orc_monster_alias = [EXPRESSION] "orc"

// Boolean Attributes:
set variable player.flying = [EXPRESSION] false
set variable player.flying = [EXPRESSION] true
set variable game.game_over = [EXPRESSION] false
set variable game.game_over = [EXPRESSION] true
set variable game.orc_monster_dead = [EXPRESSION] false
set variable game.orc_monster_dead = [EXPRESSION] true

// using 'game' for these, don't make concpetual-logical sense (hopefully obviously):
set variable game.strength = [EXPRESSION] 100
set variable game.strength = [EXPRESSION] 0
set variable game.alias = [EXPRESSION] "HK"
set variable game.alias = [EXPRESSION] "ZeroKonD"

// using 'game' for these, don't make concpetual-logical sense (hopefully obviously):
set variable player.orc_monster_dead = [EXPRESSION] false

Simple Arithmetic:

Addition:

set variable player.strength = [EXPRESSION] player.strength + VALUE
// example: set variable player.strength = [EXPRESSION] player.strength + 7

// example (in code --- it's a slightly different format than using the GUI/Editor's 'add new script' options --- compare the above example GUI/Editor's code line to the below actual in-code code lines) of how it works conceptually:
//
// Initial (old) Value: player.strength = 0
//
// player.strength = player.strength + 5
//
// player.strength (new) = player.strength (old: 0) + 5
// player.strength (new) = 0 + 5
//
// New value: player.strength = 5
//
// Old value: player.strength = 5
//
// player.strength (new) = player.strength (old: 5) + 5
// player.strength (new) = 5 + 5
//
// New value: player.strength = 10
//
// Old value: player.strength = 10
//
// player.strength (new) = player.strength (old: 10) + 5
// player.strength (new) = 10 + 5
//
// New value: player.strength = 15

a slightly more complex usage (stupid) example:

player.toughness = player.strength + player.endurance

a very complex usage example:

player.damage = player.weapon_damage + player.weapon_damage * player.strength / 100 - game.orc_monster_defense - game.orc_monster_defense * game.orc_monster_endurance / 100

Subtraction:

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

Multiplication:

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

Division:

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

Modulus:

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


see this link for much greater detail:

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

ask if you need any help, got an questions, or need any clarification/explanation


aman83
01 Dec 2016, 16:23

Thanks a million everyone!
This thread was really helpful!