This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thedobbles's profile picture

Custom Turtle API Issues

Started by thedobbles, 05 January 2015 - 01:50 PM
thedobbles #1
Posted 05 January 2015 - 02:50 PM
[CLOSED]

So, I am trying to make a custom turtle API, and I want to make it so that in startup you use one function to make it so that the turtle uses rednet. Is it possible to do it like I have done here? I don't really have a way to check at the moment. The way I envision it, each turtle has its own instance of the API when you load it… Is that how it really works?

Here is the code that I have so far

-- Variable Declaration
nAPI_RN = false -- set this to true if you don't want to use isRN()

-- Use this in your startup to enable or disable rednet
function isRN(isRN_) { -- Enter true or false
if isRN_ == "true"
  nAPI_RN = true
  return nAPI_RN
elseif isRN_ == "false"
  nAPI_RN = false
  return nAPI_RN
else
  error("true or false expected. nAPI will default to not use RedNet.")
  nAPI_RN = false
end
}
Edited on 06 January 2015 - 01:12 AM
Lyqyd #2
Posted 05 January 2015 - 03:27 PM
Moved to Ask a Pro.
Bomb Bloke #3
Posted 05 January 2015 - 11:59 PM
Remember that "true" (a string) is not the same thing as true (a boolean), and function definitions don't involve curly brackets.

Yes, if an API is loaded by one system, the instance of the API which then exists in RAM is separate to those which are loaded by other systems (even if they were loaded from the one single original file).
thedobbles #4
Posted 06 January 2015 - 02:11 AM
Thanks! When I was eating breakfast this morning I figured out a better way to do this, but it is good to know how the API works!