I have a web of interconnected functions that all run eachother, but there is one function that is trying to run a function that isnt defined yet, and no amount of rearranging would fix it. Is there a way to do it in lua? I know that you can do it with classes in python.
One funky way to go about it is
local func1
local function func2()
func1()
end
func1 = function()
end
Make sure there is actually no arrangement that fixes the problem, I did actually find myself in a similar problem once where I had to do this.
It gives me an error saying attempt to call a nil value
, and it still highlights it as an error
Try defining it as an empty function first, then defining it as a new function with all the code inside.
In the end, I always prefer to just reorder my functions, rather than deal with this issue.
You can have it as a function which changes a random named value inside the script, when the new function is created, run it and make it wait until that value changes and do whatever you want
Here is a simple example of what I meant
local shouldFire = false
local function func1()
shouldFire = true
end
local function func2()
spawn(function()
repeat wait() until shouldFire
--do whatever you want, wont yeild the rest of the script aswell!
end)
end
func2()
func1()
It still just refers to the empty function, and not the actual one
I think Iām just going to use a remote event and fire it everytime i need it to run the function. Good suggestions though!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.