Let’s say I have a character creator, and I created a character with these settings: { FaceType2, HairStyle4, BodyType1}. Now I want to be able to generate a code like “asdhkj”, and someone else can copy and paste that into their game and get the same character appearance.
Does anyone know if there is a defold/lua function or extension that can do that, or what keywords I should be looking up? All I can think of is encryption and char to ascii which isn’t quite right. Thanks!
You mean like a hash function?
I randomly find this
But it is not two way…
You could just give a number or id to each of your “traits” and then concat them…like 2 letters by trait.. and just store that in an encode and a decode static table.
How many of each category do you have? You could translate each FaceType, HairStyle, BodyType to a shorter string and concatenate them to get the code, and then do the same in reverse. Perhaps a single letter per type if you can get away with A-Z.
{ FaceType2, HairStyle4, BodyType1} would become BDA
I believe thinking about it as “random” is counter productive or potentially might trip you up.
It must be deterministic, or you cannot “reverse” the process and get the original data back.
I’d start with what @britzl suggested, where each “type” of data becomes one character.
If there is a lot of different types, the string will of course become longer.
If a short string is desired, I’d look into optimizing the process by 1) using bit fields / bit packing to create a 32 or 64 bit integer and 2) convert the integer to a hexadecimal string like “ABCD1234”.