Generating a seed that can be used to determine the properties of a location without parts?

I know that I’m going to seriously struggle to word this eloquently, given how the title makes negative sense, so bear with me a moment.

I’m currently working on the backend of a factory game (think Factorio/Satisfactory/Dyson Sphere Program kind of games) and part of it is as follows:

  • the locations of mineable ores are randomly generated in 32x32 stud chunks (equivalent to 16x16 in-game tiles)
  • the user will be able to tell what material is in a chunk, if any, by standing in it, which will come up on their HUD somewhere
  • if the user places a mining machine in a chunk, it will mine the material in that chunk, or Stone if the chunk has no material
  • these mining machines would over time drain the resources in that chunk, and after about 100k of that material has been mined mining machines in the area will no longer work and have to be picked up
  • I want to do this without having a part in every 32x32 chunk that determines the material because that’d be stupid
  • I doubt gameplay area will ever expand 2048 studs from origin in any direction so there’s the upper bounds of where ore chunks will be generated

I’m imagining that this would be doable with attaching each chunk to a set of co-ordinates in-world, with the scripts comparing the location of the Torso or a part of the mining machine with these co-ordinates to determine the chunk they’re in, but this brings up another issue - I want the game to remember where the randomly generated ores are in, and for multiple - so a string seed that determines ore position somehow seems like the best bet, which can be stored in the base folder and saved with the rest of the base, with some kind of conversion script to turn the seed into the location data that is required.

However, having the string have a character for every chunk feels like a non-option, as 4,096 characters seems rather excessive and quite truthfully I’m not even sure ROBLOX would be able to handle that.

So how would I go about implementing this, or is there a better way to do this that I can’t think of?

1 Like

Maybe random math.random or Random generation isn’t a good idea because it’s randomness is based on a sequence given one constant seed.

Given a seed you would have to maintain the order in which the chunks are generated in, so to ensure chunk 1000000 has always the same properties given a random seed, you would have to generate from chunks 1,2,3,… and so on. I do not believe you are willing the loop through that large number.

Perhaps math.noise is better because it will always generate the same output given the same input which is usually the seed with a factor of the position XYZ coordinates.

Yeah, I figured that math.random generation wouldn’t be fantastic in this situation given that, as you say, looping through all 4,096 potential chunks would take an age.

As for generating the seed, I was planning on having it so that, on load, if the seed is empty/all zeroes (indicating a blank seed), it’d generate it, and that the seed would be included in the save cycle so that it’s always the same, avoiding me having to generate it more than once, although I’d still have to parse coordinates with the seed fairly regularly.

Although that still somewhat begs the question of how such a thing would be implemented to be even remotely optimised.