PDA

View Full Version : Arrays..


pig132
07-16-2007, 02:29 PM
I have NO idea how to use arrays and thought maybe this would work, also, how can i find out if the players 2nd word is eqaul to one of the words in the array?
I tried this, but failed. Help would be appreciated.

if (created) {
this.events = {"test","race","idle"};
}
if (playerchats&&startswith(:select,#c)) {
tokenize #c;
if (#t(1) != this.events)) {
setplayerprop #c,Error: Event not found!;
}
if (#t(1) = this.events)) {
setplayerprop #c,Event chosen!;
}
}

xXziroXx
07-16-2007, 06:16 PM
if (created) {
this.events = {"test","race","idle"};
}

if (playerchats && startswith(:select,#c)) {
tokenize #c;
if (lindexof(#t(1),#s(this.events)) == -1) {
setplayerprop #c,Error: Event not found!;
} else {
setplayerprop #c,Event chosen!;
}
}

Possibly replace lindexof(#t(1),#s(this.events)) with lindexof(#t(1),this.events).

:)

Twinny
07-16-2007, 06:56 PM
I thought using "string" in GS1 isn't valid :confused:

Inverness
07-16-2007, 07:15 PM
You're mixing GS2 with GS1 up at the top there. You would use

//GS1
if (created) {
setstring this.events,test,race,idle;
}

if (playerchats && startswith(:select,#c)) {
tokenize #c;
if (lindexof(#t(1),this.events) == -1) {
setplayerprop #c,Error: Event not found!;
} else {
setplayerprop #c,Event chosen!;
}
}


//GS2
function onCreated() {
this.events = {"test", "race", "idle"};
}
function onPlayerChats() {
if (player.chat.starts(":select")) {
temp.tokens = player.chat.tokenize();
if (this.events.index(temp.tokens[1]) == -1) {
player.chat = "Error: Event not found!";
}
else {
player.chat = "Event chosen!";
}
}
}

xXziroXx
07-17-2007, 03:50 AM
Oh haha, I overlooked the array setting - should be setstring indeed! ^^