ooooo, yay! someone finally using the new OpenPeripheral ;)/>
the error was an oversight on my part, and Mikeemoo not explaining how to implement multi-return values correctly :P/> as such when something cannot happen the code will error back to you. The way to get around this is to pcall each function that will error on you. you can also then check the error message to see why it won't happen. I'll supply a list in a minute to help you :)/> here is example code
local ok, err = pcall(gate.connect, "HGFIESF")
if not ok then --# the "ok" variable is whether or not the function call was successful, in this case we're checking if it was not successful
print("Something went wrong!")
print(err) --# this will print out what went wrong from the error message stored in "err"
end
A list of what can go wrong
connect- "Stargate damaged or incompelte" — (oops, just saw spelling mistake, fixed in the next version) occurs when the gate is missing blocks and is not a complete ring (can be mitigated by checking isGateComplete)
- "Stargate addresses must be 7 letters" — occurs when the target address is not enough characters (can be mitigated by checking length yourself)
- "No Stargate at address " + address — occurs when the stargate doesn't exist (can be mitigated by checking the address with isValidAddress)
- "Stargate cannot connect to itself" — occurs when the target address is the same as the origin address (can be mitigated by making sure they're not trying to dial themselves)
- "Stargate at address " + targetAddress + " is busy" — occurs when the target gate is currently connected to another gate
- "Stargate has insufficient fuel" — occurs when the origin gate does not have enough fuel to make a connection (can be mitigated by checking fuel levels first!)
disconnect / getState / getLockedChevronCount / getFuelLevel / getMaxFuelLevel / isDHDConnected / isConnected / isInitiator / canTravelFromThisEnd / getDialledAddress- "Stargate damaged or incompelte" — occurs when the gate is missing blocks and is not a complete ring (can be mitigated by checking isGateComplete)
As you can see from the above list, most functions you can call on the stargate will error (there are a few that won't) but
all of them except the target gate being busy has some way for you to avoid them. I suggest setting up helper/wrapper functions like so
local function connect(addr)
if not gate.isGateComplete() then
return false, "Gate is not yet built"
end
if #addr ~= 7 then
return false, "Incomplete gate address"
end
if not isValidAddres(addr) then
return false, "That stargate doesn't exist"
end
--# etc
gate.connect(addr)
end
local function disconnect()
if gate.isGateComplete() then
gate.disconnect()
end
end
--# etc
as for getting it to not have the .0 do this
m.write(string.format("%d", gate.getLockedChevronCount()))
having %d will remove it.