Trouble with conditions for appearing the object


I have two characters in my scene. One of them is the bottom of the scene and another should appear at the middle or top of the scene.

I set a condition for this object to appear ( The bat object), but I don’t know why it doesn’t appear!

Can you please help me?

You need to upload a readable screenshot, it is basically impossible to see anything in this one. From what I can barely make it out it looks like you’re testing if random Variable of bat move equals a random number (1 - 3), and if the random_num is 2, you create the bat move object. There’s multiple things going wrong here from what I can tell. It looks like you meant to assign random_num with a random variable, this needs to be done in an event, not a condition. Right now it’s just testing if the initial value of random_num (probably 0) is equal to the random number that is chosen. And if that’s the case only if the initial number was always 2, the object is created. Another minor problem is you can’t hide and show an object that has not been created yet.

Sorry, I changed the image.

Thank you, did you make those fixes I mentioned? Or did I misunderstand what you were trying to do?

I want after some seconds passed from the beginning of the scene randomly a bat appeared and randomly other bats be appear.

5 seconds after scene starts set spawn to true

if spawn is true
     repeat every 1 second 5 times
            create object bat at randomInRange(0, 700) randomInRange(0, 1200) 

You could do it with a timer that uses a variable set to a random # for the duration.

At the beginning — set a variable to a random number in range, start a timer

If the elapsed time of timer is > the variable then add a bat, set the variable to a random number in your range and restart the timer

Somehow I did it.
My actual problem is I want just 5 bat objects to exit on the scene, how can I achieve this issue?
Should I destroy other bat objects?

If number of bats living on scene < 5 then add/create a bat.

1 Like

What’s wrong with the solution I gave you? It also is much much much lighter on performance then your algorithm. The solution I gave you only iterates 5 times, your algorithm changes the scene variable every tick which is super performance heavy, yes it might result in what you want, but if you plan to publish this game you want to make sure it is at least some what optimized.

Yes, you are right.
Because I am new to this engine and you didn’t write the code, I didn’t understand what you meant at that time.

My question is:
Where and when does timer “t” start working?

This is a custom extension that you install from the search page called repeatEveryXSeconds, it is different from the regular timer in that it starts itself and ends once it has iterated for the given amount of times. It is very useful I use it in almost every project, I much prefer it to using regular timers which can be a little tricky to get the hang of.

I did what you say, but why mine is not working?

What object should this plugin be added to?

I believe you need to remove the at the beginning otherwise it can’t trigger the actions.

The extension can use either scene timers or object timers if it’s added to an object as a behavior. Neither method seems any better than the other. Either way they need a condition that can be checked on each frame to be able to trigger any events or subevents.

Extensions aren’t necessarily more efficient than events you use in the main section. Sometimes it’s just the same events moved into an extension. It’s a convenience but just like the main events, extensions need to be efficient.

That’s correct. Now it works.

1 Like