## [SOLVED!] Gamebook mode: changing a counter by another counter's value?

I posted here a year or two ago and you guys were wonderfully helpful. As is normal, I think a lot of people start on way-too-huge projects and them put them down after getting overwhelmed, and then suddenly dive back in months or years later with renewed determination. That's me, anyway!

I have another question about the Gamebook mode I can't seem to figure out and would really appreciate the help. How does one change a counter value by another counter's value? For instance, if there was a bunch of gold piling up in a card game and the game is tracking how much, and then you win the hand, how do I change your personal gold counter by the value of the counter that was tracking how much gold was in the middle of the pot?

Thanks in advance if anyone knows and has the time to help!

P.S. this is in Gamebook mode and not Text Adventure mode. There's a REALLY ugly way to do it, but I was hoping for something simpler. The ugly way is as follows:

SetCounter ("yourgold", 3)
SetCounter ("potentialwinnings", //whatever amount of gold was being counted here//)
if (GetInt(game, "potentialwinnings") = 1) {
ChangeCounter ("yourgold", 1)
}
if (GetInt(game, "potentialwinnings") = 2) {
ChangeCounter ("yourgold", 2)
}
if (GetInt(game, "potentialwinnings") = 3) {
ChangeCounter ("yourgold", 3)
}

...

And then I'd have to do that for every conceivable amount of gold, over and over, to add it to your gold counter. Which is awful.

I was hoping there was someway to cheat a reference to a counter into the Gamebook code, with something as simple as:

ChangeCounter ("yourgold", {counter:potentialwinnings})

Or something along those lines.

a 'counter' is just an Integer Attribute (which holds a non-decimal Value, and thus you can use it to do arithmetic operations: addition, subtraction, multiplication, division, and modulus).

the built-in 'increase/decrease counter' Script options in the GUI/Editor is only able to increase/decrease by addition/subraction and +1/-1 for the Value.

In code, all Attributes look like this:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE

and if you want to set/re-set/change/alter an Attribute's Value (or create an Attribute):

in code:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION

in GUI/Editor:

run as script -> 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

the '[EXPRESSION]' script option lets you code/type in what you want it to do, otherwise if you're able to, you can choose the [xxx] option (I'm not familiar with the GUI/Editor, so I always cheat and use the '[EXPRESSION]' option) for doing what you want (some stuff requires you to use the '[EXPRESSION' script option)

the Game Book only has two Objects that you can add Attributes to:

the 'game' Game Settings Object and the 'player' Player Object

so, for examples:

player.strength_integer_attribute = 100
game.strength_integer_attribute = 100

player.strength_integer_attribute = player.strength_integer_attribute + 7 // addition
player.strength_integer_attribute = player.strength_integer_attribute * 4 // multiplication
player.strength_integer_attribute = player.strength_integer_attribute - 9 // subtraction
player.strength_integer_attribute = player.strength_integer_attribute / 2 // division

player.damage_integer_attribute = player.weapon_damage_integer_attribute + player.weapon_damage_integer_attribute * player.strength_integer_attribute / 100

the Game Book may or not have the special 'changed' Script Attribute implemented into it, if it does, then you can use it, for example (in code) of a sample game:

``````<game name="example_game">
<attr name="state_integer_attribute" type="int">0</attr>
<attr name="cash_pile_integer_attribute" type="int">0</attr>
<attr name="changedstate_integer_attribute" type="script">
<![CDATA[
if (game.state_integer_attribute = 2) {  // you won the card game
player.cash_integer_attribute = player.cash_integer_attribute + game.cash_pile_integer_attribute
game.cash_pile_integer_attribute = 0
game.state_integer_attribute = 0
} else if (game.state_integer_attribute = 1) { // you lost the card game
game.cash_pile_integer_attribute = game.cash_pile_integer_attribute + player.cash_integer_attribute
player.cash_integer_attribute = 0
game.state_integer_attribute = 0
} else { // game.state = 0
if (result) {
play_game_function
} else {
msg ("you decided to stop playing")
msg ("Your cash: " + player.cash_integer_attribute)
if (player.cash_integer_attribute > 666) {
msg ("You got a great score!")
} else if  (player.cash_integer_attribute > 333) {
msg ("You got an average score!")
} else {
msg ("You got a poor score!")
}
wait {
msg ("GAME OVER")
finish
}
}
}
}
]]>
</attr>
<attr name="start">
play_game_function
</attr>
</game>

