1. What do you want to achieve?
Basically, I want to call mapChangeFunc()
in the intermissionFunc()
, but I also want to call the intermissionFunc()
in the mapChangeFunc()
.
2. What is the issue?
The problem is, one of the functions will not yet be defined when the other tries to calls it. For example:
local function mapChangeFunc()
print("Hello!")
wait(1)
intermissionFunc() -- The issue, as "intermissionFunc()" is not yet defined.
end
local function intermissionFunc()
print("Hello!")
wait(1)
mapChangeFunc()
end
3. What solutions have you tried so far?
So far, I have tried calling the intermissionFunc()
in another function after intermissionFunc()
is defined, and then calling that function in mapChangeFunc()
, but then that function hasn’t been yet defined for mapChangeFunc()
. For example:
local function mapChangeFunc()
print("Hello!")
wait(1)
test() -- The issue, as "test()" is not yet defined again.
end
local function intermissionFunc()
print("Hello!")
wait(1)
mapChangeFunc()
end
local function test()
intermissionFunc()
end
Thanks in advance!
Well one thing wrong with your example is that it’s recursive. In this case I would just get rid of “local”. Doing this would allow you to call the function in the script wherever you want as long as its been declared before you call the first function that calls everything else.
ex:
function hi()
bb()
end
function aa()
hi()
end
function bb()
print('bb')
end
aa() -- prints 'bb'
Thank you, that was it! lol ----
Use a table:
local RoundSystem = {}
function RoundSystem:Intermission()
print('Intermission')
self:ChangeMap()
end
function RoundSystem:ChangeMap()
print('change map')
self:Intermission()
end
I know this was already solved, but…
-- declare the name prematurely
local intermissionFunc
local function mapChangeFunc()
print("Hello!")
wait(1)
intermissionFunc()
end
-- and define it later on
function intermissionFunc()
print("Hello!")
wait(1)
mapChangeFunc()
end
This will lead to a call stack overflow however, so I would instead just run a main
function that calls both in a loop.
local function mapChangeFunc()
print("Hello!")
wait(1)
end
-- and define it later on
local function intermissionFunc()
print("Hello!")
wait(1)
end
local function main()
while true do
intermissionFunc()
mapChangeFunc()
end
end
-- when you want to start the game loop,
main()