Jump to content

Help please - Computer craft - wireless toggle for engines?


vaikepois

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...