<object name="room">
</object>

<object name="player">
<attr name="parent" type="object">room</attr>
<attr name="cash_integer_attribute" type="int">0</attr>
</object>

<function name="play_game_function">
// blah scripting
// if you win:
// game.state = 2
// if you lose:
// game.state = 1
</function>
``````

otherwise, you can use the 'Turnscript' Element if Game Bookds doesn't have the special 'changed' Script Attribute.

for a more detailed guide on using Attributes and the 'if' Script:

some of the stuff is Text Adventure only... but the scripting is the same (for the most part) for Game Book and Text Adventure

if you have any questions, or need help with anything, let us know!

Um...
Do something like...,
if game.counter > 4
If game.counter = 1
...
If game.counter = 2
...
If game.counter = 3
...
Basically what this does, is it sets a limit on the counter. None of that "game.counter = 100000..." stuff.

This is amazing @hegemonkhan!

I think you were the one a year or two ago who wrote this little ditty for me:

player.previous_page = player.current_page
player.current_page = player.parent
if (player.current_page = Character Sheet) {
player.parent.options = NewStringDictionary()
}

Which let me offer the player the option to view their character sheet whenever I wanted, and it returns them back to the last page they were on after viewing the character sheet. That was invaluable to me (especially in Gamebook mode)!

So look, I'm just surprised there's not an easier way to do this, and forgive me if I mistook what you laid out above.

A counter is counting things every time I tell it to. I'm changing it constantly in the story (you find 420 gold! you lose 187 gold!) and the counter is counting it flawlessly. And I can reference that counter and get it to do stuff. If that counter is equal to or less then 302, I can make it end the game, or I can make it offer up any number of things to do.

That's why I'm surprised there's just not a simple little string of code where a counter can reference another counter. Like: "whatever counter 1 equals, add or subtract that amount to counter 2."

Do you know what I mean? Or did I not read you correctly above?

If I'm misreading you, can you put it in the format of the code above (which you wrote!), something I can add to the "game" object of in the Gamebook mode? I'm not familiar enough to do it, and believe me, I try every little thing I think is intuitive before I give up. Turns out I'm not very intuitive. :(

Hi @jmnevil54!

I'm not so much worried out limiting the upper bounds of a counter (is less/more than, etc.) , I just want a counter to add its current value to another counter.

Counter 1 = 10
Counter 2 = 15

How do I tell Counter 1 to add the value of Counter 2 to it?

``````SetCounter ("counter1", 10)
SetCounter ("counter2", 15)
SetCounter ("counter2", game.counter1 + game.counter2)
msg (game.counter2)
``````

or

``````game.counter1 = 10
game.counter2= 15
game.counter2= game.counter1 + game.counter2
msg (game.counter2)
``````

Nailed it! Works perfect. Thanks so much guys! I knew there was something simple. I just don't quite understand the 'game' object very well, like how to use it syntactically correct. This sheds a lot of light on it for me. This is going to let me do all kindsa crap just with counters. Love it! You guys always come to the rescue.

quest's underlying containment (child-parent) heirarchy:

