picking problem - instances of an object inside a family

Get help using Construct 2

Post » Fri May 20, 2016 5:58 pm

@lennaert in your example there is no waiting - for the waiting part the enemy must stop moving for 1.5 seconds.
The waiting part is quite important to me

@Tuiii your example does it, but instead of instances it uses clones. Can it also work with instances inside a family?
I am looking for a way to be able to do both. Instances and other members of family should have individual behavior.

Creating another instance of one of the objects results in breakage again.

So both still dont solve the issue. :|

@Ashley Have we uncovered a limitation to construct's family system?
B
40
S
15
G
4
Posts: 426
Reputation: 5,848

Post » Fri May 20, 2016 6:19 pm

Just set your state to something else, "x", before the Wait so that the "wait" code doesn't repeat.

http://www.blackhornettechnologies.com/ ... w_bht.capx

(It better to use a Timer here, rather than Wait.)
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Fri May 20, 2016 6:35 pm

Sorry, totally missed you wanted them to wait, here's another example
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri May 20, 2016 7:11 pm

@blackhornet This actually solves it - without using 'for each'... but it leaves me confused.

looking at it - it seems illogical to me. It goes against what I've learned in programming.
Shouldnt setting state to "x" stop all the events bellow that from executing?
Also I used trigger once before - why didnt that work and this does?

In what order exactly is the event sheet in C2 executing things?
@Ashley please explain

@lennaert thank you. In your case the solution was to make a manual timer with a new variable :)
But it still has an issue - it turns too early. It should turn when it starts walking in the other direction, not when it stops.

They are both elegant solutions. I will look further into using them. In this case I want to learn from them both
B
40
S
15
G
4
Posts: 426
Reputation: 5,848

Post » Fri May 20, 2016 7:38 pm

The problem is if you leave the state in "wait", event 4 runs constantly. You want this event to stop running while the Wait runs, and then the events after the Wait proceed, setting the state back to "walk".

That's why a Timer makes this simpler, in my opinion. the code is easier to follow.

Here's two simplifications.
http://www.blackhornettechnologies.com/ ... r_bht.capx
http://www.blackhornettechnologies.com/ ... 2_bht.capx
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Fri May 20, 2016 7:44 pm

In what order exactly is the event sheet in C2 executing things?

https://www.scirra.com/manual/75/how-events-work
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Fri May 20, 2016 8:53 pm

@blackhornet what confuses me is that C2 breaks one rule that programming languages follow:

1.if myVar=true:
2. dothis()
3. myVar=false
4. doThat()

in traditional programming doThat() will never execute, becase myVar was set to false on line 3 and doThat is after that.
But in construct2 everything seems to execute to the end. DoThat will do it's thing.

Thank you for the examples. I very much appreciate them!
Last edited by blurymind on Fri May 20, 2016 8:58 pm, edited 1 time in total.
B
40
S
15
G
4
Posts: 426
Reputation: 5,848

Post » Fri May 20, 2016 8:56 pm

That's not true. Provide a real example. Half the time people do this, they change myVar in doThis, and then when event 3 is hit, the condition is now true so the code executes. They should use ELSE, instead of testing the opposite condition.
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Sat May 21, 2016 4:36 pm

blurymind wrote:@blackhornet what confuses me is that C2 breaks one rule that programming languages follow:

1.if myVar=true:
2. dothis()
3. myVar=false
4. doThat()

in traditional programming doThat() will never execute, becase myVar was set to false on line 3 and doThat is after that.
But in construct2 everything seems to execute to the end. DoThat will do it's thing.

Thank you for the examples. I very much appreciate them!


There is only a 'if myVar = true .. doThis()' event possible when there are no objects involved in that event.
Wich is rarely and totaly not the scope of c2.

Read this : https://www.scirra.com/manual/75/how-events-work

Understand that an event is much more then, and very rarely a pure 'if this/then that' situation.

If the condition is true ... it runs its actions.
If the condition picked objects AND if the conditon is true ... It runs its actions on the picked objects. (zero picked objects = no action that actual does something)
If the conditon is true ... AND the action is adressed to a unreferenced object, all instances of that object are adressed.
Sub picking conditon always start with the in the top level event previous picked objects.
Previous picked objects will be forgotten in each top level event.

Refering to programming languages is pointless. Got to forget and read the manual.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat May 21, 2016 6:35 pm

blurymind wrote:lennaert thank you. In your case the solution was to make a manual timer with a new variable :)
But it still has an issue - it turns too early. It should turn when it starts walking in the other direction, not when it stops.


Your welcome blurymind :)

The turning should be easily to manipulate, it just a matter of re-positioning sub-event 8 & 9 and adding a extra check on the timeout-wait check to prevent continues flipping.
something like this

Also, I left the for each above it, while it is not needed in most cases, it clarifies a lot (readability) when you look at it from a programmers perspective. (especially one relatively new to construct 2)

Plus, you can move several events below it as sub-events and use the plus sign to open and close a range of events belonging to that loop. Ofc you could use a group too but ,meh, this was easy and for hand :)

In the end it will generally not matter if you added it or not, as the construct 2 engine will generally create the same javascript result out of the event sheet in this case. :)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Klarner and 30 guests