Stop Loop when conditions are met

Get help using Construct 2

Post » Tue Jun 26, 2012 4:35 am

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.

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.

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 = avbleft -> stop loop, get IID, play by IID, close group
    if = 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.
Posts: 4
Reputation: 358

Post » Tue Jun 26, 2012 4:45 am

Not quite sure where DomTop is set, can you explain a little bit more about the gameplay for me?
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
Posts: 2,158
Reputation: 18,481

Post » Tue Jun 26, 2012 11:02 am

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.
Scirra Founder
Posts: 23,871
Reputation: 188,207

Post » Tue Jun 26, 2012 12:19 pm

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)
bajanguy2012-06-28 16:56:23
Posts: 4
Reputation: 358

Return to How do I....?

Who is online

Users browsing this forum: Goomba, Turaco, Zaksoid and 12 guests