When I look at it again, it feels kinda inefficient if I plan to make numerous of waves. Any ideas?
First of all wut is the purpose of the arrays and why are the elements so weird and non-sensical?
Yeah, but I’m not sure what I’m missing here or what I need to do. I was grabbing my basic form of tables, got a nil value, tried using table.insert from documentation (it worked), and i started feeling weird about it.
That doesn’t answer my question…
In simple words: I don’t know.
Huh??? What is your end goal or what u tryna achieve?
If you had 2 tables with the exact same things inside, you can just clone one table.
local WaveList.Waves = {}
local t = {"1", 2, true}
table.insert(WaveList.Waves, t)
table.insert(WaveList.Waves, table.clone(t))
I plan to make a wave, then it spawns another way after the event triggers for it to happen. Like what you see in most wave-based games. I only needed help on what makes no sense here in the code and I cannot figure out which and where.
Thank you so much! This is what I’ve been forgetting.
Without getting into metatables and constructors, the next level up would be helper functions, and then to package those in a module…
-- ModuleScript
local module = {
waves = {}
AddWave = function(self, wave: table)
table.insert(self.waves, wave)
end,
GetWave = function(self, index: number)
return self.waves[index]
end,
}
return module
Something like that. I didn’t check this in studio, so probably broken code, but you get the idea. Add more helpers as you go, and compound them.
I’ll keep in mind of this, this actually helps getting some kind of idea. Thanks!
what if between the 3 or more tables are different?
I’d need a little more context than that, but if you had 3 tables and you wanted to add them to one big table while still keeping them in tables, then you could do this.
-- for reference, this is what I mean
WaveList.Waves = {
{1},
{2},
{3, "something"}
}
-- You should be able to create the index without using table.insert()
WaveList.Waves[1] = {1, true}
-- this is the same as
local t = {1, true}
table.insert(WaveList.Waves, t}
-- if you don't know the last index, then you can use this: [#table + 1]
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.