root/main OBJECT (the 'asl' tag block)
-> Sub-OBJECTS (the 'Elements': the special 'game' Game Settings Object - it's separate from the other Objects, Objects --- these are the other Objects --- Room Objects ~ Player Objects ~ non-room and non-player Objects, Verbs, Commands, Functions, Timers, Turnscripts, Object Types, etc)

so, the actual GAME OBJECT (the root/main OBJECT) is the 'asl' tag block:

``````<asl>
</asl>
``````

whereas, not to be confused with this special sub-Object (the 'game' GAME SETTINGS Object) within the actual GAME OBJECT (the 'asl' tab block):

``````<asl version="555"> // <----- the GAME OBJECT (the root/main OBJECT)
<game name="blah"> // <---------- the  special 'game' Game Settings Object 'special Object: game' Element (Element = Sub-OBJECT)
</game>
<object name=room"> // <--------- the default 'room' Room Object 'normal Object: Object' Element (Element = Sub-OBJECT)
<object name="player"> // <--------- the default 'player' Player Object 'normal Object: Object' Element (Element = Sub-OBJECT)
</object>
</object>
</asl>
``````

the special 'game' Game Settings Object is the same as in the GUI/Editor's 'tree of stuff' on the left side:

(Desktop/offline version of Quest, not sure if web/online and/or Game Book at the 'tree of stuff' on the left side)

(default new game)
Objects
-> Game <------- this is the special 'game' Game Settings Object
-> room
->-> player
Functions
Timers
Walkthrough
-> Included Libraries
->-> 'English.aslx'
->-> 'Core.aslx'
-> Templates
-> Dynamic Templates
-> Object Types
-> JS (JavaScript)

the 'game' Game Settings Object is an Object just like the 'player' Player Object, in that you can add Attributes to it (and it can also have/use the special 'statusattributes' Stringdictionary Attributes/feature too), though it also has a lot of built-in stuff for handling the Game's Settings, Info (non-game play / publishing online for people to see/read), and etc controls/effects, which is what makes it a special Object.

to use 'game' in code, it's just like any other Object:

player.strength_integer_attribute = 100
orc.strength_integer_attribute = 100
game.strength_integer_attribute = 100

player.flying_boolean_attribute = true
orc.flying_boolean_attribute = true
game.flying_boolean_attribute = true

msg ("Player Strength: " + player.strength_integer_attribute)
msg ("Orc Strength: " + orc.strength_integer_attribute)
msg ("Game Strength: " + game.strength_integer_attribute)

msg ("Player Condition: " + player.condition_string_attribute)
msg ("Orc Condition: " + orc.condition_string_attribute)
msg ("Game Condition: " + game.condition_string_attribute)

msg ("Player Flying: " + player.flying_boolean_attribute)
msg ("Orc Flying: " + orc.flying_boolean_attribute)
msg ("Game flying: " + game.flying_boolean_attribute)

and... with not knowing/realizing that for whatever you're doing, that you wanted to do: VARIABLE_2 = VARIABLE_2 + VARIABLE_1,

I didn't even realize that we could use Pertex' method (for this application that you wanted) as he did. I know of adding one variable to another variable, but didn't realize that this is what you wanted or that this can be used to achieve whatever effect/design that you wanted.

(Pertex is a great programmer, I'm still a noobie coder, sighs)

my code works a bit different, as when the game-round is won, it's tagged/flagged/indicated as won, and thus that tag/flag/indication is then used for adding the cash pile to your own cash, assuming this is what you want with your card game..., and when you lose, the same is done, with your cash going into the cash pile, again assuming this is what you want with your card game..., and you're asked if you want to play another game-round.

P.S.

you can have a as complex/long an expression as you want:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION

for example (using Game Book's limitation of the 'player' and 'game' Objects only for adding Attributes to them):

``````<page name="Page1"> // or: <object name="Page1">
</page> // or: </object>

<object name="player">

<attr name="parent" type="object">Page1</attr> // or: <attr name="parent" type="page">Page1</attr>

<attr name="strength_integer_attribute" type="int">0</attr>

<attr name="damage_integer_attribute" type="int">1</attr>

<attr name="weapon_damage_integer_attribute" type="int">1</attr>

<attr name="changedweapon_damage_integer_attribute" type="script">
player.damage_integer_attribute = player.weapon_damage_integer_attribute + player.weapon_damage_integer_attribute * player.strength_integer_attribute / 100
</attr>

<attr name="weapon_string_attribute" type="string">unarmed</attr>

<attr name="changedweapon_string_attribute" type="script">
if (player.weapon_string_attribute = "unarmed") {
player.weapon_damage_integer_attribute = 1
if (player.weapon_string_attribute = "katana") {
player.weapon_damage_integer_attribute = 50
}
</attr>

</object>

player.strength_integer_attribute = 100
player.weapon_string_attribute = "katana"
// player.damage_integer_attribute = 50 + 50 * 100/100 = 50 + 50 = 100

player.strength_integer_attribute = 75
player.weapon_string_attribute = "katana"
// player.damage_integer_attribute = 50 + 50 * 75/100 = 50 + 75/2 = 50 + 37 = 87

player.strength_integer_attribute = 0
player.weapon_string_attribute = "katana"
// player.damage_integer_attribute = 50 + 50 * 0/100 = 50 + 0 = 50

player.strength_integer_attribute = 100
player.weapon_string_attribute = "unarmed"
// player.damage_integer_attribute = 1 + 1 * 100/100 = 1 + 1 = 2

player.strength_integer_attribute = 0
player.weapon_string_attribute = "unarmed"
// player.damage_integer_attribute = 1 + 1 * 0/100 = 1 + 0 = 1
``````

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

Quest
Squiffy
ActiveLit

Documentation
Blog
GitHub

Forums