Whack a mole, How?

Hello.
I’m trying to create Whack a mole game.
I’ve been looking through past material and found that it uses the pick a random object event.
I have 2 more functions that I would like to add to this event.

  1. how can I make the moles come out not only one at a time, but also two at a time?
  2. I would also like to have objects other than moles that are penalized for touching come out of different holes at random. In this case, should I group them with the moles and use the randominRange(“object name(1,2,)”) event, or is there a better way?


my proposal is to create a variable named used to check if a hole is empty or not.
hole.used = FALSE → hole empty
hole.used = TRUE → hole popolated

Then, each n seconds, to show the mole:
Repeat n times:
CONDITIONS:

  • pick random hole
  • hole.used = FALSE
    ACTION
  • create object MOLE positin hole.x and hole.y
  • hole.used = TRUE

When the mole hide:
hole.used = FALSE (you can find the correct hole checking the mole position)
DESTROY mole

Thanks,
J

a different approach. all the locations are the “mole” sprite, but animation 0 is “blank”, 1 is “mole” and above that are “non moles”. This code randomly choses where moles appear and randomizes how long they will be there from .5 to 2.5 seconds. At any given time only locations will be active with either a mole or a nonmole.

1 Like

I think these 2 should be reversed
So it 1st checks if animation is 0
And then among ones with animation 0 it picks random one
Cause now it picks random one and kick in action only if animation is 0
So if it picked one and turned out its animation is NOT 0
Then nothing happen
At least that is what i understand from it

1 Like

if it picks a random one and it is not 0, then yeah, it won’t do anything. but all the conditions will still be true one frame later for it to pick another one. since we are randomizing when stuff shows up, even if it takes 20 frames (unlikely) for it to find a 0 mole, then it’ll just delay showing up a little bit, but not affect any of the logic.

I ran the code before i shared it, and it did exactly what I hoped it would… it randomly changes sprites to mole and not mole, then changes them back, but you never have more than 2 in play at a time.

hang on. are you saying that if i reversed those two conditions within the same event that it would yield different results? is that true?

OMG. i just tested and you are absolutely right. How have i done 4 years in gdevelop without realizing this?

In gdevelop all crap is reed from top to bottom
So 1st you pick ALL objects with animation 0
THEN you pick one random object among them

If you refers it (as you had it originally) then it picks ANY random object
And checks if its animation is 0
And if its not then action DO NOT kick in cause condition was not satisfied

You did not have event for that so nothing happen
You would need to prepare another event for scenario where if picked object animation is not 0 to roll random pick again
Which would be stupid cause it could on bad luck pick object with animation of not 0 constantly

So reversing order would bypass it never letting it pick anything that it should not pick

And no shame in that i for 1 year struggled with text object flickering when number of characters displayed changed
Resulting in text moving slightly to the right then correcting itself to the left
OVER ONE YEAR

Turned out 1st you change text in action and anywhere BELOW it you change position of that text object
And not (like i was doing for over a year) 1st change text position then change text itself

You can spot it here
1st gif in my post had change text object position above change text and it flickers
Where 2nd gif have 1st change text then below it action to change text position and it does not flicker

1 Like

I’m sorry, but I have a question.

What is the definition of the deathtime variable for mole, does it mean the time between 0.5 and 2.5 seconds for mole to come out?

yes, by randomizing between 50 and 250, then dividing by 100, you can get any 10th of a second between .5 and 2.5.

1 Like