Jump to content
  • 0

for()+deletearray, confusion question!


Question

Posted

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!

4 answers to this question

Recommended Posts

  • 0
Posted

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

  • 0
Posted
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
  • 0
Posted
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!!

  • 0
Posted
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 ^^

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