Using attributes in the web version

ScaryCat
09 Jan 2017, 20:02

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


The Pixie
09 Jan 2017, 21:38

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

ScaryCat
10 Jan 2017, 19:16

Ok, I'll try that. Thank you!


ScaryCat
11 Jan 2017, 21:59

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

hegemonkhan
12 Jan 2017, 00:49

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
</object>

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: http://docs.textadventures.co.uk/quest/scripts/create.html )


ScaryCat
12 Jan 2017, 01:40

Thank you. It works!