Jump to content




[Question] Inputs not being received intermittently in complex programs.


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

#1 TheGeek

  • Members
  • 60 posts

Posted 20 November 2012 - 11:59 AM

I am currently working on a Command & Control computer program that facilitates the setting of states of items around our base area, such as piston drawbridges and wireless melee turtles. This computer has two buttons and a monitor, and displays the states of various items.

So far I have able to overcome various bugs and such, but this one is really proving to be troublesome.

I appear to be having issues with my program not sensing inputs; IE i press the button and the program does nothing, 1 out of 4 times. The best solution would be to set an event to halt the program until that button is pressed, but its not practical as this program also is listening for RedNet messages, and responding with the proper state.

I am having a similar issue with RedNet computers not receiving messages, as I set a short timeout period for rednet.receive() so the program can deal with other inputs, such as a tripwire triggering a melee turtle to attack. The problem is solved on the piston drawbridge control computer, as it only receives during its main loop, so an infinite timeout period is practical.

Here is my code: (please be forgiving, I'm a LUA noob :(/>)
Command & Control Computer:
Spoiler

Drawbridge Control Computer:
Spoiler

And for kicks, the Wireless Melee Turtle (or as I have nicknamed them TurtleDrones) Control Program:
Spoiler

In my efforts to come up with a solution, I theorized that if I split off the button inputs into another computer that could have a dedicated button input, sending rednet signals to the C&C comp when buttons were pressed, enabling the C&C comp to work with infinite timeouts. This really wouldn't work with the Turtle's though...

Thanks in advance for the help!

EDIT: Its not really a LUA problem, its more of a question. Maybe now I might get some help.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 November 2012 - 02:10 PM

You need to be handling incoming events if you want to listen for more that one thing. Something like this:

while true do
    event, p1, p2, p3 = os.pullEvent()
    if event == "redstone" then
        --check your redstone inputs to see what changed and respond accordingly
    elseif event == "rednet_message" then
        --handle the rednet message
    end
end


#3 TheGeek

  • Members
  • 60 posts

Posted 20 November 2012 - 03:42 PM

View PostLyqyd, on 20 November 2012 - 02:10 PM, said:

You need to be handling incoming events if you want to listen for more that one thing. Something like this:

while true do
	event, p1, p2, p3 = os.pullEvent()
	if event == "redstone" then
		--check your redstone inputs to see what changed and respond accordingly
	elseif event == "rednet_message" then
		--handle the rednet message
	end
end

Hmmm. Looking at the info for os.pullEvent(), it says it will stop the program from running until an event occurs, but since it can be any event and not just RedNet OR Redstone, I think I can make this work. I guess having the time displayed will be a function of alarm or somesuch, but adding a time display to the monitor is low on the priority list.

Just to make sure I understand how to use this correctly the code would be:
while true do
	event, p1, p2, p3 = os.pullEvent()
	if event == "redstone" then
        buttonpressed = redstone.getInput(side)
       if buttonpressed == true then
		--check your redstone inputs to see what changed and respond accordingly
       end
	elseif event == "rednet_message" then
       id,message = rednet.receive()
		--handle the rednet message
	end
end

Do i have that right?

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 November 2012 - 04:50 PM

Not quite. When handling a rednet_message event, the parameters that rednet.receive() would have returned are used as the event parameters. That is to say, in the above example, p1 and p2 are the ID of the sender of the rednet message and the message itself, when the event is a rednet_message event.

#5 TheGeek

  • Members
  • 60 posts

Posted 20 November 2012 - 05:47 PM

View PostLyqyd, on 20 November 2012 - 04:50 PM, said:

Not quite. When handling a rednet_message event, the parameters that rednet.receive() would have returned are used as the event parameters. That is to say, in the above example, p1 and p2 are the ID of the sender of the rednet message and the message itself, when the event is a rednet_message event.

Ah i figured that out well after I posted that.

Thanks for the help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users