Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
XFactHD

Touch screen program

Question

I have two questions on touch screen events:

1: Is it possible to make two parallel loops to not slow down the updating of the screen by pulling an event?

2: I have a program with some rather small buttons. At first I tried to use fixed coordinates in an if statement and then I used a range for the coordinates in the if statement but it still doesn't work for me. Here is the relevant code: http://pastebin.com/KJmUsgD7

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Instead of a loop with event.pull, try registering a listener function for touch events using event.listen. The listener function is called every time a touch event happens, so you don't need to worry about running a loop yourself.

 

The reason why your range checks aren't working is because they are never even run - the outer condition not x == nil and y == nil is always false. (not has a higher operator precedence than and, meaning that the condition is parsed as (not x == nil) and y == nil. What you probably want is x ~= nil and y ~= nil. (The check shouldn't be necessary at all, I don't think that x and y could ever be nil, since all touch events have coordinates.)

 

By the way, if you only have a short piece of code, like a small function, there's nothing wrong with putting it into a code block in your post. Long programs should of course go on Pastebin.

Link to post
Share on other sites
  • 0

I don't know how to make code blocks on the mobile.

As for your suggestion: The check for not nil is just because the program crashes if you add a timeout to event.pull and the if statement then that checks for the coordinates tries to use nil as a number.

I have briefly looked into event listeners and I am not really sure how to use them.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.