Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Random variables
Omenapuu Offline
Junior Member

Posts: 31
Threads: 8
Joined: Oct 2013
Reputation: 1
#1
Random variables

Hi everyone, and happy coding! I'm asking if anyone of you know how to use the RandInt code. I basically know the variables and so, but as I can't name the random int, how to I make an if-else statement about that. Heres an example what im talking about:
--------
if(GetLocalVarInt("sounds") == 1
{
PlayGuiSound("sumthing", 100);
}
----------------
Now I want to make that like it generates a random int, if its 1 it plays something, if 2 if plays something else, and so on. I just don't understand how Huh
(This post was last modified: 10-30-2013, 07:50 PM by Omenapuu.)
10-30-2013, 07:49 PM
Find
Omenapuu Offline
Junior Member

Posts: 31
Threads: 8
Joined: Oct 2013
Reputation: 1
#2
RE: Random variables

(10-30-2013, 08:21 PM)Robosprog Wrote:
PHP Code: (Select All)
if(RandInt(18) == 8){PlaySoundAtEntity("""scare_animal_squeal.snt""Player"0.60false);}
    else if(
RandInt(1,8) == 7){PlaySoundAtEntity("""scare_human_noices.snt""Player"0.60false);}
    else if(
RandInt(1,8) == 6){PlaySoundAtEntity("""scare_male_terrified.snt""Player"0.60false);}
    else if(
RandInt(1,8) == 5){PlaySoundAtEntity("""scare_wood_creak_mix.snt""Player"0.50false);}
    else if(
RandInt(1,8) == 4){PlaySoundAtEntity("""scare_ghost.snt""Player"0.60false);}
    else if(
RandInt(1,8) == 3){PlaySoundAtEntity("""scare_walk_ghost.snt""Player"0.40false);}
    else if(
RandInt(1,8) == 2){PlaySoundAtEntity("""scare_baby_cry.snt""Player"0.60false);}
    else if(
RandInt(1,8) == 1){PlaySoundAtEntity("""scare_steps_big.snt""Player"0.40false);} 

This is how I used them, if that gives an idea of how they work? Nothing else required.


Thanks! I totally forgot else if statements..
10-30-2013, 09:09 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#3
RE: Random variables

You can totally 'name' a Random number, simply by creating a variable, then assigning to it the random number that RandInt or RandFloat gives you

int myRandomInt = RandInt(1, 8);

if (myRandomInt > 4)
{
    // do stuff
}

This will also allow you to use the super awesome Switch.. Case statements, to make a bunch of if..else if.. else if.. etc look nice

int myRandomInt = RandInt(1, 3);

switch (myRandomInt)
{
    case 1: // do stuff if random number is 1
        break;
    case 2: // do stuff if random number is 2
        break;
    case 3: // do stuff if random number is 3
        break;
}

You can read about switch..case statements here, under the 'Conditions' heading
http://www.angelcode.com/angelscript/sdk...ments.html

(This post was last modified: 10-31-2013, 03:12 AM by Adrianis.)
10-31-2013, 03:12 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#4
RE: Random variables

http://www.frictionalgames.com/forum/thread-21190.html

Random Scares and shit.

"Veni, vidi, vici."
"I came, I saw, I conquered."
10-31-2013, 07:40 AM
Find




Users browsing this thread: 1 Guest(s)