I am trying to assign a function to a lobby, however I keep getting ‘Unknown Symbol’ when trying to check for a certain lobby or assign a specific function to a lobby.
So basically, I have a dictionary handling all of the lobby info of each lobby, however when assigning a countdown function, I am left with ‘Unknown symbol’ from the dictionary, and ‘Duplicate definition’ from the function, how do I fix it?
For example,
local Lobbies = {
['Lobby1'] = {
['HasStarted'] = false,
['Function'] = Lobby1(), -- underlined with 'unknown symbol'
['MaxPlayers'] = 2,
['Players'] = {}
},
['Lobby2'] = {
['HasStarted'] = false,
['Function'] = Lobby2(),
['MaxPlayers'] = 3,
['Players'] = {}
},
['Lobby3'] = {
['HasStarted'] = false,
['Function'] = Lobby3(),
['MaxPlayers'] = 5,
['Players'] = {}
},
['Lobby4'] = {
['HasStarted'] = false,
['Function'] = Lobby4(),
['MaxPlayers'] = 8,
['Players'] = {}
}
}
function Lobby1--[[underlined with 'duplicate definition]]()
for i = 30, 0, -1 do
for i2,v2 in pairs(Lobbies['Lobby1']['Players']) do
end
end
end
-- self is automatically passed when using ':' instead of '.'
Lobbies['Lobby1']:Function()
You could look more into the self parameter in Lua if you don’t know about it.
If you wanted these functions to be called immediately then you could just call those under the table, as it seems you’re trying to call Lobby1() in the table.
Nah, I just want it there as a variable to be conveniently called whenever, instead of doing a huge if statement.
I don’t think I can do it how you did it, can I? I am wrapping that function in a coroutine as the function is a timer, and multiple timers can’t run at once in a single script w/o coroutines.
Also, does self just refer to the same script, kind of like Me in VB?
I dont have experience in VB, self is just a reference to the table the function is in. So self in our case is the Lobbies['Lobby1'].
If you’re looking for it to be a variable to be called at any time then yes, this is the solution you want. If you’re wrapping it in a coroutine, then just pass in the table since self is that table. coroutine.wrap(Lobbies.Lobby1.Function)(Lobbies.Lobby1)
local John = {
Name = 'John',
Age = 23,
Hello = function(self)
print('My name is ' .. self.Name .. ' and I am ' .. self.Age .. ' years old!')
end
}
coroutine.wrap(John.Hello)(John); -- Prints out 'My name is John and I am 23 years old!'
-- This is equivalent to: John:Hello() or John.Hello(John)