How do I "Choose between global variables"

Get help using Construct 2

Post » Sun Mar 22, 2015 4:57 pm

Hello friends I have the following question
As I can implement a " Choose " expression among variables whose value is greater than or equal to 1 ?

For example:
My variables are P1_Score (value 3) , P2_Score ( value 0 ) , P3_Score (value 1) , P4_Score ( value 0 ) , P5_Score (value 1)
As I can get this?
Choose ( P1_Score , P3_Score , P5_Score )

Greetings from Chile
B
42
S
11
G
2
Posts: 111
Reputation: 3,823

Post » Mon Mar 23, 2015 8:38 pm

Choose picks an item random from the list.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Mar 23, 2015 9:18 pm

How?
B
42
S
11
G
2
Posts: 111
Reputation: 3,823

Post » Mon Mar 23, 2015 9:21 pm

just random.

set var choose(0,1,2,3,4,5)

And that will set one of the values at random.

I also use it with every X seconds.

Every choose(1,2,3)

And at random it will trigger at 1,2 or 3.

Sometimes, when I want a greater chance of 1 number occurring, I do choose(1,2,2,3)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Mar 24, 2015 10:03 am

I understand , but I need to choose eg from the Sprites as having greater or equal to 1 variable.
B
42
S
11
G
2
Posts: 111
Reputation: 3,823

Post » Tue Mar 24, 2015 10:45 am

It isn't very clear what exactly you want, but if you have sprites associated with instance variables, I would use the picking system. First, you use pick by comparison to select all the sprites that have an instance variable greater than 1, then use Pick Random Instance to randomly select one.

If you don't have instance variables, you need to iterate over the variables and put the valid ones into an Array, then generate a random Integer between 0 and the length of the Array, then pick that variable.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Mar 24, 2015 11:29 am

isasaurio, what bladedpenguin describes is probably what you are looking for.

Event
Pick all object
pick object by evaluate where object.var > 0
action
do something with the objects
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Jackriduk and 15 guests