• Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Welcome to OpenComputers

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more!

This message will be removed once you have signed in.

  • Announcements

    • Lizzy Trickster

      Latest Stable OpenComputers Version   11/26/16

      The latest released version of OpenComputers is version 1.6.1 for MC 1.7.10, 1.8.9, 1.9.4 & 1.10.2. See more information here! Beta/Dev builds can be found at the Jenkins Build Server (ci.cil.li)
  • 0
Zeldri

Sending multiple Variables in the network

Question

Is that possible to send multiple variables with comp.modem.send() ?

Because I want to send like that :

function sendMsg(type,data,data2,data3)
    m.open(118)
    m.send(address,118,type,data,data2,data3)
end

And i call the function like that :

sendMsg("ReacteurInfo",pct(),cube.getEnergy(),cube.getMaxEnergy())

The problem is that the second variable isn't being send ( the third too ) same if i put cube.getEnergy() before, (in this case only cube.getEnergy() is being send and vise-versa) But when I want to send 2 or 3 string it's working perfectly 

sendMsg("ReacteurInfo","test1","test2","test3")

 

Share this post


Link to post
Share on other sites

3 answers to this question

  • 0

From looking at the modem component API you should be able to send up to 8 basic datums in each message.  From what I can see in your example It should work fine sending. Could you post your receiving code? The 'modem_message' event has 5 return values before the data you've sent.

local _event, localAddress, remoteAddress, portNumber, distance, sentData1, sentData2, sentData3, sentData4 = event.pull("modem_message")

 

Share this post


Link to post
Share on other sites
  • 0
46 minutes ago, Molinko said:

From looking at the modem component API you should be able to send up to 8 basic datums in each message.  From what I can see in your example It should work fine sending. Could you post your receiving code? The 'modem_message' event has 5 return values before the data you've sent.


local _event, localAddress, remoteAddress, portNumber, distance, sentData1, sentData2, sentData3, sentData4 = event.pull("modem_message")

 

Ok so I dont know why but now I receive all the data but the problem is that I receive nil when I'm using it on my program

nX3OTbWbTh_nXTDvMWZ4Aw.thumb.png.77fb1967f47fcece8cdafff9368797ed.png

But On my program i got a nil value

TB_V2oX8RjyQ2oWB46jcNg.png

There is my code

local comp = require("component")
local term = require("term")
local colors = require("colors")
local event = require("event")
local gpu = comp.gpu
local m = comp.modem
gpu.setResolution(100,31)
local w,h = gpu.getResolution()
 
os.sleep(1)
m.open(118)
m.broadcast(118)
while true do
  gpu.setBackground(0x202020)
  gpu.fill(1,1, w, h, " ")
  gpu.setBackground(0x606060)
  gpu.fill(1, 1, 2, h, " ")
  gpu.fill(1, 1, w, 1, " ")
  gpu.fill(w-1, 1, 2, h, " ")
  gpu.fill(1, h, w, 1, " ")
  gpu.fill(w/2, 1, 2, h, " ")
  gpu.fill(1, 1, w, 3, " ")
  gpu.set(w/4-4, 2,"Réacteur")
  gpu.set((w/2+w/4)-4, 2, "Crystaux")
  os.sleep(1)
local  evt,ladd,radd,dis,port,type,data1,data2,data3 = event.pull("modem_message")
  if type == "ReacteurInfo" then
    data1 = pct
    data2 = nrj
    data3 = nrjMax
    gpu.set(4,8,nrj)
    gpu.set(4,10,nrjMax)
    gpu.set(4,12,pct)
  end
  gpu.setBackground(0x000000)
end

 

Share this post


Link to post
Share on other sites
  • 0

I'm pretty sure your problem is here..

    data1 = pct -- pct is nil
    data2 = nrj -- nrj is nil
    data3 = nrjMax -- nrjMax is nil
    gpu.set(4,8,nrj) -- This is where the error comes from. "Bad Argument #3 (string expected, got nil.)"...
    gpu.set(4,10,nrjMax) -- so on..
    gpu.set(4,12,pct) -- and so on..

Nowhere in the above code you supplied did you define the values of pct, nrj, or nrjMax. So, they are nil.

Share this post


Link to post
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