Jump to content
  • 0

problem with setd and getd


tinpont

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/15/14
  • Last Seen:  

code first.

setarray .headgear0_0[0],5210,2254,10,7063,50,7168,200,7038,200,10000000;
setarray .headgear0_1[0],5254,5132,1,5068,1,2255,1,7023,5,983,1,10000000;

.@i = 0;
.@j = 1;
.@headgear = getd(".headgear" + .@i + "_" + .@j);
debugmes getarraysize(.@headgear);      // output 1
debugmes .@headgear;    // output 5254

I want to get the entire array from dynamic string, but the result not my expect.

I already read document here: http://rathena.org/wiki/Variables#Simulating_Multidimensional_Arrays , but not telling me how to get entire array dynamic.

 

Am I missing something or my way is wrong ?

Sorry for my poor English....

Edited by tinpont
Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  1479
  • Reputation:   172
  • Joined:  12/14/11
  • Last Seen:  

getarraysize (.@headgear); will of course return the value of 1.

think about this:

.@i = 0;
.@j = 1;
.@headgear = getd(".headgear" + .@i + "_" + .@j); ---> .@headgear = .headgear0_1;  right?
 

Therefore, getarraysize(.@headgear); will ofc be 1. (because .headgear0_1 is the same as .headgear0_1[0] (C's rule))

(could be different in implementation, tho..)

 

but if you want to print all elements on the array, then it shall be like this:

for (.@i = 0; .@i <10; .@i++ <or i think: set .@i, .@i+1> {
  for (.@j = 0; .@j<=1; .@j++) {
    for (.@k = 0; .@k<10; .@k++){
      .@headgear = getd(".headgear" + .@i + "_" + .@j + "[" + k + "]");
      debugmes .@headgear;
    }
  }
}

if you want to print the item name, then.....

for (.@i = 0; .@i <10; .@i++ <or i think: set .@i, .@i+1> {
  for (.@j = 0; .@j<=1; .@j++) {
    for (.@k = 0; .@k<10; .@k++){
      .@headgear = getd(".headgear" + .@i + "_" + .@j + "[" + k + "]");
      .@headgearname$ = getitemname(.@headgear);
      debugmes .@headgearname$;
    }
  }
}

is it the question?

Edited by Winz
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/15/14
  • Last Seen:  

getarraysize (.@headgear); will of course return the value of 1.

think about this:

.@i = 0;

.@j = 1;

.@headgear = getd(".headgear" + .@i + "_" + .@j); ---> .@headgear = .headgear0_1;  right?

 

Therefore, getarraysize(.@headgear); will ofc be 1. (because .headgear0_1 is the same as .headgear0_1[0] (C's rule))

(could be different in implementation, tho..)

 

but if you want to print all elements on the array, then it shall be like this:

for (.@i = 0; .@i <10; .@i++ <or i think: set .@i, .@i+1> {
  for (.@j = 0; .@j<=1; .@j++) {
    for (.@k = 0; .@k<10; .@k++){
      .@headgear = getd(".headgear" + .@i + "_" + .@j + "[" + k + "]");
      debugmes .@headgear;
    }
  }
}

if you want to print the item name, then.....

for (.@i = 0; .@i <10; .@i++ <or i think: set .@i, .@i+1> {
  for (.@j = 0; .@j<=1; .@j++) {
    for (.@k = 0; .@k<10; .@k++){
      .@headgear = getd(".headgear" + .@i + "_" + .@j + "[" + k + "]");
      .@headgearname$ = getitemname(.@headgear);
      debugmes .@headgearname$;
    }
  }
}

is it the question?

Hey, Winz, Thank you for your reply.

 

As you can see, the array size of .headgear{i}_{j} is dynamic(not confirm).

How can I get the array size? Use while(.headgear{i}_{j}[k]) or something  to calculate?

I think I should read some source code first. Thanks.

Final I found out how to get array size dynamic.

.@count = getarraysize(getd(".HLGFHeadgear" + .@i + "_" + .@j));

I think .@var is a pointer before, but I realize it is a copy pointer with it's own structure (int). So this is why I always get array size equal 1.

And getd actually return array's pointer, so it could read size easily. Thank you Winz.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  1479
  • Reputation:   172
  • Joined:  12/14/11
  • Last Seen:  


I think .@var is a pointer before, but I realize it is a copy pointer with it's own structure (int). So this is why I always get array size equal 1.

this is the thing that I'd like to say since last night.

 

sure, np!

 

//off topic

shouldn't it be GLHF? (Good Luck Have Fun)?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/15/14
  • Last Seen:  

 

I think .@var is a pointer before, but I realize it is a copy pointer with it's own structure (int). So this is why I always get array size equal 1.

this is the thing that I'd like to say since last night.

 

sure, np!

 

//off topic

shouldn't it be GLHF? (Good Luck Have Fun)?

 

Yeah, programming is fun. Thank you.

 

But I just found out a bug, if last element of array is 0, getarraysize will not corrected.

setarray .headgear[0],2237,1020,100,983,1,2241,1,0;
debugmes getarraysize(getd(".headgear"));     // output 7

But it's not a big deal.

Edited by tinpont
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  1479
  • Reputation:   172
  • Joined:  12/14/11
  • Last Seen:  

i guess rA treats last element array to be null if it's 0. or maybe you can change them to string array variable (i don't recommend it)

 

wow, you changed your profile pic! I thought somebody replied to this thread as well..

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

you can also do like this.

setarray .headgear0_0[0],5210,2254,10,7063,50,7168,200,7038,200,10000000;
setarray .headgear0_1[0],5254,5132,1,5068,1,2255,1,7023,5,983,1,10000000;


.@x = .@y = 0;
.@size = getarraysize( getd( ".headgear"+.@x+"_"+.@y ) )
// copy to a temporary array
copyarray .@temp_array,getd( ".headgear"+.@x+"_"+.@y ),.@size;

// check value
for( .@i = 0; .@i < .@size; .@i++ )
	mes ".headgear"+.@x+"_"+.@y+"["+.@i+"] = "+.@temp_array[.@i];
close;

way better than having a nested for-loop

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   0
  • Joined:  10/15/14
  • Last Seen:  

i guess rA treats last element array to be null if it's 0. or maybe you can change them to string array variable (i don't recommend it)

 

wow, you changed your profile pic! I thought somebody replied to this thread as well..

Yeah, array is better than string. Thank you for your help.

 

you can also do like this.

setarray .headgear0_0[0],5210,2254,10,7063,50,7168,200,7038,200,10000000;
setarray .headgear0_1[0],5254,5132,1,5068,1,2255,1,7023,5,983,1,10000000;


.@x = .@y = 0;
.@size = getarraysize( getd( ".headgear"+.@x+"_"+.@y ) )
// copy to a temporary array
copyarray .@temp_array,getd( ".headgear"+.@x+"_"+.@y ),.@size;

// check value
for( .@i = 0; .@i < .@size; .@i++ )
	mes ".headgear"+.@x+"_"+.@y+"["+.@i+"] = "+.@temp_array[.@i];
close;

way better than having a nested for-loop

 

Great, a new way to deal with dynamic array. Thank you, Emistry.

Link to comment
Share on other sites

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.

×
×
  • Create New...