How to pick random in python?

For questions about using Classic.

Post » Sun Jun 05, 2011 10:30 pm

I'm trying a simple code to test if I can pick a random obj with python but it always get the same one..

made 5 sprites and added them to Items family

made a script like
Layout start:
Items.PickRandom()
Items.SetAngle(30)

but always get the same object..
How do I get a random obj?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Sun Jun 05, 2011 11:16 pm

Do something like this:
[code:2q52df0n]import random
random.choice(Sprite).angle+=1[/code:2q52df0n]

When using python you can't pick objects like with conditions. You'll have to use traditional programming to do it. You can however access what objects are selected by events with SOL.Sprite.
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Sun Jun 05, 2011 11:58 pm

Thanks dude ;)
B
30
S
6
G
5
Posts: 433
Reputation: 6,061


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests