Jump to content
  • 0

setd / getd used to store AID's


Erebus

Question


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  47
  • Reputation:   7
  • Joined:  11/19/11
  • Last Seen:  

I have an array that will most likely exceed 128 variables (account AID's / getcharid(3) ), so I decided to go with a setd based on what I've been told that it can hold far more and blah blah blah. Problem is that it doesn't seem to act like an array and the documentation for it, just doesn't describe it well enough for me. Here is what I have so far, 2 variations. Top is for adding them to array and bottom is for removing them from it. Neither work but I've substituted them back and forth for making them add to the array. There is nothing ever in the $Events array either.

for(set .@i,0; .@i < GetArraySize(getd("$Events")); set .@i,.@i+1){
					if(getd("$Events"+"["+.@i+"]")!=getcharid(3)){
						setd("$Events"),getcharid(3);
						close2;
						dispbottom "You have been added to Event queue!";
						end;
					}


for(set .@i,0; .@i < GetArraySize(getd($Events)); set .@i,.@i+1){
						if($Events[.@i]==getcharid(3)){
							deletearray getd($Events[.@i]),1;
							close2;
							dispbottom "You have been removed from Event queue!";
							end;

Basically what happens is when I use the 1st one, it breaks out of the for() and continues on to give me my debug error message. Looking over various other setd/getd scripts, it shows the array in "" so I attempted that as well as the scope variable.. The 2nd one tends to give me an error with illegal scope and please report this. However, my test server is 14921 eAthena, I'm assuming that it's already been addressed (haven't set up a rAthena one yet to test that theory). Am I just using the commands wrong or?

I would much rather use 1 long array instead of having to break it up into if getsizeofarray 1 =128, add AID to array 2 and so on, then cycle through all of those arrays.

Edited by Arcenciel
Please use a [Code] next time.
Link to comment
Share on other sites

2 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  241
  • Reputation:   46
  • Joined:  11/08/11
  • Last Seen:  

Ok Imma get my hands dirty, I can't stand watching you while the other nabs ignore u :)(

So first of all, setd,getd doesn't construct an array for you, and you can't ( thats why your getarraysize failed here )

what happens in setd,getd is you basically modify the variable names as "strings", basically the "address" of your variables,

the reason why many suggest to use this instead, is because you can simulate array out of it e.g ".x1, .x2, .x3"

for(set .idx,0; .idx< 256; set .idx,.idx+1)
{
setd ".npcVarArray"+.idx,<somevalue>;
}

here we create 256 variables not a single array, e.g .npcVarArray0,..... .npcVarArray255

but this is very different from an array, they are basically different individuals(variables) but you just know how to refence them by index "simulating arrays" because of the way you named them :P

now if we would like to get the values we can simply ,

for(set .idx,0; .idx< 256; set .idx,.idx+1)
{
mes getd( ".npcVarArray"+.idx);
}

it is obvious that you will not be able to use [] heres (only the core source gods can confirm this) maybe because parser treats this as real arrays ( NOT REALLY SURE GOD DAMN IT XD)

so here in your example :

GetArraySize(getd("$Events"));

you are not accessing the entire array we just created, you are accessing a single element $Events variable nothing else,

there is obviously no way to track the count of our variables now

but we can now simulate somewhat "object" mindset here

we can do

push_array(arraysource,valueTopush);

internally we can do something like

setd ($arraySourceName+"Count"), ($arraySourceName+"Count") + 1; // this will increase our setd collection count
setd ($arraySourceName+getd(arraySourceName+Count)),value);  // we set the value being held in this index 

we can now do

array_count("arrayNamehere");

return getd($arraySourceName+"Count");

and can do the rest like

pop_array()

set .tempResult = getd( ($arraySourceName+getd(arraySourceName+Count)));


setd ($arraySourceName+"Count"), ($arraySourceName+"Count") - 1; // this will decrease our setd collection count
setd ($arraySourceName+getd(arraySourceName+Count)), <null / 0 / empty string >);  // we set the value being held in this index to empty or something else that means nothing

return .tempResult;

and what else you can do with that

we can even simulate a Hashtable or Dictionary here but that will get more complicated and slow ROFL :)

Thank you very much

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  24
  • Reputation:   13
  • Joined:  12/09/11
  • Last Seen:  

Now I am a little bit enlightened. I need to practice more! :)

More reading here: Variables#Getd_.26_Setd

Thank you Mercurial!

Edited by Ghost
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...