local vars not set in OnClicked, are set in OnRelease

  • 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!

  • make sure the event is OnClicked and not OnMouseButtonDown

  • startMouseX/Y need to be Global variables, not locals. Locals always get reset to zero outside of their scope.

  • ah! thank you, that helps. I guess I'm thinking too much like a programmer...

  • Programmers should know of scoping, too.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)