![]() |
#1 |
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. Last edited by Dziriki : 10-07-11 at 10:41 AM. Reason: Typos. |
|
![]() |
![]() |
![]() |
#2 |
Place objectfactory.lua first in the RunAtStartup list. Thus:
Code:
RunAtStartup = { "objectfactory.lua", "addon.lua", }
__________________
Lua Code:
|
|
![]() |
![]() |
![]() |
#3 |
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.
|
|
![]() |
![]() |
![]() |
#4 |
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.
__________________
Lua Code:
|
|
![]() |
![]() |
![]() |
#5 |
hmmm... I still can't make it work.
I have placed the lua files in the correct order in RiftAddon.toc Code:
RunOnStartup = { "objectfactory.lua", "addon.lua", } Code:
function create_object(objectname) creating objects... creating obkects... end then inside addon.lua I call this function as: Code:
create_object(testobject) Code:
attempt to call global 'create_object' (a nil value) In addon/addon.lua Last edited by Dziriki : 10-08-11 at 02:34 AM. |
|
![]() |
![]() |
![]() |
#6 |
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).
__________________
Lua Code:
|
|
![]() |
![]() |
![]() |
#7 | ||
Quote:
__________________
Quote:
|
|||
![]() |
![]() |
![]() |
![]() | Riftui » Developer Discussions » Lua Help » Call a function in another codefile |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|