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

Undefined Functions

Started by 1wsx10, 19 October 2017 - 08:17 AM
1wsx10 #1
Posted 19 October 2017 - 10:17 AM
I want to write a program that can run with or without an api.

Whenever i run it without the api loaded, i get an error at the first function call.

If i wanted to do this with some variable, i would do something like this:

function do_something(var)
	if not var then
		--do it without var
	else
		--use var
	end
end
Is there a way for me to do this with an API function that may or may not be loaded?

i was thinking maybe a second API that gives function pointers, but then that would have the same problem.
Edited on 19 October 2017 - 09:06 AM
KingofGamesYami #2
Posted 19 October 2017 - 12:43 PM
APIs are tables and functions are variables.


if API and API.somefunction then
  --# do one thing
else
  --# do another
end
1wsx10 #3
Posted 19 October 2017 - 01:23 PM
Thanks!