Jump to content

Recommended Posts

Posted

Hello!

Umm.. I was wondering.. is there way to connect computer with engines?

I mean is there a way. That i Set up MAIN computer and give commands from there to turn off Stirling engines etc.. (basically toggle redstone signals) and use the wirless devices?

If someone knows how. then please explain.

Posted

You can set up computers to send and receive signals wirelessly using wireless modems. It requires a bit of knowledge of how to configure a computer to listen for events, but once you learn the basics, it becomes much more powerful than the ChickenBones wireless redstone, since every computer can either send to multiple targets, or receive signals from multiple computers, handling each such signal differently.

Posted

The functions you are looking for are:

1. http://computercraft.info/wiki/Rednet.send for sending messages to a specified computer, or http://computercraft.info/wiki/Rednet.broadcast for sending messages to ALL computers with wireless modems.

2. http://computercraft.info/wiki/Rednet.receive for receiving messages. You can set up a timeout so that it waits only some time for a rednet signal, and then keeps on running the rest of the program.

3. http://computercraft.info/wiki/Os.pullEvent for making a system that can receive messages from multiple different senders - see http://computercraft.info/wiki/Rednet_message_(event) for the syntax on the message. It can also be used to make a program react to other events, like receiving a redstone signal, or a touchscreen interaction.

You can get your computer's ID by either using os.getComputerID, or there is, I believe, a certain program pre-baked on the computers to check it without using the LUA prompt. So here's an example. I assume that sender ID is 1, and receiver ID is 2. Double-dash (--) denotes the start of a comment in LUA. I apologize if what I'm writing is too basic for you, I have no idea of your knowledge of LUA coding.

First, sender code:

ID = os.getComputerID

print(ID) -- The first 2 lines are not necessary, but just show how you can find out your computer ID.

message_true = "I like turtles" -- This way of doing it can be useful if you want to modify your message.

message_false = "I don't like turtles"

 

while true do -- Endless loop

    if redstone.getInput("left") == true then -- Checks for redstone signal from left side of the computer, and sends message if there is.

        rednet.send(2, message_true, true)

        sleep(0.1) -- To prevent bogging down the server with computer programs that run too fast.

    else

        rednet.send(2, message_false, true)

        sleep(0.1) -- to quickly skip the loop and wait for another redstone input.

    end

end


 

Second, receiver code if using rednet.receive:

 


while true do

    ID, message, distance = rednet.receive() -- Will wait for a rednet message forever until it receives one, and then uses variables ID, message and distance to store data upon reception.

    if ID == 1 then -- Is the computer that sent this message the PROPER computer?

        if message == "I like turtles" then

            redstone.setOutput("back", true)

        else

            redstone.setOutput("back", false)

        end

    end

end


 

Finally, receiver code if using os.pullEvent:

 


while true do

    event_type, param1, param2, param3 = os.pullEvent() -- Same as rednet.receive, except it can handle other events.

    if event_type == "rednet_message" then -- Now it turns into rednet.receive completely.

        if param1 == 1 then -- Is the computer that sent this message the PROPER computer?

            if param2 == "I like turtles" then

                redstone.setOutput("back", true)

            elseif param2 == "I don't like turtles" then

                redstone.setOutput("back", false)

            end

        end

        elseif event_type == "char" -- Here it can detect a keystroke pressed on the keyboard when running the program and accessing the computer. Can be handy for elevators.

            print(param1) -- Will display the key pressed on the monitor

        end

    end

end

Note how receiving computers don't need to use "sleep" - since they have to wait for a message or another event, the computer stops running until such an event occurs - which, essentially, means that the receiving program can only run as fast as the sending one.

P.S. I wrote these snippets without access to the actual game at the moment, so take their syntax with a grain of salt. I do not guarantee that these programs will execute properly, or at all. This is just to give you a gist of how the thing works.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...