Stop Loop when conditions are met

0 favourites
  • 4 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • I've created a domino game using c2 and I am 80% completed.

    What's got me stuck is trying to do some basic AI playing.

    Design:

    For a domino(sprite) i have 3 instance variables (boolean:isplayed, boolean:iscouple, number:playernum)

    I have a group that runs a random array that 'shuffles' each domino an assigns to the 4 players. It also sets the playnum(player 1-4) and sets the iscouple(couples).

    I have a global variable 'izturn' that I use to compare against playernum to validate which player can play.

    I also have 2 global variables that i set what domino can play left or right (avbleft,avbright).

    On each play i have groups that determine the location to play each domino, at which end of the board and angle.

    My gameplay works perfectly if I play as each player manually, all the locations and angles for set perfectly. So now i'd like to automate cpu playing.

    Logic:

    After the user plays run automate group (with 3 sub groups)

    1st sub group 'play couples':

    loop through all dominoes,

    domino not isplayed,

    domino iscouple

    playnum(domino) = playerturn

       if these match, then sub-event checks if domino can play left or right:

        if dom.top = avbleft -> stop loop, get IID, play by IID, close group

        if dom.top = avbright -> stop loop, get IID, play by IID, close group

    My problem is that the loop doesn't seem to stop. Why?

    Other 2 sub groups are disabled for now as the also run loops and cause the same problems.

    I've put in a MyTest variable to see how many iterations of the loop runs and i'm getting different figures from a few hundred to a few thousand.

    I consider myself to be an intermediate programmer who has done quite a few loop scripts in vb and javscript and C2 has me stuck for days trying to figure this out. <img src="http://chezral.6te.net/group.jpg" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not quite sure where DomTop is set, can you explain a little bit more about the gameplay for me?

  • As far as I can see, DomTop is not set anywhere inside the loop. This means every time the loop will always either stop immediately, or run all the way to the end of the loop, because the conditions never change while the loop is running.

  • Sorry, I forgot to mention those instance variables.

    DomTop is assigned the top value of the domino during shuffling. Likewise for DomBot the bottom value, with these I can detect what is the domino value when clicked or picked.

    Is my logic correct? I would assume that on each loop (28 dominoes) it would try to match the top or bottom and stop on that iteration, if not go on to the next iteration.

    It seems that it is looping past the (for each domino) 28 instances, since when I run it i'm seeing mytext value >400

    here is file: (link removed)

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