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.

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.
B
4
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! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

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
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

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
B
4
Posts: 4
Reputation: 358


Return to How do I....?

Who is online

Users browsing this forum: ETgirl79 and 13 guests