Double for-loop problem

  • 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: dropbox.com/s/kesery3omcea9gv/4In4.capx

    Thank a lot for all friends and experts

  • Your example shows just 7 images and an global text variable, no loops.

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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..

    Do it like this instead:

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

    for tokencount(list,",")

    pick sprite.index = tokenat(list,loopindex,",")

    .. sprite.destroy

  • Dear vee41

    How do I pick sprite.index..??

    I just only know pick top/bottom or pick by unique ID only...

    Thank to much...

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

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

    No...it doesn't work..

    Like that..??<img src="http://dautruong.vn/avatar/3Key%20Err.png" border="0" />

    my capx here:

    dropbox.com/s/kesery3omcea9gv/4In4.capx

    Everyone help me please..!!

  • Here is an example: 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.

  • You right...I got mistake with comparison with types of object...:)

    Very thank for your correction.

    Best regards..:)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)