hi, i made a random map generation for my game, similar to that from the game SCP: Containment Breach.
the game is going to be round based and each round i would like to regenerate the map to keep things interesting. but i was wondering what would be the best way of doing this?
my first idea is to disable the map generation script and re-enable it through a different script each round. this seems like the easiest thing to do, but are there any drawbacks? will there be memory leaks or such? would i need to collect garbage?
or should i use an event and fire it when i want a new map to be generated?
maybe there’s another way i hadn’t thought of, if so i’d love to hear it!
thanks in advance!
1 Like
Disabling/enabling will give you bizarre behavior eventually.
I don’t think you need an event for this, unless you’re talking between the server and the client for some reason, but I assume that this is all being done on the server, so no need, right?
Just call the generation function inside your main game loop:
local function GenerateMap()
-- do something
return map -- some model or something
end
local function DoARound()
print("round start")
-- do something
wait(10)
print("round over")
end
-- main game loop
while true do
local map = GenerateMap()
DoARound()
map:Destroy() -- could be fancier like generate the map slowly and only swap them out once it's done generating
end
2 Likes
that’s interesting to know.
i opted for an event so that i could be more organized; i would have the map generation in one script and the thing that handles the round in another (since not every round will last the same if we assume one team could win before the timer runs out)
thanks though!
1 Like
Consider using ModuleScripts to organize your code without needing events to communicate. Event triggering is a little harder to debug than just calling a function 
2 Likes