Using attributes in the web version

I know there isn't a tab for adding attributes to an object in the web version, but in the variables category when you go to "run a script" there are options for setting attributes on an object. So far I haven't been able to successfully use any of them. Can anyone explain the process to me? For example, when you feed the piranhas they go from attribute "ravenous" to "lethargic".

Set up the attribute in the start script of the game object. In code view like this:

piranhas.state = "ravenous"

In the GUI view, it should look a bit like this:

Set variable [piranhas.state] = [expression] ["ravenous"]

Then in whatever causes them to change (feed verb or command script?), the code would be:

piranhas.state = "lethargic"

Set variable [piranhas.state] = [expression] ["lethargic"]

You might also want to change the "Look at" object description to be a script, and put in something like this:

if (piranhas.state = "lethargic") {
  msg(The cute little fish are swimming serenely.")
else {
  msg("The ferocious fish are snapping at anything that moves.")

Ok, I'll try that. Thank you!

I tried what you said, but I keep getting this error:
Error running script: Error compiling expression 'piranhas.state = "lethargic"': Unknown object or variable 'piranhas'

I'm not sure what I did wrong. The codes look like this (I'm actually changing a few names to avoid giving away too much of how to win; e.g "piranhas" is a substitute for another object):
For "Start Script" - [Set variable]
piranhas.state = "ravenous"

For "feed piranhas " command - [Set variable]
piranhas.state = "lethargic"

For "Pet" verb

if (piranhas.state = "lethargic") {
  msg ("They swim past your hand")
else {
  msg ("they bite")

Your 'piranhas/whatever' needs to be an actual Object (make sure the spelling matches up as spelling counts, including upper/lower case sensitivity):

(this is what it should roughly look like in code --- err, maybe can't see your game code due to web version... meh)

<object name="piranhas">
  <attr name="state" type="string">unknown</attr> // you can change 'unknown' to whatever default/initial/starting state you want it to be

the scripting (piranhas.state = "unknown") will create/add the Attribute tag as you see above, but not the Object. You have to create/add the Object yourself (or use the 'create' Function/Script: )

Thank you. It works!

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