Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
ƸӜƷ

calling component in variable but error

Question

Hello world !

I need you for the first time because i'm in a project : research ice by drone like the series "Mars" on mars from the Galacticraft mod

 

but i have problems for programing : for the client (drone) it's done but for the server no i'm stuck

i'm using the folowing line for registering the module : modem :

local m=require("modem")

but it's not working...

the error

module modem not found

 

thanks a lot

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Try:

local c = require("component")
local m
if c.isAvailable("modem") then
    m = c.getPrimary("modem")
end

or

local c = require("component")
local m = c.modem

or

local m = require("component").modem

or

local m = require("component").getPrimary("modem")

 

Share this post


Link to post
Share on other sites
  • 0

The reason that your code isn't working is that require is a function avaliable in open-os

on an eeprom you have to interface directly with the components.

try:

function getComponent(name)
	component.proxy(component.list(name, true)())
end

local m = getComponent("modem")

component.list lists all components with the given name's addresses and type (calling the return value returns the first index's address)

component.proxy gives you a "proxy" of the component using an address

with out a proxy you would have to use component.invoke to call a method on a component

 

realised that you needed help with the server not the drone sorry, ignore this post.

Edited by J_E_Mc
misread the post

Share this post


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.