Seed Numbers for Randomization

Get help using Construct 2

» Thu Jan 30, 2014 2:22 pm

Let's say I want to program the option to seed my game so that friends can share randomized levels and features.

I grant myself a 25-digit "number", digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

so a number could look like this: z5a83nd83jsw201n4j5b692001

How do I program a function to look at that digit by digit and say: the first digit is z, therefore level 1 will use this tile... the second digit is 5 so the first level will also have this monster...

What would be the best way to get such a function working? Sorry to get so abstract. It's just an idea, but I'm not sure how to go about programming the game to recognize these numbers.
B
12
S
3
G
1
Posts: 172
Reputation: 1,611

» Thu Jan 30, 2014 3:13 pm

You can use this plugin by rexrainbow https://dl.dropboxusercontent.com/u/5779181/C2Repo/rex_randomgen.html its like the default random but allows for seeds

Then every time you make something random, it will do it based on the seed, so a "randomgen.random" will always return the same number if you're using the same seed.

If you do "set level tile to int(randomgen.random*10)" it will give you a number from 0 to 9, the same every time if you use the same seed
B
87
S
22
G
15
Posts: 1,041
Reputation: 15,353

» Thu Jan 30, 2014 3:13 pm

I would do it as such:

variable charString="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
variable randString=""

Condition:
-On start of layout
-Repeat 25 times (the length of the string to generate)
Action:

To get the char of a certain index in the randString, use expression mid(randString, 0, 1), this will get the 1st char of the randString.

Reference to using tokenat,mid,random:
https://www.scirra.com/manual/126/system-expressions

B
17
S
8
G
4
Posts: 93
Reputation: 3,190

» Thu Jan 30, 2014 3:18 pm

If the string is always 25 characters long, you could easily send the numbers into an array with:

left(text, count)

Just repeat it 25 times with count 1 while deleting a number from the left side of the text.

From the array you could set up the actions to perform when a value (x) is a certain number/letter.

Come to think of it, you wouldn't even need an array for it.. hahaLittleStain2014-01-30 15:21:32
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

» Fri Jan 31, 2014 12:17 am

Thank you everyone, this is very helpful. c4sp3r89, that looks like exactly what I was trying to ask for. I'm not 100% sure how to decipher some of the latter parts but I think I'll figure it out eventually.

EDIT: No wait, I do get it! Awesome. That was easier than I thought.teacherpeter2014-01-31 00:17:54
B
12
S
3
G
1
Posts: 172
Reputation: 1,611