Variable that impacts choices depending on it's state

Hello! I really need your help, guys! I don't know programming at all, and I wish to create a gamebook that features a certain variable (Mood or Energy, in my case). With certain choices I would like to add or subtract energy points. Also other choices would require a certain level of energy to be available (eg "above 50 energy to go for a jog"). Can you guys shed some light on this for me?


quest has 3 types of VARIABLES (keeping this simple)

VARIABLES:

  1. Variable
  2. Attribute
  3. Parameter

You'll want to use Attributes

so, that's all I'm going to get into for now


Data Types:

  1. Strings: a collection of letters, numbers, and/or (some) symbols ------- (Aka: "text")

examples:

"a"
"abc"
"1"
"123"
"abc_123"
"abc 123"
"hi, welcome to my game, I hope you enjoy it!"

"1.0"
"true"
"false"
"player"

anything within double quotes is a String Value, including numbers (which means that they're NOT amounts -- so you can't do arithmetic operations with them when the numbers are String Values, which is when you got them within double quotes)

  1. Integers: any non-decimal/non-fractional number/amount

examples:

-9999999999
-100
-1
0
1
100
99999999

notice how they do NOT have double quotes (if they did, they'd be String Values, and not Integer/amount Values)

  1. Doubles (Floats / Floating Points): any decimal/fractional number/amount

examples:

-99999999.123456
-100.789
-1.9
0.0
1.1
100.789
99999.123456

notice how they do NOT have double quotes (if they did, they'd be String Values, and not Doubles/amount Values)

  1. Booleans: 'true' or 'false' Value

examples

true
false

these are special/reserved words, for being the Boolean Data Type's Values

again, notice how they're NOT in double quotes


Advanced Data Types:

(we'll hold off on these for now)

  1. Objects: a reference/pointer to the Object's location/address in memory (this is a bit technical, so just ignore it --- all you need to know/understand, is that it's not actually the Object itself as the Value)

  2. Lists

  3. Dictionaries

  4. Scripts


Attribute General Syntax:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
// or:
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION


the Game Book only has 2 Objects (aside from the 'Page' Objects) for you to use:

  1. the special Game-Wide Settings and Publishing Info 'game' Object

  2. the (defaultly named) 'player' Player Object


Attribute Usage (the Game Book only has scripting, so here's how to do the scripting of Attributes):

'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)

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

examples:

set variable player.strength = [EXPRESSION] 100
set variable game.strength = [EXPRESSION] 100

set variable player.alias = [EXPRESSION] "HK"
set variable game.intro = [EXPRESSION] "Welcome to my game, I hope you enjoy it!"

set variable game.dead = [EXPRESSION] false
set variable player.dead = [EXPRESSION] false

example of creating an effective Object (as you can't create additional Objects in the Game Book, aside from Page Objects), in this case/example, an 'orc' monster Object:

set variable game.orc_dead = [EXPRESSION] false
set variable game.orc_damage = [EXPRESSION] 10
set variable game.orc_current_life = [EXPRESSION] 200
set variable game.orc_maximum_life = [EXPRESSION] 200
set variable game.orc_life = [EXPRESSION] "Orc Life: " + game.orc_current_life + "/" + game.orc_maximum_life

// or:

set variable player.orc_dead = [EXPRESSION] false
set variable player.orc_damage = [EXPRESSION] 10
set variable player.orc_current_life = [EXPRESSION] 200
set variable player.orc_maximum_life = [EXPRESSION] 200
set variable player.orc_life = [EXPRESSION] "Orc Life: " + player.orc_current_life + "/" + player.orc_maximum_life


Note: for us humans, some things don't make conceptual sense, but code doesn't care, for example:

'game.dead' (works fine, but is "jarring" for us humans) instead of 'player.dead' (works fine and is NOT "jarring" for us humans)

// another example:

// ("jarring" for us humans, but it works fine)

set variable player.orc_dead = [EXPRESSION] false
set variable player.orc_damage = [EXPRESSION] 10
set variable player.orc_current_life = [EXPRESSION] 200
set variable player.orc_maximum_life = [EXPRESSION] 200
set variable player.orc_life = [EXPRESSION] "Orc Life: " + player.orc_current_life + "/" + player.orc_maximum_life

// vs (NOT "jarring" and works fine):

et variable game.orc_dead = [EXPRESSION] false
set variable game.orc_damage = [EXPRESSION] 10
set variable game.orc_current_life = [EXPRESSION] 200
set variable game.orc_maximum_life = [EXPRESSION] 200
set variable game.orc_life = [EXPRESSION] "Orc Life: " + game.orc_current_life + "/" + game.orc_maximum_life


Arithmetic Operations, examples:

  1. Addition:

// player.strength = 100

set variable player.strength = [EXPRESSION] player.strength + 5
// player.strength = [player.strength = 100] + 5
// player.strength = [100] + 5
// player.strength = 105

  1. Subtraction:

// player.strength = 100

set variable player.strength = [EXPRESSION] player.strength - 10
// player.strength = [player.strength = 100] - 10
// player.strength = [100] - 10
// player.strength = 90

  1. Multiplication:

// player.strength = 100

set variable player.strength = [EXPRESSION] player.strength * 3
// player.strength = [player.strength = 100] * 3
// player.strength = [100] * 3
// player.strength = 300

  1. Division:

// player.strength = 100

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

  1. Modulus (Division, but it finds/gets/returns the REMAINDER):

does these operations: cyclic, is number even or odd, or factors/divisibilities of a number

cyclic example:

// game.hour_count = GetRandomInt (0,100)

set variable game.clock_civilian_hour = [EXPRESSION] game.hour_count % 12
// game.clock_civilian_hour = [0 to 11]

set variable game.clock_military_hour = [EXPRESSION] game.hour_count % 24
// game.clock_military_hour = [0 to 23]

is a number even/odd example:

// game.number = GetRandomInt (0,100)

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

if (game.number % 2 = 0) {
  msg (game.number + " is an even number")
} else {
  msg (game.number + " is an odd number")
}

// or:

if (game.number % 2 = 1) {
  msg (game.number + " is an odd number")
} else {
  msg (game.number + " is an even number")
}

factoring/disibility of a number example:

// game.number = GetRandomInt (0,100)

if (game.number % 2 = 0) {
  msg (game.number + " is divisible by 2, or to say it differently, 2 is a factor of " + game.number)
} else if (game.number % 3 = 0) {
  msg (game.number + " is divisible by 3, or to say it differently, 3 is a factor of " + game.number)
} else if (game.number % 4 = 0) {
  msg (game.number + " is divisible by 4, or to say it differently, 4 is a factor of " + game.number)
} else if (game.number % 5 = 0) {
  msg (game.number + " is divisible by 5, or to say it differently, 5 is a factor of " + game.number)
} else if (game.number % 6 = 0) {
  msg (game.number + " is divisible by 6, or to say it differently, 6 is a factor of " + game.number)
} else if (game.number % 7 = 0) {
  msg (game.number + " is divisible by 7, or to say it differently, 7 is a factor of " + game.number)
}
// etc 'else ifs' for infinity of factor/divisibility of a number

the 'if' Script:

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

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] CONDITIONAL_EXPRESSION_1
-> then -> add new script
// optional:
else if [EXPRESSION] CONDITIONAL_EXPRESSION_2
-> then -> add new script
// optional: additional 'else ifs'
// optional:
else
-> then -> add new script

some examples (in code... hopefully you can figure out how to do with the 'add new script' script options in the GUI/Editor, if not, let me/us know, and we'll help you with them):

// game.test_score = GetRandomInt (0,100)
// game.test_grade ="unknown"

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

// high to low:

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"
}

// or alternatively (if you don't like the '-1' for the Value: if you want to use the 'greater than or equal to' operation / operator symbol), high to low:

// (to do the 'greater/lesser than or equal to' operations / operator symbols: the '=' must be on the right side and the '</>' must be on the left side, and there must be NO space between the '=' and '</>', see the below two lines)

//  (greater than or equal to: >= )
// ( lesser than or equal to: <= )

if (game.test_score >= 90) {
  game.test_grade = "A"
} else if (game.test_score >= 80) {
  game.test_grade = "B"
} else if (game.test_score >= 70) {
  game.test_grade = "C"
} else if (game.test_score >= 60) {
  game.test_grade = "D"
} else {
  game.test_grade = "F"
}

// low to high:

if (game.test_score < 60) {
  game.test_grade = "F"
} else if (game.test_score < 70) {
  game.test_grade = "D"
} else if (game.test_score < 80) {
  game.test_grade = "C"
} else if (game.test_score < 90) {
  game.test_grade = "B"
} else {
  game.test_grade = "A"
}

// stringlist_variable = split ("true;false", ";")
// game.orc_dead = StringListItem (stringlist_variable, GetRandomInt (0, ListCount (stringlist_variable) - 1))

if (game.orc_dead) { // if (game.orc_dead = true) {
  msg ("The orc is dead")
} else { // if (game.orc_dead = false) {
  msg ("The orc is alive")
}

// stringlist_variable = split ("hegemonkhan;sabinlord", ";")
// player.alias = StringListItem (stringlist_variable, GetRandomInt (0, ListCount (stringlist_variable) - 1))

if (player.alias = "hegemonkhan") {
  msg ("Hey, it's hegemonkhan, who's been using quest for some years now")
} else if (player.alias = "sabinlord") {
  msg ("Oh, okay, nice to meet you sabinlord, you're a new guy to quest, I hope you enjoy using it and will not have too hard a time in learning to use quest and/or also its coding as well")
}

Thank you so much, hegemonkhan! I don't deserve the effort and time you spent writing this reply for me. I shall work hard to create a beautiful game thanks to you!


let me know if anything confuses you, or if you need help with anything, as this stuff (Attributes and the 'if' Script usage) is a lot of stuff to try to take in (OVER-WHELMING, I know, I was so overwhelmed when I was first learning to code myself using quest many years ago, lol) and understand, if you're new to coding.


if you want to see me struggling to learn to code (it's a good laugh for me looking back on it now, as I'm like man was I stupid... but that's coming from someone who now understands all of this stuff, but back then, I didn't understand this stuff and so it showed/shows, being confused with the terms and concepts as I didn't really fully understand them, like I do now --- which makes it hard for me to help new people to coding as the stuff I say makes sense to me, but not to the new people I'm trying to help, lol):

https://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread

I was so overwhelmed and confused by all of the terms and concepts and etc... lol


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

Support

Forums