Jump to content




os.pullEvent = os.pullEventRaw failing

lua

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

#1 Micheal Pearce

  • Members
  • 87 posts
  • LocationUSA

Posted 17 April 2013 - 04:19 PM

os i tried making this program unhackable or whatever and added os.pullEvent thing and tested the ctrl+T and sometimes it returns 75 sometimes it returns 74 sometimes it returns some java fuck up or something ive never seen sometimes it returns nothing and just nuls the program and other times it freezes the computer heres the code its fine if noone can help it would be nice to have it unhackable

function Coms()
KID = fs.exists(Gname)
if KID == true then
file = fs.open(Gname,"r")
Cstatus = file.readLine()
file.close()
term.setCursorPos(Px,Py)
term.setBackgroundColor(colors.lightGray)
write("+"..Cname)
if Cstatus == "ON" then
  term.setBackgroundColor(colors.lime)
elseif Cstatus == "OFF" then
  term.setBackgroundColor(colors.red)
end
write(" ")
Py = Py + 2
else
term.setCursorPos(Px,Py)
term.setBackgroundColor(colors.lightGray)
write("+"..Cname)
term.setBackgroundColor(colors.orange)
write(" ")
Py = Py + 2
end
end
function PutComsLeft()
Px = 1
Py = 3
Cname = "Computer 1"
Gname = "C1"
Coms()
Cname = "Computer 2"
Gname = "C2"
Coms()
Cname = "Computer 3"
Gname = "C3"
Coms()
Cname = "Computer 4"
Gname = "C4"
Coms()
Cname = "Computer 5"
Gname = "C5"
Coms()
Cname = "Computer 6"
Gname = "C6"
Coms()
Cname = "Computer 7"
Gname = "C7"
Coms()
Cname = "Computer 8"
Gname = "C8"
Coms()
Cname = "Computer 9"
Gname = "C9"
Coms()
Px = 13
Py = 3
Cname = "Computer 10"
Gname = "C10"
Coms()
end
function SyncCom()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lime)
print("Make sure the computer that your're syncing is already on and realy to sync")
write("Computer ID: ")
SyncID = read()
write("Syncing Computer")
textutils.slowPrint("...",1)
rednet.send(217,"PasswordPLZ")
id , PASS, dis = rednet.receive()
print(dis)
if PASS == "8932" then
end
end
function Background()
term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.gray)
print("SteamPunk Servers v1.5							 ")
term.setBackgroundColor(colors.blue)
print("GREEN = ON, RED = OFF ORANGE = CALL KIDGAMER")
end
function MainSelect()
event, button,X,Y = os.pullEvent("mouse_click")
if button == 1 then
if X == 1 and Y == 3 then
  CN = "Computer 1"
  CS = "C1"
  ComSc()
elseif X == 1 and Y == 5 then
  CN = "Computer 2"
  CS = "C2"
  ComsBack()
elseif X == 1 and Y == 7 then
  CN = "Computer 3"
  CS = "C3"
  ComsBack()
elseif X == 1 and Y == 9 then
  CN = "Computer 4"
  CS = "C4"
  ComsBack()
elseif X == 1 and Y == 11 then
  CN = "Computer 5"
  CS = "C5"
  ComsBack()
elseif X == 1 and Y == 13 then
  CN = "Computer 6"
  CS = "C6"
  ComsBack()
elseif X == 1 and Y == 15 then
  CN = "Computer 7"
  CS = "C7"
  ComsBack()
elseif X == 1 and Y == 17 then
  CN = "Computer 8"
  CS = "C8"
  ComsBack()
elseif X == 1 and Y == 19 then
  CN = "Computer 9"
  CS = "C9"
  ComsBack()
elseif X == 13 and Y == 3 then
  CN = "Computer 10"
  CS = "C10"
  ComsBack()
  end
end
end
function updateComs()
rednet.open("top")
end
function ComsBack()
term.setBackgroundColor(colors.blue)
term.clear()
term.setBackgroundColor(colors.gray)
term.setCursorPos(1,1)
print("SteamPunk Servers v1.5							 ")
end
function ComSc()
ComsBack()
term.setBackgroundColor(colors.blue)
write("Loading")
textutils.slowPrint("...",4)
term.clear()
ComsBack()
ADD = fs.exists(CS)
if ADD == true then
file = io.open(CS,"r")
Pstatus = file:read()
file:close()
term.setCursorPos(2,3)
term.setBackgroundColor(colors.blue)
write(CN.." Status = "..Pstatus)
print()
write(" +Back")
event,button,X,Y = os.pullEvent("mouse_click")
while true do
if button == 1 then
  if X == 2 and Y == 4 then
   main()
  end
end
end
end
end
function main()
os.pullEvent = os.pullEventRaw
rednet.open("top")
Background()
PutComsLeft()
MainSelect()
sleep(1)
end
main()


#2 Sariaz

  • Members
  • 107 posts

Posted 17 April 2013 - 04:56 PM

In your comsback function where you do event,button,x,y = os.pullEvent("mouse_click") if you change that to

repeat
  event,button,x,y = os.pullEvent()
until event == "mouse_click"


then it should fix do the same thing anywhere you specify what event to pull. This is because for some reason in my experience making it lock with the pullEventRaw messes with os.pullEvents where an event to wait for is specified.

Also id advise tabbing after every line of code that needs a end, makes it look neater also spacing between functions end and beginning little things like that and comments make your code a lot easier to read.

#3 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 17 April 2013 - 08:26 PM

Hi Yuri,

I looked over your code and made some changes see comments for information.
Main thing is that i put your pullevents into loops so that the code is not finishing when you click at an undefined location.
and added some loops to make it little bit shorter

Spoiler

i have tested control+T and its not terminating :)

Geets Loki

#4 JokerRH

  • Members
  • 147 posts

Posted 17 April 2013 - 08:42 PM

View PostSariaz, on 17 April 2013 - 04:56 PM, said:

This is because for some reason in my experience making it lock with the pullEventRaw messes with os.pullEvents where an event to wait for is specified.

os.pullEvent(filter)
calls
os.pullEventRaw(filter)
calls
coroutine.yield(filter)

There shouldn't be any problem.

Edit: I have no idea where your problem is. I copied your program from your post and tested it and it terminated just fine...
Edit2: Do you know how it feels if you write sh*t and as you want to delete it your internet connection crashes?

#5 Sariaz

  • Members
  • 107 posts

Posted 17 April 2013 - 08:44 PM

View PostJokerRH, on 17 April 2013 - 08:42 PM, said:

View PostSariaz, on 17 April 2013 - 04:56 PM, said:

This is because for some reason in my experience making it lock with the pullEventRaw messes with os.pullEvents where an event to wait for is specified.

os.pullEvent(filter)
calls
os.pullEventRaw(filter)
calls
coroutine.yield(filter)

There shouldn't be any problem.

View PostJokerRH, on 17 April 2013 - 08:42 PM, said:

View PostSariaz, on 17 April 2013 - 04:56 PM, said:

This is because for some reason in my experience making it lock with the pullEventRaw messes with os.pullEvents where an event to wait for is specified.

os.pullEvent(filter)
calls
os.pullEventRaw(filter)
calls
coroutine.yield(filter)

There shouldn't be any problem.

it just seams that if i ctrl+t then it triggers os.PullEvent(filter) event though not right event.

#6 JokerRH

  • Members
  • 147 posts

Posted 17 April 2013 - 09:08 PM

function MainSelect()
  event, button,X,Y = os.pullEvent("mouse_click")
    if button == 1 then
       ...
    end
end

There's your problem.
Computers are resumed with an api similar to the parallel api (I think Cloudy said that sometimes), and that checks if the filter matches or the event is "terminate".

In your case os.pullEvent will be resumed with "terminate" and your button variable is nil, so the program stops.
That's the same reason why you can press the right mouse button to stop the program...

#7 Micheal Pearce

  • Members
  • 87 posts
  • LocationUSA

Posted 18 April 2013 - 09:16 AM

Thanks guys :)

#8 Sariaz

  • Members
  • 107 posts

Posted 18 April 2013 - 09:39 AM

Our pleasure.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users