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

Help with Nanomachine cycling

Question

I need help with nanomachine "probing". I'm trying to create a very basic program that cycles trough nanomachine slots. I intialize a variable in the beginning then create a for loop and increment the variable with 1 each time it's finishes. However it does not work. I can for example initialize the same variable in the first line, gave it a number and then it will check if that nanomachine slot do anything but as soon as I add the commented out code parts the program does nothing besided priting x.

x = 17

local component = require("component")
local m = require("component").modem
local event = require("event")
local term = require("term")

--for i=1,10 do


component.modem.broadcast(1, "nanomachines", "setInput", x, true)
os.sleep(2)

component.modem.broadcast(1, "nanomachines", "setInput", x, false)
print(x)

--x = x+1
--end

 

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

The variable 'x' is only ever defined as 17 and is never changed.

your loop will just iterate over the code 10 times.

if you change the 'x' variables to 'i', then the modem calls will use the current number stored in i (which for your for loop above, would be 1 through to 10)

 

 

Link to post
Share on other sites
  • 1
5 hours ago, Lizzian said:

The variable 'x' is only ever defined as 17 and is never changed.

your loop will just iterate over the code 10 times.

if you change the 'x' variables to 'i', then the modem calls will use the current number stored in i (which for your for loop above, would be 1 through to 10)

 

 

Not correct, there is x=x+1 line near the bottom. 

Link to post
Share on other sites
  • 0
On 11/21/2018 at 9:30 AM, Mystery said:

I suppose that you should add "os.sleep(1)" after "print (x)". There is no delay between setInput calls here.

 

On 11/21/2018 at 3:50 PM, Lizzian said:

The variable 'x' is only ever defined as 17 and is never changed.

your loop will just iterate over the code 10 times.

if you change the 'x' variables to 'i', then the modem calls will use the current number stored in i (which for your for loop above, would be 1 through to 10)

 

 

Ahh actually, I got to set x as local (And equal to 1) in the first line. Now it does cycl trough the channels. Easy and cheesy!:)

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.