sizenine Posted March 22, 2012 Posted March 22, 2012 (edited) i have arrays named: $@box_1[0] $@box_2[0] $@box_3[0] $@box_4[0] $@box_5[0] $@box_6[0] set .@num, rand (1,6); i want to use a variable .@num to call an array in a for loop but the following code won't seem to work: for(set .@i,0; .@i < getarraysize("$@box_"+.@num); set .@i,.@i+1) { attachrid "$@box_"+(.@num)+"["+.@i+"]"; - script - detachrid; } deletearray "$@box_"+(.@num)+"[0]",128; any ideas? Edited March 22, 2012 by sizenine Quote
Panallox Posted March 22, 2012 Posted March 22, 2012 doc/script_commands Ctrl+F *getd Enter I love you. 1 Quote
sizenine Posted March 23, 2012 Author Posted March 23, 2012 for(set .@i,0; .@i < getarraysize(getd("$@box_"+.@num+"")); set .@i,.@i+1) { attachrid getd("$@box_"+(.@num)+"["+.@i+"]"); - script - detachrid; } deletearray getd("$@box_"+(.@num)+"[0]"),128; does this look right? it doesnt seem to be working.. no errors either. Quote
Emistry Posted March 23, 2012 Posted March 23, 2012 but why not simply do your array like this ? save the value into 1 array ? setarray $@Box,<value>,<value>,<value>; then you can simply write a loop process for it... for( set .@i,0; .@i < getarraysize( $@Box ); set .@i,.@i + 1 ) attachrid $@Box[.@i]; Quote
sizenine Posted March 23, 2012 Author Posted March 23, 2012 (edited) Yeah I wouldn't have made so many arrays if i didn't need to. But of course I did that because the values in each can't be mixed in one array. As you see, I wipe the array afterwards. Yeah I wouldn't have made so many arrays if i didn't need to. But of course I did that because the values in each can't be mixed in one array. As you see, I wipe the array afterwards. Each time the function is called, a different box runs the script and gets deleted. Edited March 23, 2012 by sizenine Quote
Emistry Posted March 23, 2012 Posted March 23, 2012 owh..i though you just use each array to store 1 value anyway...in your post#5 ...it doesnt remove the array completely.. to remove the array completely....you have to include that deletearray command inside the for-loop.. or you can also create another for-loop just for delete the array Quote
sizenine Posted March 23, 2012 Author Posted March 23, 2012 How does it not delete it? I think that command is for clearing all values in the array up to size 128. But my problem now is that the -script- inside is not running. So I think some of the getd formatting might be off. Quote
Emistry Posted March 23, 2012 Posted March 23, 2012 (edited) deletearray getd("$@box_"+(.@num)+"[0]"),128; in your script..it only delete the last array...... because ... your .@num end up with 6 and the rest is not deleted because you didnt run this command in the loop process and this line for(set .@i,0; .@i < getarraysize(getd("$@box_"+.@num+"")); set .@i,.@i+1) { suppose to be for(set .@i,0; .@i <= 6); set .@i,.@i+1) { because you are going to loop through how many Array you have..but not how many value you have in the array Look at the wrong variable...LOL >.< Edited March 23, 2012 by Emistry Quote
sizenine Posted March 23, 2012 Author Posted March 23, 2012 (edited) You're not understanding my script correctly... let try to me explain... deletearray getd("$@box_"+(.@num)+"[0]"),128; in your script..it only delete the last array...... because ... your .@num end up with 6 and the rest is not deleted because you didnt run this command in the loop process Yes I know that. Because it is only supposed to delete one array (the one that was assigned by the rand .@num) each time the function is called. and this line for(set .@i,0; .@i < getarraysize(getd("$@box_"+.@num+"")); set .@i,.@i+1) { suppose to be for(set .@i,0; .@i <= 6); set .@i,.@i+1) { because you are going to loop through how many Array you have..but not how many value you have in the array That is wrong, because .@num is not the size of the array... that's only the number of box 1 to 6. Every single box (1-6) is an array, and they ALL will have a bunch of values added into its array. The point of assigning .@num is so it can take just one of the box (array) and make it go through the loop to run a script (on the account ID's stored in the array). After the script runs (for each account ID in the appointed array/box), those IDs are no longer needed, which is why I use deletearray to get rid of only that appointed array/box... It's definitely something wrong with the formatting of the getd() because I tried directly applying the numbers instead of using .@num and it worked. Example: for(set .@i,0; .@i < getarraysize($@box_3); set .@i,.@i+1) { attachrid $@box_3["+.@i+"]; atcommand "@hide"; atcommand "@option 0 0 0"; warp "SavePoint",0,0; detachrid; } deletearray $@rwc_spectate_7[0],128; end; this worked with no problems at all, so the only thing that's not working is when i try to use .@num with getd. UPDATE: Fixed the formatting and it works perfectly now: for(set .@i,0; .@i < getarraysize(getd("$@box_"+(.@num))); set .@i,.@i+1) { attachrid getd("$@box_"+(.@num)+"["+.@i+"]"); -script- detachrid; } deletearray getd("$@box_"+(.@num)+"[0]"),128; Edited March 23, 2012 by sizenine Quote
Question
sizenine
i have arrays named:
$@box_1[0]
$@box_2[0]
$@box_3[0]
$@box_4[0]
$@box_5[0]
$@box_6[0]
set .@num, rand (1,6);
i want to use a variable .@num to call an array in a for loop but the following code won't seem to work:
any ideas?
Edited by sizenine9 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.