Call a function in another codefile
Hello, I am relatively new to programming in LUA. I cannot figure out how to call a function located in a secondary .lua file inside the addon folder.
I have 3 files in the folder. addon.lua objectfactory.lua RiftAddon.toc I add both lua files to RiftAddon "RunAtStartup" section. But every time I try to call a function in objectfactory I get this error: Error: attempt to index global "function" (a nil value) In addon/addon.lua Any advice would be greatly appreciated. |
Place objectfactory.lua first in the RunAtStartup list. Thus:
Code:
RunAtStartup = { |
From the error it looks like it's trying to call a function from addon.lua and not objectfactory.lua. You might want to check to make sure you dont have functions of the same names in the two files. Also, make sure your functions are public and not private.
|
The issue is that, if the codefile for the function is not loaded first, then the function won't be defined when it's called. The main addon file should always be the LAST file in the list.
Of course, I'm assuming the order of the files in the TOC, but that wasn't explicitly stated. |
hmmm... I still can't make it work.
I have placed the lua files in the correct order in RiftAddon.toc Code:
RunOnStartup = { Code:
function create_object(objectname) then inside addon.lua I call this function as: Code:
create_object(testobject) Code:
attempt to call global 'create_object' (a nil value) |
If you'd like, PM me with the full code and I'll take a look and see what's going on. What you've posted should work; the only thing I can think of is that there is an error in the objectfactory.lua file that is stopping it from completely loading (thus the function is undefined).
|
Quote:
|
All times are GMT -6. The time now is 07:26 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2022 MMOUI