tinpont Posted October 15, 2014 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 4 Reputation: 0 Joined: 10/15/14 Last Seen: April 2, 2019 Share Posted October 15, 2014 (edited) 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 October 15, 2014 by tinpont Quote Link to comment Share on other sites More sharing options...
Winz Posted October 15, 2014 Group: Members Topic Count: 22 Topics Per Day: 0.00 Content Count: 1479 Reputation: 174 Joined: 12/14/11 Last Seen: November 21, 2016 Share Posted October 15, 2014 (edited) 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 October 15, 2014 by Winz Quote Link to comment Share on other sites More sharing options...
tinpont Posted October 16, 2014 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 4 Reputation: 0 Joined: 10/15/14 Last Seen: April 2, 2019 Author Share Posted October 16, 2014 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. Quote Link to comment Share on other sites More sharing options...
Winz Posted October 16, 2014 Group: Members Topic Count: 22 Topics Per Day: 0.00 Content Count: 1479 Reputation: 174 Joined: 12/14/11 Last Seen: November 21, 2016 Share Posted October 16, 2014 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)? Quote Link to comment Share on other sites More sharing options...
tinpont Posted October 16, 2014 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 4 Reputation: 0 Joined: 10/15/14 Last Seen: April 2, 2019 Author Share Posted October 16, 2014 (edited) 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 October 16, 2014 by tinpont Quote Link to comment Share on other sites More sharing options...
Winz Posted October 16, 2014 Group: Members Topic Count: 22 Topics Per Day: 0.00 Content Count: 1479 Reputation: 174 Joined: 12/14/11 Last Seen: November 21, 2016 Share Posted October 16, 2014 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.. Quote Link to comment Share on other sites More sharing options...
Emistry Posted October 16, 2014 Group: Forum Moderator Topic Count: 93 Topics Per Day: 0.02 Content Count: 10018 Reputation: 2372 Joined: 10/28/11 Last Seen: 20 hours ago Share Posted October 16, 2014 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 Quote Link to comment Share on other sites More sharing options...
tinpont Posted October 16, 2014 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 4 Reputation: 0 Joined: 10/15/14 Last Seen: April 2, 2019 Author Share Posted October 16, 2014 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. Quote Link to comment Share on other sites More sharing options...
Question
tinpont
code first.
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 tinpontLink to comment
Share on other sites
7 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.