Show amount of gold in inventory

Mareus
07 Oct 2015, 01:41
Hey there!

I have been wondering if anyone can tell me what code should i write for showing the amount of gold in my inventory upon looking at the gold in my inventory? The way I added gold into my game was via attributes/integrer. Whenever I find gold I just write the following code: player.gold = player.gold + 100. And then i get 100 gold. It appears neatly in my bar under the health, but I wish to be able to write a command: examine gold/look at gold and then get a description: "you have xx amount of gold in your inventory.

Can anyone help me with that? There has to be a simple code to show this. I tried ListObjectContents (this), but this only gives me a list of objects i am carrying in my inventory. Basically it just tells me You are carrying gold, but it doesnt tell me the amount. I need to list the integrer value of the amount of gold. Thanks in advance.

Mareus
07 Oct 2015, 20:08
Bumping this again. Please can anyone help?

Anonynn
07 Oct 2015, 20:34
I'm not sure if this will help any...but try this.

Go to the "player.object"
and then "Status Attributes"
Click "Add".
And write in the "key": gold

and in the "format string" (exactly as it appears) Gold: !

After that....
Make an "attribute" on the player.object (below inherited types) and call it..... gold (make it lowercase, it'll save you trouble later on)
Make it an integer "0"

I believe that will make it appear "Status" box during the game.

To increase and decrease the gold value, try this...

Set variable player.gold = expression player.gold + 5
((in code it will look like this))

player.gold = player.gold + 5



For subtraction, just put a subtraction sign.

**REMEMBER CAPITALIZATION MATTERS**...... Except in the "Status Attribute, Format String" because that is how the player will see it.

Anonynn
07 Oct 2015, 20:38
I hope I did that correctly. Let me know if it helped or not! You can thank HK for that, he helped me with it a couple of months ago


Oh.....I just realized you already knew how to do that. Sorry I'm an idiot. e_e

Pertex
07 Oct 2015, 21:01
Something like this?

msg("you have {player.gold} amount of gold in your inventory")

HegemonKhan
07 Oct 2015, 23:38
on the left side (the ' tree of stuff ' ), click on Commands:

a new~default game's 'tree of stuff':

Objects
-> game
->-> Verbs
->-> Commands <======= click on this
-> room
->-> player
Functions
Timers
Walkthrough
Advanced
-> Included Libraries
->-> English.aslx
->-> Core.aslx
-> Templates
-> Dynamix Templates
-> Object Types
-> Javascript


now that you clicked on Commands (and it is highlighted), then you can see its settings on the right side, and on the right side, click on ' Add ' (we're going to create~add a Command).

now, let's create our new Command (there's two Tabs for it: ' Command ' and ' Attributes ' ~ it defaults to showing the ' Command ' Tabs options ~ settings, which is what we want, so if you clicked on the ' Attributes ' Tab, click back on the ' Commands ' Tab):

------

Pattern: [Command pattern]

------

(unlabeled text box): (see below)

(this is what you got to type in during game play, for activating this Command, and inputting anything that the Command uses ... but we're not dealing with that for what you want to do, as it's a bit more advanced for right now for you, so better to just ignore it for now)

we need what I like to call an ' activator ' word, this is the first word, that the engine looks at, so let's make it unique, which will ensure that this Command is activated, and not some other Command (which would have its own unique first ' activator ' word too, keeping your Commands correctly separate~distinguished for the engine and its parsing of what you type in, in trying to figure out what you want it to do.

let's use as our ' activator ' word:

info

(or use whatever you want, though keep it short, as you don't want to have to type a long word, lol)

and, this will be it, we're keeping this simple, during game play, whenever you type in ' info ', this Command will activate, doing its scripts (that I show you how~what to add~create~assign further below).

so to be clear:

(unlabeled text box): info // (or whatever you want to use, and you'd have to type in this intead during game play, of course)

-----

Name: character_info_screen_command // (or whatever you want to call it)

----

Unresolved object text: ( ~ I THINK ~ this is what it'll say if you type in a wrong input during game play, so up to you if you want to write anything in this text box or not)

-----

Script: (see below, remember, this is just an example for you, you'd need to add~create all of these Attributes upon your default ' player ' Player Object, of course)

add new script -> output -> ' Clear the Screen ' Script
add new script -> output -> ' Print a message ' Script -> print [expression] "Name: " + player.alias
add new script -> output -> ' Print a message ' Script -> print [expression] "Age: " + player.age
add new script -> output -> ' Print a message ' Script -> print [expression] "Sex: " + player.sex
add new script -> output -> ' Print a message ' Script -> print [expression] "Level: " + player.level
add new script -> output -> ' Print a message ' Script -> print [expression] "Experience: " + player.experience
add new script -> output -> ' Print a message ' Script -> print [expression] "Gold: " + player.gold
add new script -> output -> ' Print a message ' Script -> print [expression] "Strength: " + player.strength
add new script -> output -> ' Print a message ' Script -> print [expression] "Endurance: " + player.endurance
add new script -> output -> ' Print a message ' Script -> print [expression] "Agility: " + player.agility
add new script -> output -> ' Print a message ' Script -> print [expression] "Dexterity: " + player.dexterity
// etc etc etc, you get the idea
add new script -> output -> ' Wait for key press ' Script
-> wait for key press, then run script-> add new script -> output -> ' Clear the Screen ' Script

~OR (using ' text processor commands ' instead of the normal ' variable+text ' scripting) ~

add new script -> output -> ' Clear the Screen ' Script
add new script -> output -> ' Print a message ' Script -> print [expression] "Name: {player.alias}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Age: {player.age}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Sex: {player.sex}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Level: {player.level}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Experience: {player.experience}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Gold: {player.gold}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Strength: {player.strength}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Endurance: {player.endurance}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Agility: {player.agility}"
add new script -> output -> ' Print a message ' Script -> print [expression] "Dexterity: {player.dexterity}"
// etc etc etc, you get the idea
add new script -> output -> ' Wait for key press ' Script
-> wait for key press, then run script-> add new script -> output -> ' Clear the Screen ' Script


this will output (for pretend example):

Name: HK
Age: 18 // I wish I was 18 again, lol
Sex: male
level: 99
Experience: 999999999
Gold: 99999999999999
Strength: 100
Endurance: 100
Agility: 100
Dexterity: 100


this is just for reference (you would do this to actually add~create these Attributes on your character: 'player' Player Object -> 'Attributes' Tab -> Attributes -> Add), but if you're interested in learning to code more, this is how you create~add these Attributes in the code's scripting):

player.alias = "HK" // Attribute Type: string
player.age = 18 // Attribute Type: int (integer)
player.sex = "male" // Attribute Type: string
player.level = 99 // Attribute Type: int
player.experience = 99999999 // Attribute Type: int
player.gold = 99999999999 // Attribute Type: int
player.strength = 100 // Attribute Type: int
player.endurance = 100 // Attribute Type: int
player.agility = 100 // Attribute Type: int
player.dexterity = 100 // Attribute Type: int

------

anyways... the big thing is this:

changing the ' print [MESSAGE] ' to ' print [EXPRESSION] '

the ' print [MESSAGE] ' Script, *ONLY* allows for text~words~sentences~~paragraphs (aka: strings: sequences of characters~symbols, text).

the ' print [EXPRESSION] ' Script allows for ' VARIABLES + text ', which is what you want !!!

for example:

textual part of the 'print [EXPRESSION] ' is: "Name: "
(any value inside of double quotes is a string)

VARIABLE part of the ' print [EXPRESSION] ' is: player.alias

if you know algebra, it's just algebraic substitution:

x = 6
x + 4 = ???
answer = 10

x = "HK"
"Name: " + x
answer: Name: HK

but, instead of ' x ', we're using: player.alias

player.alias = "HK"
"Name: " + player.alias
answer: Name: HK

in programming, the ' + ' (along with being addition for math calculations) is known as "concatenation" for strings.

concatenation is literally~physically, putting things together; next to each other:

Concatenation: "5"+"5" ---> 55
math addition: 5+5 = 10

concatenation: "5"+"5"+"5"+"5" ---> 5555
math addition: 5+5+5+5 = 20

Concatenation: "1010"+"50" ---> 101050
math addition: 1010+50 = 1060

Concatenation: "Name:"+"HK" ---> Name:HK

(spaces are a character~symbol, just like letters, numbers, and etc symbols like !@#$%^&*(), are characters~symbols)

Concatenation: "Name:"+ " " + "HK" ---> Name: HK
Concatenation: "Name: " + "HK" ---> Name: HK
Concatenation: "Name:" + " HK" ---> Name: HK

concatenation: "HK"+"HK"+"HK"+"HK" ----> HKHKHKHK
concatenation: "HK + " " + "HK"+ " " + "HK" + " " + "HK" ----> HK HK HK HK

concatenation: "HK "+"HK "+"HK "+"HK" ----> HK HK HK HK
concatenation: "HK"+" HK"+" HK"+" HK" ----> HK HK HK HK

concatenation: "HK"+"99"+"HK"+"99"+"HK"+"99"+"HK"----> HK99HK99HK99HK

--------------

you do *NOT* put the VARIABLE inside of the double quotes !!!

for example:

"Name: " + "player.alias" -----> WRONG! ERROR!!! (actually there's no error, but you'll get this outputted: Name: player.alias)

..

UNLESS, you're using the text processor commands format method instead:

"Name: {player.alias}"

the text processor commands, *MUST* be inside of the curly brackets, which MUST be inside of the double quotes:

" text {text processor command expression with your VARIABLE} text "

-------------

link for the text processor commands:

http://docs.textadventures.co.uk/quest/ ... essor.html

Mareus
08 Oct 2015, 09:33
Pertex wrote:Something like this?

msg("you have {player.gold} amount of gold in your inventory")

Yes! Thank you Petrex! I knew it was easy, but it never occurred to me to do this through a simple message. Lol! I was trying to find a function to show an attribute number.