0

I am trying to make a computer system/network on Tekkit using computercraft.

Computecraft is a Lua based modification which runs within Minecraft/Tekkit and other modification packages.

Basically, I am currently using a wireless router to perform this:

rednet.open('top') -- Open Connection to the wireless router
print ("test")
input = read()
rednet.receive()  -- Listen for messages send/broadcasted 

if message then
 print (message)
end

I am trying to perform a change to all my systems which is something like this:

rednet.open ('top')
 -- Do all normal stuff

rednet.receive()
if message == "Lock202" then 
 os.pullEvent = os.pullEventRaw
 term.clear()
 term.setCursorPos(1,1)
 print ("Alert In Progress, Terminal Locked")
end

by do all normal stuff, I want the user to be able to navigate and use the functionality of the computer. But when calling rednet.receive() it freezes and awaits an incoming message.

I want this to run in the background and only act when a message is received.

I have tried looking at the documentation, helpsites. and thought to bring this question over to SO because due to the range of Lua Coders available.

Ryan Stein
  • 7,930
  • 3
  • 24
  • 38
user2146021
  • 47
  • 3
  • 9

3 Answers3

4

http://computercraft.info/wiki/Parallel.waitForAll

that is a function that will basicly multi thread your program... sooo you could doo...

function listen()
 while true do
  id, msg, distance = rednet.receive()
  FUNCTION_THAT_RUNS_STUFF(id, msg, distance)
  sleep(1)
 end
end

function main_loop()
 while true do
  --do your other stuff in here
 end
end

--end of file run everything
parrallel.waitForAll(listen, main_loop)
Alan Doyle
  • 98
  • 16
0

The command rednet.receive() can have an argument in it's parameters and that is "Time-out".

This is measured in seconds. It is also a float (decimal) e.g. 4.50, 1.23. etc.

This means that it will receive for that period of time.

A good way of accomplishing what you want is to have another computer constantly receiving messages and then giving out a redstone signal to the computer you want to be doing the modular receiving and writing something along the lines of

function Check()
  If rs.getInput("back") then
     local id, message = rednet.receive(5)
     print("Receiving Message")
  end
end

The other computer would be doing this:

computerid = 50

id, message = rednet.receive()
  rs.setOutput("back",true)
  sleep(1)
  rednet.send(computerid, message)
  rs.setOutput("back",false)

The computerid would be equal to whatever the original computer you want to be running's ID is. You would also have to use the Check() function regularly while running the code, It won't affect the computer unless a message is being received in which case it receives for the amount of time specified in the "rednet.receive"'s arguments.

Hope this has been helpful

--EwilDawe

Ewildawe
  • 11
  • 1
0

what i did was i had 1 pc running os.pullEvent, and a load of other ones gathering information and sending it through rednet, which made it so only one pc was stuck like that, despite the fact that the others were pretty much unusuable, of course if you did what i did you could make it detect keys and rednet_message and more.

Edward Ford
  • 71
  • 1
  • 1
  • 3