6 posts
Posted 07 December 2015 - 02:33 AM
Hey I have computercraft and all galacticcraft mods also and I'm trying to make an interaction and result program with the oxygen sensor. not really being bothered with creating a whole new system for one rarely used block i am trying to create a red-stone interaction system based on the computer sensing a red stone input or not and the result causing the attached monitor to display one text or another.
mon = peripheral.wrap("monitor_0")
if redstone.getInput("back") == true then
mon.print("yes")
elseif redstone.getInput("back") == false then
mon.print("no")
end
I'm not quite sure what I'm doing wrong
the error received is : "startup:5: attempt to call nill
7083 posts
Location
Tasmania (AU)
Posted 07 December 2015 - 03:08 AM
It's telling you that you're attempting to call a function that doesn't exist, and indeed, there's no "print" function in your "mon" terminal object table - just the ones
here.
You could make use of
term.write():
local mon = peripheral.wrap("monitor_0")
if redstone.getInput("back") then
mon.write("yes")
else
mon.write("no")
end
… but that doesn't give you word-wrapping or line-breaking functionality. For that, you might use
term.redirect(), allowing you to change which terminal object the "regular" print function outputs to:
local mon = peripheral.wrap("monitor_0")
local oldTerm = term.redirect(mon)
if redstone.getInput("back") then
print("yes")
else
print("no")
end
term.redirect(oldTerm)
6 posts
Posted 07 December 2015 - 03:46 AM
thankyou for that that helped alot,
now i have implemented also a line for repeating it indefinitely
its:
repeat
.
.
.
.
until false
now this doesnt change when the conditions are met
any thoughts?
7083 posts
Location
Tasmania (AU)
Posted 07 December 2015 - 04:07 AM
Are you calling redstone.input() within that loop?
You may also run into yield protection issues (ComputerCraft will close scripts that run too long without yielding) - you may want to stick an os.pullEvent("redstone") in there, as that'll make the script yield whenever the redstone input isn't actually changing.
If you're still stuck, post your full code.
6 posts
Posted 07 December 2015 - 04:11 AM
mon = peripheral.wrap("monitor_5")
if redstone.getInput("right") == true then
redstone.setOutput("left", false)
mon.setCursorPos(1,1)
mon.setTextScale(2.5)
mon.write("Atmosphere Secure")
end
if redstone.getInput("right") == false then
mon.setCursorPos(1,1)
mon.setTextScale(2.5)
redstone.setOutput("left", true)
mon.write("Atmospheric Breach")
end
sleep(.5)
mon.clear()
shell.run("startup")
(the output set is for an alarm next to the computer unit)
the shell.run was my alternative and it crashed after a while some window or something error
will try again and grab whole code
window:277: vm error:
java.lang.ArrayIndexOutOfBoundException
Edited on 07 December 2015 - 03:10 AM
8543 posts
Posted 07 December 2015 - 04:24 AM
Moved to Ask a Pro.
7083 posts
Location
Tasmania (AU)
Posted 07 December 2015 - 06:00 AM
When you call shell.run(), it doesn't shut your script down before running the new instance; the old running copy stays in memory until the new one completes, at which point the old one continues from where it left off.
In your case, that never happens: You just keep firing up new instances of the script. Eventually the memory ComputerCraft reserves for such shenanigans runs out and you get that "index out of bounds" error.
Use a proper loop, sticking to one of the structures
explained here. For example:
local mon = peripheral.wrap("monitor_5")
mon.setTextScale(2.5) -- No need to repeat this.
while true do -- Start a loop that repeats indefinitely.
mon.clear()
mon.setCursorPos(1,1)
if redstone.getInput("right") then
redstone.setOutput("left", false)
mon.write("Atmosphere Secure")
else
redstone.setOutput("left", true)
mon.write("Atmospheric Breach")
end
os.pullEvent("redstone") -- Pause until a redstone state change occurs.
end
Edited on 07 December 2015 - 05:02 AM