random skin not working

Posted By: DLively

random skin not working - 04/20/15 23:04

Why doesn't this work?

Code:
random_seed(0);
value = integer(random(6));
my.skin += value;



I read what I could in the manual about this particular 'thing' and came up with nothing more than more confusion as to why this doesnt work........

Posted By: xbox

Re: random skin not working - 04/20/15 23:36

just off the top of my head,
I think
Code:
value = integer(random(6));


should be
Code:
var value = integer(random(6));


unless you already defined value earlier.
Posted By: Anonymous

Re: random skin not working - 04/20/15 23:37

try

Code:
random_seed(0);
value = integer(random(6)+1);
my.skin += value;

Posted By: DLively

Re: random skin not working - 04/20/15 23:56

Sorry I was a bit vague.

This action is used on 50+ models.
If I remove the random_seed(0); I get the same result each time (their skins will randomize, but always be the same random value [as the manual says it would]).

with the random_seed(0) all skins stay the same color.


@xbox: yes, its been defined wink

@malice: I tried your idea, but it didnt work smirk

I've done this before in the past and it worked fine. Strange how such a thing can happen..
Posted By: Anonymous

Re: random skin not working - 04/20/15 23:59

How about running random_seed(0) once in the main function fallowed by a wait and remove it here

Also debug_var the value of "value" lol

also debug skin to see if it chages or exceeds the number of skins
i=my.skin;
debug_var(i);

http://www.conitec.net/beta/macros.htm
Posted By: DLively

Re: random skin not working - 04/21/15 01:36

I put the random_seed in the main function... but I think the issue was because they were created and built with WED. I created some more models at runtime and their skins changed randomly..
Posted By: 3run

Re: random skin not working - 04/21/15 05:52

Just do this:
Code:
var rndSkin = 0;
rndSkin = integer(random(6));
my.skin = rndSkin + 1;

Also note that random(6) will create value between 0-5, so thats why I add 1 to the skin at th end. I'm not sure about using 'random_seed' over and over again, it works great for me if I add it once in the main function.

greets
Posted By: Superku

Re: random skin not working - 04/21/15 10:29

Random number generators always follow the same pattern, which means that when the last generated value is known you can always predict the next one, it's a machine after all.
Let's say you have such a function
int random_base(int seed);
which outputs a value between 0 and 65000, then your default random(var range) will be calculated somewhat as follows if I'm not mistaken:
Code:
var random(var range)
{
  var value;

  seed = random_base(seed);
  value = seed/65000.0*range;

  return value;
}


where seed is some global integer. You can change the seed number by calling random_seed(int num), and when you call the latter with num = 0, I assume the computer will take some additional information like the system's time (at game start) or something like that.
If you call random_seed() over and over you mess with the random(_base) pattern and in the worst case just get the same number over and over.
© 2024 lite-C Forums