Double for-loop problem

Get help using Construct 2

Post » Fri Mar 15, 2013 2:43 pm

Dear all.

This problem never come to me with r95. But after upgrade to R114, it comes to me...:(

CC2 seem not to works in double for-loop..:(

How do I solve it

My sample here: https://www.dropbox.com/s/kesery3omcea9gv/4In4.capx

Thank a lot for all friends and expertshoanganh172013-03-15 14:45:38
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Fri Mar 15, 2013 3:48 pm

Your example shows just 7 images and an global text variable, no loops.
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Sat Mar 16, 2013 11:01 am

My code can be explained like that

Global list = "1,2,4,6";
for(count= 0 to tokencount(list,","),count++){
   foreach(sprite in game){
      if(sprite.index==tokenat(list,loopindex,",")){
        sprite.destroy();
      }
   }
}

My expectation is at least some of sprites must be destroyed. Actually nothing.
Could some one let me know why.
Thank to much in advance..
hoanganh172013-03-16 11:02:39
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Sat Mar 16, 2013 12:21 pm

[QUOTE=hoanganh17] My code can be explained like that

Global list = "1,2,4,6";
for(count= 0 to tokencount(list,","),count++){
   foreach(sprite in game){
      if(sprite.index==tokenat(list,loopindex,",")){
        sprite.destroy();
      }
   }
}

My expectation is at least some of sprites must be destroyed. Actually nothing.
Could some one let me know why.
Thank to much in advance..
[/QUOTE]

Do it like this instead:

Global list = "1,2,4,6";

for tokencount(list,",")
pick sprite.index = tokenat(list,loopindex,",")
.. sprite.destroy
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Mar 16, 2013 3:56 pm

Dear @vee41
How do I pick sprite.index..??
I just only know pick top/bottom or pick by unique ID only...

Thank to much...hoanganh172013-03-16 15:59:59
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Sat Mar 16, 2013 4:07 pm

Assuming sprite.index is an instance variable you defined yourself, you can do sprite.index=tokenat(..). Its compare instance variable in sprite conditions. If you use uids in your global list, you can do pick by unique id.
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Mar 16, 2013 4:18 pm

[QUOTE=vee41] Assuming sprite.index is an instance variable you defined yourself, you can do sprite.index=tokenat(..). Its compare instance variable in sprite conditions. If you use uids in your global list, you can do pick by unique id.[/QUOTE]

No...it doesn't work..

Like that..??

my capx here:

https://www.dropbox.com/s/kesery3omcea9gv/4In4.capx

Everyone help me please..!!
hoanganh172013-03-16 16:27:00
B
11
S
2
Posts: 73
Reputation: 1,438

Post » Sat Mar 16, 2013 4:36 pm

Here is an example: http://dl.dropbox.com/u/19921470/pick_by_index.capx

EDIT: In your project you are comparing string (the list) to int (index), that is why it fails.vee412013-03-16 16:38:19
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Mar 16, 2013 10:06 pm

@vee41..
You right...I got mistake with comparison with types of object...:)
Very thank for your correction.

Best regards..:)
B
11
S
2
Posts: 73
Reputation: 1,438


Return to How do I....?

Who is online

Users browsing this forum: h1k3, Unconnected and 0 guests