Jump to content
  • 0

calling variables in variables..?


Question

Posted (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 by sizenine

9 answers to this question

Recommended Posts

Posted

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.

Posted

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];

Posted (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 by sizenine
Posted

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

Posted

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.

Posted (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 by Emistry
Posted (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 by sizenine

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...