List Function

So I don't know what I am doing wrong. The process seems simple. In the "game" scripts section I put this:

playerSkillsActive = NewStringList()
playerSkillsInactive = NewStringList()

Then in a room exit I have a script that says:

list add (playerSkillsActive, Agility)

And when I run the program it comes up with this error:

Error running script: Error compiling expression 'playerSkillsActive': Unknown object or variable 'playerSkillsActive'

So what am I doing wrong?


Io

I think it's looking for an attribute called Agility, rather than adding the string "Agility".


I've tried it with quotes and without and get the same error.


You're making playerSkillsActive a local variable.

A variable which just has a name exists only within the script that created it, and then disappears. So your list is discarded as soon as the start script finishes.

If you want it to continue existing for use in another script, you have to use an attribute instead of a variable. An attribute continues to exist after the end of the script, and is associated with a particular object. As this variable is clearly related to the player object, you might attach it to the player object.

For example:

player.SkillsActive = NewStringList()
player.SkillsInactive = NewStringList()

The dot means that these attributes will be valid as long as an object named player exists, so they can be used in other scripts.

(if you've named the player object something other than "player", you'd have to use the actual name of the object; or you can use the special expression game.pov, which refers to the player object regardless of what its name is)


Thank you!


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

Support

Forums