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
[Lua] Problem with repeat loops and timers
Started by civilwargeeky, Apr 19 2013 12:39 PM
11 replies to this topic
#1
Posted 19 April 2013 - 12: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?
#2
Posted 19 April 2013 - 12: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
#3
Posted 19 April 2013 - 12:49 PM
Engineer, on 19 April 2013 - 12:47 PM, said:
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
#4
Posted 19 April 2013 - 03:21 PM
So is this a bug or what?
#5
Posted 19 April 2013 - 03:39 PM
Whats with having just
local messageand not define the message? Or is there more to your code?
#6
Posted 19 April 2013 - 05:07 PM
Spongy141, on 19 April 2013 - 03:39 PM, said:
Whats with having just
local messageand not define the message? Or is there more to your code?
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.
#7
Posted 20 April 2013 - 01:54 AM
Bubba, on 19 April 2013 - 05:07 PM, said:
@OP: What do you mean it never activates the timer? Your code works fine for me.
#8
Posted 20 April 2013 - 01:58 AM
@Engineer, there are no integers in lua, nor are there doubles. There is only numbers.
#10
Posted 20 April 2013 - 03:11 AM
civilwargeeky, on 20 April 2013 - 01:54 AM, said:
Bubba, on 19 April 2013 - 05:07 PM, said:
@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.
#11
Posted 20 April 2013 - 04: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
#12
Posted 20 April 2013 - 04:36 PM
Bubba, on 20 April 2013 - 03:11 AM, said:
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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











