PDA

View Full Version : Help With For();


Rapidwolve
10-21-2006, 07:19 PM
I am making a QMenu that gets its information from an ItemLib.

Lets say I have clientr.items= 421,320,52. I would use
for (i = 0; i < clientr.items.size(); i++)

How would I make it so I can use for(); with something such as:
clientr.item_421
clientr.item_320
clientr.item_52

Without having to have clientr.items

Yen
10-21-2006, 07:20 PM
for (i: clientr.items) {

}

i will be every element of clientr.items

Rapidwolve
10-21-2006, 07:32 PM
public function listLib(){
temp.list.loadvars(this.library);
for (i: temp.list.getstringkeys("item-")){
echo("Items: " @ i);
}
return;
}


I figured out part of it thanks to Yen on aim, its supposed to echo all the id's in the text file. But it's not working

xAndrewx
10-21-2006, 07:32 PM
for (curItem: getstringkeys("clientr.items"))
{
curItem stuff
}

To new one:
What is 'this.library'?

Yen
10-21-2006, 07:41 PM
getstringkeys() requires a bit of hacking when you use it like that.

Rapidwolve
10-21-2006, 07:46 PM
for (curItem: getstringkeys("clientr.items"))
{
curItem stuff
}

To new one:
What is 'this.library'?

this.library is "scriptfiles/ur_itemlib.txt"

Also:

GraalScript: Function getstringKeys not found at line 67 in script of ItemLib (in level databases.nw at pos (30.5, 30))

xAndrewx
10-21-2006, 07:52 PM
this.library is "scriptfiles/ur_itemlib.txt"

Also:

GraalScript: Function getstringKeys not found at line 67 in script of ItemLib (in level databases.nw at pos (30.5, 30))

Weird?
Works fine for me, I use it all the time:

this.shield_1 = {"Basic Shield", "shield1.png", "tom_icon-shield1.png"};
this.shield_2 = {"Mirror Shield", "shield2.png", "tom_icon-shield2.png"};
this.shield_3 = {"Lizard Shield", "shield3.png", "tom_icon-shield3.png"};

for (temp.curShield: getstringkeys("this.shield_"))
{
echo(temp.curShield);
}

I used it earlier today to just do this... o-O


For the file, I think you'd need to use 'getdynamicvarnames()'

Rapidwolve
10-21-2006, 07:53 PM
Ahh getdynamicvarnames(); Worked, except it returns the "item_" too.

xAndrewx
10-21-2006, 08:10 PM
Maybe use file.substring(5) or maybe makevar would fix it, not too sure. =]

Rapidwolve
10-21-2006, 08:13 PM
Here is the problem with substring.

echo(temp.list.getdynamicvarnames("item_").substring(5,-1));

Echos 372,item_402

It only takes away the first five letters for the first string, and leaves the rest as it is

xAndrewx
10-21-2006, 08:17 PM
Here is the problem with substring.

echo(temp.list.getdynamicvarnames("item_").substring(5,-1));

Echos 372,item_402

It only takes away the first five letters for the first string, and leaves the rest as it is

Ah yes
simple:

for (temp.reMake: temp.list.getdynamicvarnames("item_"))
{
temp.newItems @= temp.reMake.substring(5);
}
message(temp.newItems);

Should work

Rapidwolve
10-21-2006, 08:20 PM
Now it doesnt show the commas x_X
It returns: 372402

But I fixed using
temp.newItems @= temp.reMake.substring(5) @",";

xAndrewx
10-21-2006, 08:24 PM
hehe, glad it works =]

Rapidwolve
10-21-2006, 08:29 PM
Thanks.