# [Solved] Update post title : sub-events and picked instances

Just started using Construct 2? Post your questions here

### » Tue Mar 11, 2014 11:15 pm

My questions seems trivial but couldn't find any rational explanation.

Look this :

It's a 2 player board game where tiles are clicked and the id of the tile does something (here tile = 23).
"spies" is a spyglass that shows the other player. I often use this trick, to get the other player ID by doing a "1 - currentPlayer", wich give "0" for "1" and "1" for "0".

I used this some other times in the game events (even in this one), but now I want to use it in a condition (on "slots", to retrieve the slot that correspond to the other player), the calcul doen't seem to "work", ie it did not execute the event "spies set Y".

I did some tries in the condition :

Code: Select all
`slots (where) playerID = 1 - currentPlayer => NOT OKslots (where) playerID = currentPlayer - 1 => NOT OKslots (where) playerID = int(1 - currentPlayer) => NOT OKslots (where) playerID = currentPlayer - 0 => OKslots (where) playerID = currentPlayer => OK`

Any help on this easy strange problem appreciated ^^
Thanks

PS : 100 events reached
Last edited by jhice on Wed Mar 12, 2014 1:03 pm, edited 1 time in total.
French developper based in La Rochelle/Tours
Machines I used to play or develop games : Amstrad, Atari, Amiga, PC, PS, Xbox, mobile
B
11
S
2
Posts: 69
Reputation: 819

### » Wed Mar 12, 2014 12:12 am

(number+1)%2 will turn 1 into 0 and 0 into 1 if that's what you're looking for
B
87
S
22
G
15
Posts: 1,041
Reputation: 15,353

### » Wed Mar 12, 2014 9:52 am

7Soul wrote:(number+1)%2 will turn 1 into 0 and 0 into 1 if that's what you're looking for

Thanks 7soul.

In fact the formula is ok :

1 - 0 => 1
1 - 1 => 0

And similar to yours.

The problem I face is not in the formula but in the fact that the condition is not "true" (ie the player slot is not picked).
It seems I've got a bug in my conception...

I've got to debug this and come back...
French developper based in La Rochelle/Tours
Machines I used to play or develop games : Amstrad, Atari, Amiga, PC, PS, Xbox, mobile
B
11
S
2
Posts: 69
Reputation: 819

### » Wed Mar 12, 2014 10:53 am

Ok, I have a "slots" selected in the loop before, and the code I show here is inside it.

It is like once an object has been selected in an event/condition, the same type of object can not be selected in a sub-event of the same event.

IE :

object -> Pick instance with UID 5 => ok picked
|__ object -> Pick instance with UID 6 => not picked

Need to verify this...
French developper based in La Rochelle/Tours
Machines I used to play or develop games : Amstrad, Atari, Amiga, PC, PS, Xbox, mobile
B
11
S
2
Posts: 69
Reputation: 819

### » Wed Mar 12, 2014 1:01 pm

OMG RTFM

"How events works" ... https://www.scirra.com/manual/75/how-events-work

Picking resets between events
On the other hand, sub-events (which appear indented) carry on from where its parent event left off. A sub-event will further filter the instances left over by the event that came before it.
etc.

I have read it, but now I experienced it, that's not the same
French developper based in La Rochelle/Tours
Machines I used to play or develop games : Amstrad, Atari, Amiga, PC, PS, Xbox, mobile
B
11
S
2
Posts: 69
Reputation: 819

### » Wed Mar 12, 2014 2:37 pm

To explain picking, you can look at it like a sorting machine.

Imagine you have 30 different coloured boxes.

30 - Boxes
10 - Red boxes
10 - Blue boxes
10 - Green boxes

Pick all boxes - (Will pick 30 boxes)

Pick Red boxes - (Will pick 10)
and so on.

Imagine that each of these boxes have a variable that hold a number from 1 to 3, which are random for all the boxes no matter what color they have.

If you have an event like this.

Pick all boxes who have a value of 1 (Lets assume that it pick 8 boxes)
--- (Sub event) Boxes need to be red (This will pick all red boxes of those 8, so it might pick 2 boxes.)
--- (Sub event) Pick all Boxes (Will pick all 30 boxes because it is a system command)
B
45
S
12
G
3
Posts: 1,210
Reputation: 7,549

### » Wed Mar 12, 2014 3:29 pm

Thanks @nimos100

I got it know but yes, examples are welcomed to get it better ^^
And ok for the the "Pick all" command exception, to keep in mind.

It's a pleasure to use C2... I hope to deliver my game "soon", and cherry on the cake would be a multiplayer local or network game, but I'll post more about the game when it will be more advanced.

Now let's find a moment to go and buy a license €€
French developper based in La Rochelle/Tours
Machines I used to play or develop games : Amstrad, Atari, Amiga, PC, PS, Xbox, mobile
B
11
S
2
Posts: 69
Reputation: 819