Posted 10 January 2015 - 05:26 PM
Hi
I tried to use the pcall in my newest program (it's a small code for controlling a stargate, see SG Craft for more info), and it usually works greatly and as intended, except in the case when I try to run the code as the 'startup' program - and that's the actual environment that I want my program to run!
Whenever I reboot the computer and have the startup program run by itself, the error will not be caught (if thrown) and will actually force the program to exit, showing as the default-style error message in the console.
If I run the 'startup' in the console by typing it, it will work as intended and will never exit when error do occur (as just stated above.)
I am baffled. Is there something I am missing or doing wrong?
The following is the code that I am currently testing (it's a mess really; I am not a proper programmer at all!):
Thank you in advance.
I tried to use the pcall in my newest program (it's a small code for controlling a stargate, see SG Craft for more info), and it usually works greatly and as intended, except in the case when I try to run the code as the 'startup' program - and that's the actual environment that I want my program to run!
Whenever I reboot the computer and have the startup program run by itself, the error will not be caught (if thrown) and will actually force the program to exit, showing as the default-style error message in the console.
If I run the 'startup' in the console by typing it, it will work as intended and will never exit when error do occur (as just stated above.)
I am baffled. Is there something I am missing or doing wrong?
The following is the code that I am currently testing (it's a mess really; I am not a proper programmer at all!):
Spoiler
sg = peripheral.wrap("left") --Gate Interface side
addr = "NN8L-G30-SA" --Gate dial address
side = "bottom" --Redstone input side
--This is a crude and temporary attempt to run the stargate.
while true do
if( sg.stargateState() == "Idle") then
if( redstone.getInput(side) ) then
print("Dialling...")
ok, result = pcall(sg.dial, addr) --Try to dial the address
--sg.dial(addr)
if ok then --WIll print true if successful, false if err
print("Dial complete\n")
sleep(300) --So that the program will wait until the gate shuts down automatically
else
print("Dialling failed: ", string.sub(result,8),"\n")
sleep(2) --So that the message is not displayed more than once. This is a crude implementation.
end
--sleep(300)
end
end
sleep(0.5)
end
Thank you in advance.