local vars not set in OnClicked, are set in OnRelease

Get help using Construct 2

Post » Fri May 01, 2015 1:29 am

capx: drive (dot) google (dot) com/file/d/0BxHHLmonInAlcWpDazh4QTlGLTg/view?usp=sharing
(sorry I realize I don't have the rep to post URLs, but I can't figure out how to upload attachments! If someone wants to show me that would be great.)

I'm trying to calculate the angle between two points: when I press the mouse down and when I release it. In the layout, there are three text boxes. The first shows start and end X values, the second shows start and end Y values, and the third shows the angle between them.

It appears that endMouseX and endMouseY are being set correctly in the OnRelease event. But, startMouseX and startMouseY in the OnClick event are not being set. This is what I believe is happening, but I don't have a license so I can't debug this.

Thanks for the help!
B
4
Posts: 5
Reputation: 210

Post » Fri May 01, 2015 2:22 am

make sure the event is OnClicked and not OnMouseButtonDown
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Fri May 01, 2015 3:20 am

startMouseX/Y need to be Global variables, not locals. Locals always get reset to zero outside of their scope.
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Fri May 01, 2015 6:27 am

ah! thank you, that helps. I guess I'm thinking too much like a programmer...
B
4
Posts: 5
Reputation: 210

Post » Fri May 01, 2015 7:39 am

Programmers should know of scoping, too.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Wed May 06, 2015 9:26 am

mindfaQ wrote:Programmers should know of scoping, too.


Absolutely! Since local vars are visually declared outside of the events that use them, I was confused and didn't think their values would reset. I was simply thinking of global vars.
B
4
Posts: 5
Reputation: 210


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, maranpis and 35 guests