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

Need Help Calling Functions

Started by Adjgamer, 16 December 2012 - 07:36 AM
Adjgamer #1
Posted 16 December 2012 - 08:36 AM
I was writing a program for CC but i wanted to use a text editor instead just because of debugging/saving. I wrote functions as different pages so they were in a separate .lua file. I tried to call all of my functions together but it couldn't find the functions. I put them all in a folder together but it still couldn't find them. Do I HAVE to write all my functions in the program? I know you can call functions from other files in Python (which i'm used to).
Thanks
NDFJay #2
Posted 16 December 2012 - 08:46 AM
You could try loading the other files as an API using os.loadAPI("file") for each of the files that have functions you want to include, this will load the files/functions into the OS its self so you can call them in in program for that session
dissy #3
Posted 16 December 2012 - 09:29 AM
If you load each file as an API, you will need to adjust your code when calling any of those functions.
Instead of just: command()
It will need to be: filename.command()
This could also have an effect on the scope of your variables, depending how you are using scopes.

If/when it comes time to distribute your program, this will rule out things like pastebin, and probably annoy others greatly if you have a lot of functions where most of them are fairly small.

You could keep your files seperate for development/editing, and then paste them all together in the end (making sure your 'main' file is pasted last at the end), but that sounds like it would just make a ton of extra work on your end for not much gain. Up to you however.

Unless your program is multiple hundreds of lines long in total, it's generally easier to keep them in one file.
Especially so if you ever plan to distribute it - but of course if this is private then that part won't matter.

If you use notepad++, there are a couple plugins that can merge a directory of files together for you into a single output file, which may also be helpful.