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

Micro controller programming. (my erorrs in it)

Question

I am not very versed in that kind of programming,

but I managed to write the following code so far:

local modem=component.proxy(component.list("modem")())
local turbine=component.proxy(component.list("br_turbine")())
modem.open(1)
local target = false
while true do
	local e, to, from, _, _, command = computer.pullSignal()
	if e == "modem_message" then
		if command == "s" then
			modem.send(from,1, "Handshake")
			local target = from
		elseif command == "a" then
			if (turbine.getActive()) then
				turbine.setActive(false)
			else
				turbine.setActive(true)
			end
		elseif command == "c" then
			if (turbine.getInductorEngaged()) then
				turbine.setInductorEngaged(false)
			else
				turbine.setInductorEngaged(true)
			end
		elseif (target) then
			local data1 = tostring(turbine.getActive())
			local data2 = tostring(turbine.setInductorEngaged())
			local data3 = tostring(turbine.getRotorSpeed())
			modem.send(target,1, data1, data2, data3)
		end
	end
end

But if I try to run it I only get the error message:

Quote

bad argument #1 (string expected, got nil)

and I haven't a clue what did I wrong where.

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

It's pretty hard to tell where exactly this is coming from. I dont have br and im too lazy to install a modpack with it.... However, I would usggest littering your code with print statements to see where specifically the code is failing... Try this and see if provides any clues...

local modem=component.proxy(component.list("modem")())
local turbine=component.proxy(component.list("br_turbine")())
modem.open(1)
local target = false
print "main loop start."
while true do
	local e, to, from, _, _, command = computer.pullSignal()
	if e == "modem_message" then
    	print("modem_message event. from: '" .. from .. "'")
		if command == "s" then
      		print "'s' command. sending handshake."
			modem.send(from,1, "Handshake")
			local target = from
		elseif command == "a" then
      		print "active command"
			if (turbine.getActive()) then
				turbine.setActive(false)
        		print "turbine inactive"
			else
				turbine.setActive(true)
        		print "turbine active"
			end
		elseif command == "c" then
      		print "inductor command"
			if (turbine.getInductorEngaged()) then
        		print "inductor disengaged"
				turbine.setInductorEngaged(false)
			else
        		print "inductor engaged"
				turbine.setInductorEngaged(true)
			end
		elseif (target) then
      		print "target... how did we get here..."
			local data1 = tostring(turbine.getActive())
			local data2 = tostring(turbine.setInductorEngaged())
			local data3 = tostring(turbine.getRotorSpeed())
      		print("sending turbine data to target")
      		print("target: " .. (type(target)=="string" and target or "target should be string not bool.."))
			modem.send(target,1, data1, data2, data3)
		end
	end
end
print "we made it..."

 

Link to post
Share on other sites
  • 0
local modem=component.proxy(component.list("modem")())
local turbine=component.proxy(component.list("br_turbine")())
local target = nil
modem.open(1)
local target = false
while true do
	local e, to, from, _, _, command = computer.pullSignal()
	if e == "modem_message" then
		if command == "s" then
			modem.send(from,1, "Handshake")
			target = from
		elseif command == "a" then
			if (turbine.getActive()) then
				turbine.setActive(false)
			else
				turbine.setActive(true)
			end
		elseif command == "c" then
			if (turbine.getInductorEngaged()) then
				turbine.setInductorEngaged(false)
			else
				turbine.setInductorEngaged(true)
			end
		end
		if (target) then
			local data1 = tostring(turbine.getActive())
			local data2 = tostring(turbine.setInductorEngaged(true))
			local data3 = tostring(turbine.getRotorSpeed())
			modem.send(target,1, data1, data2, data3)
		end
	end
end

This should do it. When you defined target, it was local to the block it was defined in, and nil outside. You also didn't pass a boolean to setInductorEngaged, but since I don't use BR / ER, I don't know much about the API, and it may not even need an argument.

Link to post
Share on other sites
  • 0

How can this code work at all?

The big reactor turbine is an external component.

As far as I know the only interaction with the world is possible with a wireles modem and redstone signals.

1.PNG

 

I guess component.list("br_turbine") is nil and component.proxy(nil) doesn't work so it ends in line 2.

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.