Object Counters

I am trying to make a counter, but I don't know how to create them and I need some help getting started.

For example, I'd like to give my character a wallet. When you check it the wallet will say how much money is inside. If you pick up loose change, the amount of money goes up, and if you don't have enough money to pay for something, the wallet will tell you.


What you're trying to do is very easy :)

You have your Object: Wallet
Go to the attributes tab in the Wallet, and click add
Attribute:
money (integer) 0

When you do the scripting for adding money, you would go...

wallet.money = wallet.money + 5

On the description of the object do this...
You have {wallet.money} gold coins remaining.
((It'll look like: You have 5 gold coins remaining)).

To check it for buying something, that would be an "if script"

if (wallet.money >=4) {
msg ("You bought the item!")
MoveObject (blahblah, roomnamehere)
}   
else {
msg ("You can't afford it!")
}

To be honest though, you might want to add money to the Player Object because if the player can drop the wallet or lose it for any reason, then the game will keep adding to the wallet but the player won't be carrying it and won't be able to keep track of how much they have. You would just change "wallet" to "player"; for example...

player.money = player.money + 5 

Hope that helps! BTW this is for a Text Adventure not a GameBook.

Anonynn.


just to add to Anonynn's post:

'counters' are merely Integer Attributes, which you can then also increase (addition or multiplication) or descrease (subtraction or division) upon them

in the GUI/Editor, the 'increase/decrease counter' Script option only does so by +1 or -1, which in code scripting is this:

NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE + 1
or
NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE - 1

if you want to use a different value other than 1 and/or multiplication or division, then you've got to script/code it in yourself, via:

'set a variable or attribute' Script option -> (see below)

set variable NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE = [EXPRESSION] NAME_OF_OBJECT.NAME_OF_INTEGER_ATTRIBUTE OPERATOR VALUE

for examples:

// examples of setting/re-setting/changing/altering its values:

set variable player.strength = [EXPRESSION] 0
// (player.strength = 0)
set variable player.strength = [EXPRESSION] 100
// (player.strength = 100)

// examples of arithmetic operations (setting/re-setting/changing/altering/adjusting its value based on the arithmetic operation done to it):

// (player.strength = 100)
set variable player.strength = [EXPRESSION] player.strength + 50 // (old:100) + 50 = 150
// (player.strength = 150)
set variable player.strength = [EXPRESSION] player.strength * 2 // (old:150) * 2 = 300
// (player.strength = 300)
set variable player.strength = [EXPRESSION] player.strength / 3 // (old:300) / 3 = 100
// (player.strength = 100)
set variable player.strength = [EXPRESSION] player.strength - 100 // (old:100) - 100 = 0
// (player.strength = 0)


P.S.

here's a detailed guide on the 'bread and butter' of scripting/coding and game making: Attribute and the 'if' Script usage:

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


Thanks for the help, but I must confess I'm not quite that familiar with the Quest engine. Where can I find attribute tabs for an object?


If you're using the online editor then you will not see it because it does not have it as a tab, you have to manually code in attributes.


as Onimike said, in the online quest and/or Game Book, there's no 'Attribute' Tabs, so you'll have to use scripting for using/doing your Attributes.


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

Support

Forums