How do I randomly pick objects that aren't on screen?

Get help using Construct 3!

Post » Thu Aug 24, 2017 7:39 pm

Image

Goal: I'd like for those colored blocks to appear randomly, one at a time, on screen based on a global variable's value. Each one has a set x and y; so the position doesn't have to be random, just which one shows up.

So for example:
variable = 5 | one block shows up
variable = 10 | another shows up
etc.

I imagine I have to use some check that looks to see "if on screen..." but other than that, I haven't figured it out correctly without having them all show up or none of them showing up. I'm going with "if on screen..." because the blocks can be destroyed and I would like for them to appear again.
B
46
S
13
G
3
Posts: 279
Reputation: 4,631

Post » Thu Aug 24, 2017 8:02 pm

'Off screen' is not really a player in the flow. It is just a 'place' where you place those that are 'not in play'.

I suppose you use instances, else use a family.

Give them a instance Boolean 'InPlay'.

When the global variable demands to bring one in play ....
___ Object > Is Boolean instance set 'InPlay' <--- INVERTED (so it reads as 'InPlay' = false)
___ System > Pick random instance (Object)
__________action > Object > Set Boolean 'InPlay' to true
__________Actions to place it somewhere on screen.

When an object is destroyed.
_________action > Object > Set Boolean 'InPlay' to false
_________action > Object > set X to -9999

Do not actual destroy it, just move it off screen.

If you want to use ''Off screen' as kind of 'the Boolean' ...

When the global variable demands to bring one in play ....
___ Object > Is On screen <--- INVERTED
___ System > Pick random instance (Object)
__________Actions to place it somewhere on screen.

When an object is destroyed.
_________action > Object > set X to -9999
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

Post » Thu Aug 24, 2017 8:35 pm

@99Instances2Go

Thanks! Super helpful.

One issue I'm running in to is that there is no check if an object is already in a position so it's stacking instances. Any ideas on how to go about that?
B
46
S
13
G
3
Posts: 279
Reputation: 4,631


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests