Random from a Seed

Get help using Construct 2

Post » Sun May 06, 2012 7:30 pm

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!
B
6
S
1
Posts: 37
Reputation: 774

Post » Sun May 06, 2012 9:02 pm

I think there is a plugin for this...
If not, it should be trivial to create one for yourself.

EDIT: here you are!
http://www.scirra.com/forum/plugin-randomplus_topic45261.htmlsqiddster2012-05-06 21:05:26
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon May 07, 2012 4:30 am

You are wonderful. Thank you! This is exactly what I was looking for!
B
6
S
1
Posts: 37
Reputation: 774

Post » Mon May 07, 2012 1:10 pm

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?Fistmaker2012-05-07 13:12:40
B
6
S
1
Posts: 37
Reputation: 774

Post » Mon May 07, 2012 3:15 pm

Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon May 07, 2012 3:39 pm

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?
B
6
S
1
Posts: 37
Reputation: 774

Post » Mon May 07, 2012 3:44 pm

You could try adding a space to the string, and increase the loop.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon May 07, 2012 7:12 pm

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.

SeedGen Capx

I'm very thankful for all of the help so far!
B
6
S
1
Posts: 37
Reputation: 774

Post » Mon May 07, 2012 7:36 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon May 07, 2012 8:46 pm

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.


Updated SeedGen.capx
B
6
S
1
Posts: 37
Reputation: 774

Next

Return to How do I....?

Who is online

Users browsing this forum: Braus and 16 guests