notgodsarmy666 0 Posted August 19, 2017 Share Posted August 19, 2017 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. Quote Link to post Share on other sites
0 Molinko 43 Posted August 19, 2017 Share Posted August 19, 2017 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..." Quote Link to post Share on other sites
0 BrisingrAerowing 12 Posted August 19, 2017 Share Posted August 19, 2017 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. Quote Link to post Share on other sites
0 Nexarius 18 Posted August 20, 2017 Share Posted August 20, 2017 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. I guess component.list("br_turbine") is nil and component.proxy(nil) doesn't work so it ends in line 2. Quote Link to post Share on other sites
0 Molinko 43 Posted August 20, 2017 Share Posted August 20, 2017 When you're dumb and overlook the obvious.. thanks. I don't know why I didn't think of that... Quote Link to post Share on other sites
I am not very versed in that kind of programming,
but I managed to write the following code so far:
But if I try to run it I only get the error message:
and I haven't a clue what did I wrong where.
Link to post
Share on other sites