Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random code question #222111
08/18/08 02:14
08/18/08 02:14
Joined: Aug 2008
Posts: 25
B
bluemax Offline OP
Newbie
bluemax  Offline OP
Newbie
B

Joined: Aug 2008
Posts: 25
my code is in a function to randomly play any 1 of 3 movies clips:

random_wlcm = integer(random(3));
if (random_wlcm == 0)
{
media_play("I_wlcm1.avi",NULL,100);
}
if (random_wlcm == 1)
{
media_play("I_wlcm2.avi",NULL,100);
}
if (random_wlcm == 2)
{
media_play("I_wlcm3.avi",NULL,100);
}

wait(-5);

The code works to some extent...
If I <tab> onto the console and change the random_welcm variable, it will play the correct file.

However; during gameplay, this code ALWAYS plays the same movie. I know its a 1 in 3 chance every time, but it ALWAYS plays the same one.

Any thoughts??

Re: random code question [Re: bluemax] #222113
08/18/08 02:19
08/18/08 02:19
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
check the manual :P

The var returned is fractional, and is always less than the upper limit. The random sequence starts always with the same numbers, unless 'randomized' at game start by random_seed().

see random() and random_seed()

Hope this helps! smile

Re: random code question [Re: MrGuest] #222114
08/18/08 02:44
08/18/08 02:44
Joined: Aug 2008
Posts: 25
B
bluemax Offline OP
Newbie
bluemax  Offline OP
Newbie
B

Joined: Aug 2008
Posts: 25
Thanks, I'll check it out. Just to be sure, doesn't integer return a "non-fraction"?

Re: random code question [Re: bluemax] #222117
08/18/08 03:52
08/18/08 03:52
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
u do something like this:

var rnd_num;


function x()
{
random_seed(0);
rnd_num = random(3);

if (integer(rnd_num) == 0)
{
...
}

if (integer(rnd_num) == 1)
{
...
}

if (integer(rnd_num) == 2)
{
...
}

....


wait(2);

}

----------------------------

Random function returns a float. random_seed(0) does a really random seed.


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: random code question [Re: delinkx] #222118
08/18/08 04:10
08/18/08 04:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia

random_wlcm = integer(random(3));

works fine for me, even without any "random_seed(0);"
though I would suggest having it at the start of main
somehere (and after save-game loads too)


or you could try this
Code:
switch(integer(random(3)))
{
   case 0:
      media_play("I_wlcm1.avi",NULL,100);
      break;
   case 1:
      media_play("I_wlcm2.avi",NULL,100);
      break;
   default:
      media_play("I_wlcm3.avi",NULL,100);
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: random code question [Re: EvilSOB] #222199
08/18/08 12:16
08/18/08 12:16
Joined: Aug 2008
Posts: 25
B
bluemax Offline OP
Newbie
bluemax  Offline OP
Newbie
B

Joined: Aug 2008
Posts: 25
thanks, the random_seed does exactly what i want.
i'm anxious to try the switch coding. thanks for the input.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1