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

DeBrates

Members
  • Content Count

    5
  • Joined

  • Last visited

Reputation Activity

  1. Upvote
    DeBrates reacted to Fingercomp in Double Click Issue/Touch Signal Sent Twice?   
    The bug is really simple. To find it, follow through the code line-by-line, analyzing what happens at each line. (This is something I do quite often when debugging an obscure problem.)
    First, skip the first few dozens of lines until we get to the L65 (short for line 65), where the loop is defined. We then encounter the if block at L68, of which the first branch is actually run (page == "page1" as it was set to this value on L63), resulting in the pageOne call.
    The next line to examine is L79, where the program stops until it pulls the touch event. Here, I check that the event parameters weren't mixed up. All right, let's go on and press the button.
    The first condition, on L82, is satisfied (page == "page1", set on L63), so we get the page variable updated to the new value, "page2". But there's more code to run before we loop back! The second condition, on L89. The coodinate mess after the first and evaluates to true. What about page? Well, we've just set it to "page2", so... it, too, yields true. Therefore, the whole condition is satisfied. And the variable is set back to "page1". We loop back, and redraw the first page.
    This is how we've just spotted the bug. In case you wonder why Event 2 isn't written to the screen: well, it is written. At position (4, 45). You've just mistaken x for y (and vice versa): 4 is the column, 45 is the row. This is clearly beyond the viewport 58×18, so you see nothing actually printed.
    OK. How should you fix it? It's simple: use elseifs.
    if (x >= w / 2 - 5 and x <= w / 2 - 5 + 11 and y >= h / 2 - 1 and y <= h / 2 + 1) then if page == "page1" then mon.set(4, 10, "Event 1") table.insert(a, "X") page = "page2" elseif page == "page2" then mon.set(45, 10, "Event 2") page = "page1" end end
  2. Like
    DeBrates reacted to Molinko in event.pull freezing loop workaround   
    event.pull has an optional first argument, a timeout. 
    local name, _, x, y = event.pull(0.1, "touch") if name then -- # name will be nil if event.pull(0.1, ...) times out after 0.1 sec if y == 1 and x < 30 and x > 18 and reactorOnline then r.setActive(false) elseif y == 1 and x < 30 and x > 21 then r.setActive(true) elseif y == 8 and x == 21 or x == 22 then r.setAllControlRodLevels(rodLevel - 10) elseif y == 8 and x == 28 or x == 29 then r.setAllControlRodLevels(rodLevel + 10) end end  
×
×
  • Create New...

Important Information

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