Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hello again. I've cant get how to use the "random" function. I've got this code:

integers {
   s_code_1: integer {(random(1))};
   s_code_2: integer {(random(1))};
   s_code_3: integer {(random(1))};
}

And then this:

strings {
   s_code : dynamic_string {(
      s_code_1 + "" + s_code_2 + "" + s_code_3
   )} }

And after printing I get:

-2147483648-2147483648-2147483648

If I don't use "random", everything is ok:

integers {
   s_code_1: integer "1";
   s_code_2: integer "0";
   s_code_3: integer "1";
}

Prints as:

101

WAIDW?

(1 edit)

Hi, 

Sorry about this,

Try this:

 integers {
   s_code_1: dynamic_integer {(random(1))}
   s_code_2: dynamic_integer {(random(1))}
   s_code_3: dynamic_integer {(random(1))}
}

Yeah, that works, but it changes on every tick what is against the idea that it should be randomized only on game start.

Yes, dynamic integers are reevaluated every time you reference them.

What you want then is something like this:

integers {
   s_code_1;
   s_code_2;
   s_code_3;
} on_startup {
   : set_integer var = "s_code_1" {(random(1))}
   : set_integer var = "s_code_2" {(random(1))}
   : set_integer var = "s_code_3" {(random(1))}
}

Oh, so this is what the right solution looks like. Thank you.

Glad I could help :-)