Jump to content
  • 0
Hyroshima

for()+deletearray, confusion question!

Question

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 [email protected]_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

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

for ([email protected] = getarraysize([email protected]_magic_shop) - 1; [email protected] >= 0; [email protected])
	if([email protected]_magic_shop[.@i]) 
		deletearray [email protected]_magic_shop[[email protected]],1;

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

Link to comment
Share on other sites

  • 0
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
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
14 hours ago, Emistry said:

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

for ([email protected] = getarraysize([email protected]_magic_shop) - 1; [email protected] >= 0; [email protected])
	if([email protected]_magic_shop[.@i]) 
		deletearray [email protected]_magic_shop[[email protected]],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...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.