Jump to content




Program closes even when not all if's are done

help lua pocket

2 replies to this topic

#1 DRoleplaysBG

  • Members
  • 7 posts

Posted 15 December 2017 - 08:33 PM

So I am building an Pocket PC OS and I've ran into this problem:
I have 2 touchscreen if's (starting at line 47) and they are at the end. When I click somewhere for the first time, it's fine and if it's on the correct x and y - it runs the code that should run. However, if I do that one time the program stops (without any error) and puts up the craftos shell. I am expecting an second click to be made and then the program to shut down.
Code:
term.setBackgroundColor(colors.lime)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.white)
print("jOS Loading...")
-- BEGGINING: LOADING
local signal = 0
local version = 1
-- ENDING: LOADING
sleep(3)
function home()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.lightBlue)
  term.clear()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.white)
  term.clearLine()
  term.setTextColor(colors.black)
  print("jOS "..version)
  term.setCursorPos(18,1)
  if signal == 1 then
  term.write("Connected")
  else
  term.write("No signal")
  end
  term.setCursorPos(1,20)
  term.setBackgroundColor(colors.black)
  term.clearLine()
  term.setTextColor(colors.white)
  write("YouAd   SMS")
end
function Ads()
  term.setCursorPos(1,2)
  term.setTextColor(colors.white)
  term.setBackgroundColor(colors.yellow)
  term.clearLine()
  write("hello")
end
function SMS()
  home()
end
home ()
[b]-- Touchscreen
local event, button, xPos, yPos = os.pullEvent("mouse_click")
if (xPos > 0 and xPos < 5) and (yPos > 19 and yPos < 21) then
  home()
  Ads()
end[/b]
if (xPos > 8 and xPos < 11) then
  home()
  SMS()
end

Thanks in advance!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 December 2017 - 02:40 AM

You pull 1 event. The program will end after 1 event. I suggest adding a loop to pull and compare an infinate number of events.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 December 2017 - 09:03 AM

See the sections here regarding "while", "for", and "repeat" to see how loops (repeating blocks of code) are constructed.

Edited by Bomb Bloke, 16 December 2017 - 09:03 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users