sizenine Posted March 22, 2012 Group: Members Topic Count: 37 Topics Per Day: 0.01 Content Count: 149 Reputation: 13 Joined: 02/17/12 Last Seen: January 25, 2018 Share 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 Link to comment Share on other sites More sharing options...
Gepard Posted March 22, 2012 Group: Members Topic Count: 22 Topics Per Day: 0.00 Content Count: 392 Reputation: 285 Joined: 12/19/11 Last Seen: January 23, 2022 Share Posted March 22, 2012 doc/script_commands Ctrl+F *getd Enter 2 Quote Link to comment Share on other sites More sharing options...
Panallox Posted March 22, 2012 Group: Members Topic Count: 12 Topics Per Day: 0.00 Content Count: 117 Reputation: 169 Joined: 11/10/11 Last Seen: April 10, 2024 Share Posted March 22, 2012 doc/script_commands Ctrl+F *getd Enter I love you. 1 Quote Link to comment Share on other sites More sharing options...
sizenine Posted March 23, 2012 Group: Members Topic Count: 37 Topics Per Day: 0.01 Content Count: 149 Reputation: 13 Joined: 02/17/12 Last Seen: January 25, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
Emistry Posted March 23, 2012 Group: Forum Moderator Topic Count: 93 Topics Per Day: 0.02 Content Count: 10018 Reputation: 2370 Joined: 10/28/11 Last Seen: Sunday at 05:32 PM Share 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 Link to comment Share on other sites More sharing options...
sizenine Posted March 23, 2012 Group: Members Topic Count: 37 Topics Per Day: 0.01 Content Count: 149 Reputation: 13 Joined: 02/17/12 Last Seen: January 25, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
Emistry Posted March 23, 2012 Group: Forum Moderator Topic Count: 93 Topics Per Day: 0.02 Content Count: 10018 Reputation: 2370 Joined: 10/28/11 Last Seen: Sunday at 05:32 PM Share 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 Link to comment Share on other sites More sharing options...
sizenine Posted March 23, 2012 Group: Members Topic Count: 37 Topics Per Day: 0.01 Content Count: 149 Reputation: 13 Joined: 02/17/12 Last Seen: January 25, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
Emistry Posted March 23, 2012 Group: Forum Moderator Topic Count: 93 Topics Per Day: 0.02 Content Count: 10018 Reputation: 2370 Joined: 10/28/11 Last Seen: Sunday at 05:32 PM Share 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 Link to comment Share on other sites More sharing options...
sizenine Posted March 23, 2012 Group: Members Topic Count: 37 Topics Per Day: 0.01 Content Count: 149 Reputation: 13 Joined: 02/17/12 Last Seen: January 25, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
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 sizenineLink to comment
Share on other sites
9 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.