local message
local timeWaited = 0
term.clear()
while message ~= "stop" do
repeat
local id = os.startTimer(interval)
local event, idCheck, sendChannel, _, locMessage, distance = os.pullEvent()
message = locMessage
if (event == "timer" and idCheck == id) then timeWaited = timeWaited + interval else timeWaited = 0 end
until (event == "modem_message" and idCheck == modemSide and sendChannel == sender) or (event == "timer" and idCheck == id)
sendMsg(relayMessage)
--Text to screen stuff
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[Lua] Problem with repeat loops and timers
Started by civilwargeeky, 19 April 2013 - 11:39 AMPosted 19 April 2013 - 01:39 PM
Hello. In a section of my quarry rednet receiver program, there is a part where it should wait for either a message or a five second timer, however it does not ever activate for the timer. I cannot figure out what I'm doing wrong. Can anyone help?
Posted 19 April 2013 - 01:47 PM
That is because interval is never defined, you should have a number as integer. Eg. 1 and 4, every number that has no decimals. That is a double; 0.24
Posted 19 April 2013 - 01:49 PM
Oh I'm sorry, interval was assigned in the config. Currently interval is set to 5That is because interval is never defined, you should have a number as integer. Eg. 1 and 4, every number that has no decimals. That is a double; 0.24
Posted 19 April 2013 - 04:21 PM
So is this a bug or what?
Posted 19 April 2013 - 04:39 PM
Whats with having just
local message
and not define the message? Or is there more to your code?Posted 19 April 2013 - 06:07 PM
Whats with having justand not define the message? Or is there more to your code?local message
If you define the variable without giving it a value, it will maintain the same scope throughout the entire program (or at least until you define another variable with the same name, in which case the new variable will take precedence until you have exited the function).
@OP: What do you mean it never activates the timer? Your code works fine for me.
Posted 20 April 2013 - 02:54 AM
Well. When I use the full program, it will receive messages and display them to the screen, but it will not update a section that says "Seconds since last message." One thing to note is that this function is part of a coroutine. The other coroutine function just waits for read() to relay commands to the turtle.@OP: What do you mean it never activates the timer? Your code works fine for me.
Posted 20 April 2013 - 02:58 AM
@Engineer, there are no integers in lua, nor are there doubles. There is only numbers.
Posted 20 April 2013 - 04:10 AM
It was for the sake of the example@Engineer, there are no integers in lua, nor are there doubles. There is only numbers.
Posted 20 April 2013 - 04:11 AM
Well. When I use the full program, it will receive messages and display them to the screen, but it will not update a section that says "Seconds since last message." One thing to note is that this function is part of a coroutine. The other coroutine function just waits for read() to relay commands to the turtle.@OP: What do you mean it never activates the timer? Your code works fine for me.
You should provide the whole code because the problem may lie in that; I was able to get this to run just fine. My guess is that the function that is supposed to write the time to the screen is not actually updating anything.
Posted 20 April 2013 - 05:34 PM
Ok. Here is the code. Sorry it might be a bit messy, but it was in the middle of being updated.
http://pastebin.com/6L2JZPjH
The part where it outputs time is line 84
http://pastebin.com/6L2JZPjH
The part where it outputs time is line 84
Posted 20 April 2013 - 05:36 PM
You should provide the whole code because the problem may lie in that; I was able to get this to run just fine. My guess is that the function that is supposed to write the time to the screen is not actually updating anything.
Ok. Here is the code. Sorry it might be a bit messy, but it was in the middle of being updated.
http://pastebin.com/6L2JZPjH
The part where it outputs time is line 84
Here is the turtle program that (should) work with this version of the receiver. Use the argument "-rednet true" when you start
http://pastebin.com/UC0XehGH