variable reset - problem

Get help using Construct 2

Post » Sat Jun 20, 2015 12:40 am

Hi,

My goal is: when you press the left arrow key, an instance is created randomly to one of two specified positions.
I use a global variable and a local variable. The global variable defines the left arrow key has been pressed, and the local variable is used to choose one of two positions.

I added a "reset global variables" event. Despite this, it seems that the time between the change in value of the variable and reset is long enough to create multiple instances instead of one. I do not understand why.

Here you can download the if you want to take a look.

[www.norab.fr/images/reset_test.capx]

Thank you for taking the time to read my rough english.
B
7
S
1
Posts: 64
Reputation: 585

Post » Sat Jun 20, 2015 12:50 am

Don't reset globals every tick! Just set validate to 0 after decoding it.
ImageImageImage
B
71
S
21
G
221
Posts: 3,651
Reputation: 124,231

Post » Sat Jun 20, 2015 1:51 am

Thanks for your answer, but infortunately the problem is still there. If I set "validate" to 0 before instance is created, instance is just not created, and if i do it after instance creation, it still create several intance instead of only one...
B
7
S
1
Posts: 64
Reputation: 585

Post » Sat Jun 20, 2015 2:09 am

You are using key is down - do you want on key pressed? Otherwise, I don't follow what you are looking for.
ImageImageImage
B
71
S
21
G
221
Posts: 3,651
Reputation: 124,231

Post » Sat Jun 20, 2015 2:24 am

My post didn't take so here it is again, Don't "reset global variables"

Keyboard > Left Arrow is Down > System > Set Validate = 1
________________________________ > System > Wait 1.0
________________________________ > System > Set Validate = 0

or

Keyboard > Left Arrow is Released > System > Set Validate = 0
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Sat Jun 20, 2015 1:32 pm

This is it!

I fixed my problem by using "key is pressed" instead "key is down".

Thanks for your help! :)
B
7
S
1
Posts: 64
Reputation: 585


Return to How do I....?

Who is online

Users browsing this forum: Ryan Kocourek and 2 guests