Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 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")

 

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 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")

 

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

 

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.