How do I make click events work properly?

Get help using Construct 2

Post » Wed Nov 19, 2014 10:31 pm

I am having no sporadic success getting click events to activate.

For instance:
Image
This click event does not want to work, when I run it in Chrome. It will not do any of the actions listed in either event.
I have tried with my toggle being global or local. I've tried conditioning it on the opacity of my "blotter" object.

When I disable the ".. click on toggleText" event then everything works as intended, so why don't my click events work?

I am sure I am doing something simple and stupid wrong... I just can't find it yet.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Nov 19, 2014 11:06 pm

Hi gumshoe! I can't see your "for instance" but I had a similar problem that drove me nuts for a while - it just might be the same thing that's affecting you...

Double click the object that you want to be clickable.
When the "Edit image" window opens up, look down the left hand side and click on the bottom icon "Set collision polygon"
Look at your image in the editor and make sure it is fully covered.
If not, you can right-click for some automatic options or else drag and drop the little red squares.

Hope that helps.
Image
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

Post » Wed Nov 19, 2014 11:42 pm

Let me see if I can upload the image to the Scirra site rather than a random image host site.

Here is the not working copy:
1.png


I found a toggle button tutorial that worked it a different way.

This version seems to work. It is just an annoying side effect of JavaScript being completely asynchronous. It seems that both events (in the previous example) triggered simultaneously.
2.png
You do not have the required permissions to view the files attached to this post.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Thu Nov 20, 2014 4:10 am

I've run into this problem a few times, I think basically both events are run at the same tick so the switch is turned on and off instantly. A quick solution is to add a wait action of 0.01 before changing the variable.
It's also important to check the "Static" box for the local variable if you use local variables for this, otherwise the value is resetting every tick.
You do not have the required permissions to view the files attached to this post.
B
75
S
29
G
17
Posts: 256
Reputation: 15,250

Post » Thu Nov 20, 2014 5:50 am

Just put an Else between them. Even better (IMO) is to make the variable an instance variable. What happens when you have 2 clickers?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Nov 20, 2014 6:38 am

Yeah, Else seems to work. Instead of the onOffToggle = 1 use and else condition.
B
75
S
29
G
17
Posts: 256
Reputation: 15,250

Post » Tue Nov 25, 2014 6:13 pm

Ok, cool. I will keep those two observations in mind when doing toggle switches in the future. I am definitely going to implement these, because I don't need any more global variables running amok in my MMO.

I have had other click actions behave in peculiar manners since then also -- not just toggle buttons -- so there is definitely some clicky weirdness going on that I do not have a good handle on yet.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Nov 26, 2014 5:16 am

The Toggle-switch behaviour might be useful too.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 01, 2014 7:21 pm

codah wrote:The Toggle-switch behaviour might be useful too.


Is that something that already exists? Or are you suggesting? I can't find this in the Behaviors?
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Mon Dec 01, 2014 8:19 pm

gumshoe2029 wrote:
codah wrote:The Toggle-switch behaviour might be useful too.


Is that something that already exists? Or are you suggesting? I can't find this in the Behaviors?


It's 3rd party, look in the completed add-ons forum.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests