This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gheotic's profile picture

COmputer Smart interface (Need help)

Started by gheotic, 23 January 2013 - 12:49 AM
gheotic #1
Posted 23 January 2013 - 01:49 AM
Im working on a script that have some buttons that you can switch between
but if i do something like this
local sEvent, param = os.pullEvent("key")

would it be able to carry on a loop
then activate a if command


like
while true do
local message = rednet.receive() – i know there might be an error here just ignore that

local sEvent, param = os.pullEvent("key")

if(sEvent == "key") then
if(param == 200) then
term.setCursorPos(18, 10)
end

end – loop



any help would be appreciated =)
3ydney #2
Posted 23 January 2013 - 01:56 AM
Take it out of the loop! It doesnt need it!

local sEvent, param = os.pullEvent("key")
while true do
 local id, message = rednet.receive()
 if(sEvent == "key") and (param == 200) then
  term.setCursorPos(18, 10)
 end
end
ikke009 #3
Posted 23 January 2013 - 03:52 AM
1. Yes, you can put it in a loop.
2. You dont need to check if sEvent == "key" because you already pulled the event with the "key" filter.
3. at FreePaidRemake, if you'd have that loop it would keep receiving rednet messages and putting the cursor on 18,10 forever if you pressed the right key :S so yeah it either needs to be in that loop or you'll have to restrict the loop till a certain point