This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thedogs's profile picture

Modem Channel Help With ICBM

Started by thedogs, 09 August 2013 - 06:08 PM
thedogs #1
Posted 09 August 2013 - 08:08 PM
Hello I need help with the new modem api

I am trying to make is if the message is 1234 it launches the missile

Here is my code

Server

local modem = peripheral.wrap("right")
icbm = peripheral.wrap("left")
modem.open(3)
if modem_message == "1234" then
icbm.launch()
end
end

Another question is how would I write a message to send
So I would have to write the message and then it would send that message to the server

Client

local modem = peripheral.wrap("right")
modem.transmit(3, 1, "1234")

In case you guys don't understand what I am trying to do with my code.
On the client side- You type the launch code if it is wrong a message comes up that says WRONG and something blows up. If it is write then the client send the command to the server to launch the missile.

Server Side
If it recieves the command it launches the missile

Or

Client Side
You type in launch code to send. Sends it and server receives message

Server side
If message is right it launches missiles
If wrong sends a command back to client that will make the area surrounding it blow up


What I don't Understand:
I do not understand how to make the server read a message that is sent from the client.
I do not understand how to make the server check the client message versus the right answer.
Bubba #2
Posted 09 August 2013 - 08:48 PM
Split into new topic.
thedogs #3
Posted 09 August 2013 - 09:41 PM
Heres another question is rednet still working or has it been discontinued?
thedogs #4
Posted 09 August 2013 - 11:19 PM
Another question lol how do Make it where a computer revieves a message from a modem and does a command?
reububble #5
Posted 10 August 2013 - 12:09 AM
you need to use events. For most of this information you can see the wiki page http://computercraft.info/wiki/Os.pullEvent.

All that you need to do is tell your program to wait for a message by using the line
event, param1, param2, param3 = os.pullEvent('rednet_message')
Then the message that is received will be stored in the variable called param2.

You will need to call the pullEvent function every time you want to wait for a new message.
reububble #6
Posted 10 August 2013 - 12:16 AM
For writing the command you can use the read function.
the read function takes an optional argument for what to display as the string is being entered, most commonly '*' is used.

A basic implementation would look like this.


local modem = peripheral.wrap('right')
repeat
  term.clear()
  term.setCursorPos(1,1)
  print('Enter Command')
  command = read('*')
  -- you can put in the exact desired function here
  -- perhaps this is what you need
  modem.transmit(3,1,command)
until command=='exit'
reububble #7
Posted 10 August 2013 - 12:17 AM
Also, yes rednet still works. lol