Jump to content




Defective Program


  • You cannot reply to this topic
2 replies to this topic

#1 xcrafter_40

  • Members
  • 50 posts
  • LocationIn a room with a computer, duh.

Posted 12 January 2017 - 03:18 AM

Hi,

I was recently working on a OS called CPOS, and the menu wasn't working.
Here is my code:
Source Code
Pastebin code:
pastebin get 9rfeG3em cpos
Now when I click the # to open the run menu, it does nothing
I need help quick!

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 12 January 2017 - 08:03 PM

That's not how to best use os.pullEvent

I would recommend looking for a tutorial on event pulling.

#3 Bomb Bloke

    Hobbyist Coder

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

Posted 12 January 2017 - 11:22 PM

while run do
  if os.pullEventRaw() == "terminate" then
        .
        .
        .
  elseif screen == "desktop" then
        if steel.clickedAt(1,1,1,1) then
          .
          .
          .
        end
  end
end

When this code runs, on each iteration it'll stop and wait for an event (to see if it's a terminate event - it'll ignore it if it isn't), then stop and wait for another event (to see if it's a click at a certain screen location - it'll ignore it if it isn't).

So let's say you click your #. The first event into the queue is a mouse_click event, which will be ignored because it's not a terminate event. The second event into the queue will be a mouse_up event (as the user lets go of the button), which will be ignored because it's not a mouse_click event. Then your loop repeats...

It's better to pull one event, then check it against all event types you're interested in before pulling another. Eg, something like:

while true do
  local myEvent = {os.pullEventRaw()}

  if myEvent[1] == "terminate" then
    -- do exiting stuff.

  elseif clickedAt(myEvent, 1,1,1,1) then  -- Pass the event data we've already got to the function.
    -- do mouse-clicky stuff.

  end
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users