Seed Numbers for Randomization

0 favourites
  • 5 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • 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.

  • 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

  • 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:

    -add tokenat(charString,floor(random(25)),",") to randString

    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:

    scirra.com/manual/126/system-expressions

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.. haha

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)