Jump to content
  • 0

for()+deletearray, confusion question!


Hyroshima

Question


  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  159
  • Reputation:   58
  • Joined:  07/11/14
  • Last Seen:  

Hello guys, I'm having a problem which is making me confused. The situation is the deletion of null values of an array, however a null value remains...

dispbottom "Array Value Before: "+getarraysize(.@tmp_magic_shop)+"";
	for(set .@i,0; .@i<getarraysize(.@tmp_magic_shop); set .@i,.@i+1)
	{ dispbottom ""+.@tmp_magic_shop[.@i]+""; }

RTQAvlS.jpg

 

Remove null values.

for(set .@i,0; .@i<getarraysize(.@tmp_magic_shop); set .@i,.@i+1)
	{ if(!.@tmp_magic_shop[.@i]) deletearray .@tmp_magic_shop[.@i],1; }

 

dispbottom "Array Value After: "+getarraysize(.@tmp_magic_shop)+"";
	for(set .@i,0; .@i<getarraysize(.@tmp_magic_shop); set .@i,.@i+1)
	{ dispbottom ""+.@tmp_magic_shop[.@i]+""; }

 

9mZRYjS.jpg

 

OBS:

deletearray .@tmp_magic_shop[0],1;  <- remove that value 0

the confusion is why this value It's not removed like the others.

 

Thank you since now!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

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

there exists another way for you, in case you afraid to mess up with the index value. 

for (.@i = getarraysize(.@tmp_magic_shop) - 1; .@i >= 0; .@i--)
	if(!.@tmp_magic_shop[.@i]) 
		deletearray .@tmp_magic_shop[.@i],1;

start looping from the end of the array to the front...

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  924
  • Reputation:   167
  • Joined:  04/05/13
  • Last Seen:  

prontera,152,184,5	script	formNPCTemplate	54,{
	.@tmp_magic_shop[0] = 0;
	.@tmp_magic_shop[1] = 1;
	.@tmp_magic_shop[2] = 1;
	.@tmp_magic_shop[3] = 1;
	dispbottom "Array Value Before: " + getarraysize(.@tmp_magic_shop) + "";
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	dispbottom "" + .@tmp_magic_shop[.@i] + "";
	L_DoItAgain:
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	{ 
		if(!.@tmp_magic_shop[.@i]){
			deletearray .@tmp_magic_shop[.@i],1;
			goto L_DoItAgain;
		}
	}
	dispbottom "Array Value After: " + getarraysize(.@tmp_magic_shop) + "";
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	dispbottom "" + .@tmp_magic_shop[.@i] + "";
	end;
}

 

1234.JPG

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  159
  • Reputation:   58
  • Joined:  07/11/14
  • Last Seen:  

54 minutes ago, TARTs said:

prontera,152,184,5	script	formNPCTemplate	54,{
	.@tmp_magic_shop[0] = 0;
	.@tmp_magic_shop[1] = 1;
	.@tmp_magic_shop[2] = 1;
	.@tmp_magic_shop[3] = 1;
	dispbottom "Array Value Before: " + getarraysize(.@tmp_magic_shop) + "";
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	dispbottom "" + .@tmp_magic_shop[.@i] + "";
	L_DoItAgain:
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	{ 
		if(!.@tmp_magic_shop[.@i]){
			deletearray .@tmp_magic_shop[.@i],1;
			goto L_DoItAgain;
		}
	}
	dispbottom "Array Value After: " + getarraysize(.@tmp_magic_shop) + "";
	for(.@i = 0; .@i < getarraysize(.@tmp_magic_shop); .@i++)
	dispbottom "" + .@tmp_magic_shop[.@i] + "";
	end;
}

 

1234.JPG

OMG, I forgot that deletearray moves the index.

 

Thank you very much!!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  159
  • Reputation:   58
  • Joined:  07/11/14
  • Last Seen:  

14 hours ago, Emistry said:

there exists another way for you, in case you afraid to mess up with the index value. 


for (.@i = getarraysize(.@tmp_magic_shop) - 1; .@i >= 0; .@i--)
	if(!.@tmp_magic_shop[.@i]) 
		deletearray .@tmp_magic_shop[.@i],1;

start looping from the end of the array to the front...

OMG, I even thought of doing so, but I was tired and did not reasoned more kkkkk

Thank you ^^

I'm creating an interesting store, i do not know if it already exists, because I've never seen something similar.

I have not been developing anything for a while, sometimes i get stuck in a small complex problem but looking at script_command.txt I'll reminding.

Thanks again ^^

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...