Random Choosing w/ Multiple Different Values

Get help using Construct 2

Post » Sun Jan 31, 2016 10:47 pm

I'm working on a remix of Pacman.
So far, I've got the control system for Pacman working fine.
I'm using JunctionCheck objects to determine which direction Pacman can go next. Each instance of JunctionCheck has a variable for each direction which states if that direction (north, south, east, west) is true/available or false/not available. (I probably could have set it up in an array, too....ah, but that that's 20/20.

But now I need to set up a system for the Ghosts which will be very much like the controls for Pacman, but which will be operated automatically instead of by the player/manually using the same JunctionCheck objects.

My dilemma is that there will be a mixture of 1-4 directions to choose from and, obviously, each combination will be different. It will be easy enough to manually enter which directions are available for the A.I. ghosts to choose from (that's already set), but the number of directions to choose from will be tedious to enter in without creating too any event lines.

What I'm after is something like this:

Code: Select all
Ghost On Overlap w/ JunctionCheck | Set GhostDirection to choose(Direction 1, Direction 2, ...)

BUT, the code will only list those directions which are true/available. If a path doesn't have and optional east path, then that won't be part of the list of options to choose from.

Any suggestions on how I can do this concisely? Thanks for your help!
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
139
S
22
G
8
Posts: 777
Reputation: 14,830

Post » Sun Jan 31, 2016 10:53 pm

Clear an array, check each of the four Junction conditions and Push the direction into the array, only if valid. You'll end up with an array with only valid directions. Now just pick a valid random index in the array, and you've got your direction.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Sun Jan 31, 2016 11:06 pm

@blackhornet - As always, the obvious eludes me. LOL Thank you, sir. I should be able to do that easily.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
139
S
22
G
8
Posts: 777
Reputation: 14,830


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 63 guests