And since it uses Perlin noise, it also uses a seed, and seed is typically a number. Now, in games like BLOX / minecraft, you’re able to use text as a seed.
But if I use text as a seed in my terrain generator, I get an error. Is there any way I can use text as a seed in math.noise?
You could hash the string with md5 or something, but that’s probably overkill for what you want. Something really simple might be better. e.g. using string.byte:
local function StringToNumber(str)
local val = 0
for i = 1, str:len() do
val = val + str:byte(i)
end
return val
end
This is a terrible hashing function and will return the same thing for e.g. abc and bca, but it’s up to you if you care that much.
edit: here, on the other end of the spectrum, is an implementation of sha1 hashing in lua.
local max32 = math.pow(2, 32) - 1
local function HashCode(str)
local val = 0
local n = str:len()
for i = 1, n do
val = (val + str:byte(i) * math.pow(31, n - i)) % max32
end
return val
end