pick random object

For questions about using Classic.

Post » Tue Feb 17, 2009 5:59 am

hi,

I've searched in the forum (and found a similar topic, about creating private variables (in the pick random object-topic), but got lost while reading the topic) and wiki, but couldn't find the answer to:

does the event "pick random object" work with a tetris clone, so that Construct chooses from a set of (edit: already existing) pieces, randomly?
If so, that is what I'm searching for.

(Perhaps the real question:)
But when selecting "pick random object", I only get to choose 1 object. So how can it select randomly, from only 1 object? I would like to have a random choise between multiple pieces.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Tue Feb 17, 2009 7:12 am

i believe 'pick random object' is used more for existing objects, not for picking objects to spawn from a group of non-existing objects.

what you could do to pick a random piece --

condition for spawning new piece
-set private variable to Random(7) (replace 7 with however many possible pieces there are)

if private variable = 1
trigger once while true
-spawn piece 1

if private variable = 2
trigger once while true
-spawn piece 2

and so on

[quote:2iz066v7](Perhaps the real question:)
But when selecting "pick random object", I only get to choose 1 object. So how can it select randomly, from only 1 object? I would like to have a random choise between multiple pieces.[/quote:2iz066v7]
well, for future reference for other applications, you would add all the pieces to a family and then pick random object from that family. but again, pick random object wouldn't really work for this situation, i don't think.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Tue Feb 17, 2009 7:55 am

Thanks, I will try to get it work.

I have about 5 sprite-tetris-blocks which I will try to show randomly with your information.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Tue Feb 17, 2009 8:52 am

oh, and i'm not sure why i said private variable. it would probably be smarter to use a global variable.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Tue Feb 17, 2009 10:31 am

They just added this condition to families, why don't you try that?
Just add all the different objects to the same family.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Tue Feb 17, 2009 6:58 pm

[quote="newt":35p7rhcy]They just added this condition to families, why don't you try that?
Just add all the different objects to the same family.[/quote:35p7rhcy]

Thanks for the tip, I'm using the family object, which contains the objects I want to choose from.
Family is useful.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests