Frictional Games Forum (read-only)
[SCRIPT] Random variables - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Random variables (/thread-23749.html)



Random variables - Omenapuu - 10-30-2013

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


RE: Random variables - Omenapuu - 10-30-2013

(10-30-2013, 08:21 PM)Robosprog Wrote:
PHP Code:
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..


RE: Random variables - Adrianis - 10-31-2013

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

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

Code:
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/docs/manual/doc_script_statements.html


RE: Random variables - PutraenusAlivius - 10-31-2013

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

Random Scares and shit.