Lists - create and check for entries

wertandrew
25 Feb 2016, 11:55
Hey everyone,

So I am trying to log the player's actions and allow one-time activation of an achievement system I am using.

The system I have in mind is split into the input script, and the function that triggers the achievement.
What I stumbled upon is inside the function.
I want to make a string list that takes the parameter given by the input script, checks if the entry exists and if not it creates it and activates the achievement.
That way, each input script has a unique ID and it only triggers once.

I tried using lists and dictionaries but I couldn't get it to work.

I would appreciate if anyone shares a way to do this.


EDIT: the functions ListContains or DictionaryContains always return false for some reason when I check:

gameTracker = NewStringList()
if (ListContains (gameTracker, "chen") ) {
msg ("Entry Exists")
}
else {
msg ("Added")
list add (gameTracker, "chen")
}
msg (gameTracker)

The Pixie
25 Feb 2016, 13:03
Your code creates a new empty list, then checks if a string is in that list, and given you just created it, it will not be.

You need to set up the string list once at the start of the game, either by putting:
game.gameTracker = NewStringList()

... into the stat script on the game object or (if offline) adding gameTracker as an attribute to the game object (and make it a string list). Then your code becomes:
if (ListContains (game.gameTracker, "chen") ) {
msg ("Entry Exists")
}
else {
msg ("Added")
list add (game.gameTracker, "chen")
}
msg (game.gameTracker)

wertandrew
25 Feb 2016, 13:34
The Pixie wrote:*snip


Actually I did this, but didn't know how to make a 'global' attribute. Many thanks.