I was looking at the system expressions in the Manual, and I do see a few options for randomization. I was wondering if it was possible to generate a random number by a given variable. I've done something similar in python, and it saved me alot of time and memory.
I am currently using an array with a random number in each point to generate terrain for my map. Now, because I cannot save a layout, I would need to save that array via web storage, or as a JSON string to be loaded later. I'm still playing with those options, but it's still a learning process.
If I could generate the same random terrain via a Seeded Randomization, I would not need to store the terrain array, just the simple random seed in web storage. This would be WAY smaller, and save me alot of time.
So, is there a way to create a random from a seed? Anyone know of a plugin? Or is it possible to request this feature in a future release? Any help would be wonderful!
I think there is a plugin for this...
If not, it should be trivial to create one for yourself.
EDIT: here you are!
You are wonderful. Thank you! This is exactly what I was looking for!
After some testing, I have another quick question. If I try to set the seed to a string of text, the result is always the same, regardless of the text the seed is set to. I tried using numbers and it works correctly.
So, my next question would be, how can I go about changing the string from text to numbers? Is using the replace(src,find,rep) function in the text input the easiest way to do this? This seems to be the only solution I have come across so far. Thanks again for any input!
Ninja Edit: If replace is the best way, how can I go about iterating over the string?
This is working great with one exception, spaces. If a space is typed into the text box, the preview and construct2 crash. Good thing I saved! Any ideas on how to fix?
You could try adding a space to the string, and increase the loop.
Develop games in your browser. Powerful, performant & highly capable.
Great! That worked. Now I dont have anymore crashes, but I think I messed up trying to use what you showed me. When I generate a new seed, I'm getting a result with letters with the numbers appended. Example: abba is given, and result is abba1221. I just want the 1221 when it's finished. Here is the capx.
I'm very thankful for all of the help so far!
You don't want to concatenate the text from the edit box.
Just add a text object and set its text to text.text&loopindex, or use a variable, etc. Just be sure to use int() if you plan to use that string as a number.
Ok. I tried to take the text from my input box and transfer it to another plain text box but I'm still getting the same output. I'm not sure what I am doing wrong here. Here is the edited capx.
Something's wrong with your cap there.
From the previous cap I can tell you do not add anything to the "trans" text object other than trans.text&loopindex-1.
Also you do not need to swap strings around. The edit box has an option to get its text. Use that instead.
One more thing, you need to make sure that the trans text has no text before you do the loop. IE backspace on its text in its preferences in the layout editor.
While I'm not quite 100% on why this works, I finally do have it working. I think I had too much stuff jumbled around on my event sheet. An extra Include later and it's all working now. I think I was pointing at the wrong text box before, but I went over it again with your suggestions and all is well! Thanks again for taking the time to give me a hand!