I’m making a system that loads thousands of cities onto a globe of the Earth, kinda like in Rise of Nations.
I want to make the countries have a set color for cities, instead of just one city color over the entire globe, so I came up with a system that converts the letters to numbers
Code
local lettersConversionList = {
["a"] = 1,
["b"] = 2,
["c"] = 3,
["d"] = 4,
["e"] = 5,
["f"] = 6,
["g"] = 7,
["h"] = 8,
["i"] = 9,
["j"] = 10,
["k"] = 11,
["l"] = 12,
["m"] = 13,
["n"] = 14,
["o"] = 15,
["p"] = 16,
["q"] = 17,
["r"] = 18,
["s"] = 19,
["t"] = 20,
["u"] = 21,
["v"] = 22,
["w"] = 23,
["x"] = 24,
["y"] = 25,
["z"] = 26,
["'"] = 27,
[" "] = 28,
["("] = 29,
[")"] = 30,
["-"] = 31,
[","] = 32
}
local seed = ""
for _,letter in pairs(string.split(city[4],"")) do -- city[4] is a string of the country's name.
seed ..= lettersConversionList[string.lower(letter)]
end
seed = tonumber(seed) -- I put this line here because math.randomseed(tonumber(seed)) said there was an error when there wasn't, for some reason.
math.randomseed(seed)
local cityColorVal = Color3.fromHSV(math.random(0,360), math.random(100,255), math.random(100,255))
The issue is though, despite different countries giving different seeds, countries are appearing as the exact same RGB values. Am I doing the color generation wrong or something?
Maybe it’s too big of numbers for math.randomseed?
By the way, all countries that do have different colors have it working properly. Any cities that are the wrong color in a properly colored country are actually a small country inside of the larger country.
Ex:
These cities in Italy are different cause they’re not technically in Italy, but all actual Italian cities are colored properly.
I am getting no errors, and I did check, every seed is different as far as this checking system is concerned:
if not seeds[seed] then
seeds[seed] = city[4]
else
if city[4] ~= seeds[seed] then
print("seed repeated")
end
end