Skip to content

Switch/Case

ZephiriusZephirius Member Posts: 411
edited December 2022 in Builders - Scripting
I'm really confused as to why when I use Random(3), it consistently only spits out option 1 - the mindflayer.
Would someone show me the correct structure to code a true Random(3). Thanks

Code so far -
location lSummon = GetLocation(GetWaypointByTag("SUMMON_LOC"));
        switch (Random(3))
        {
            case 0: DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_CREATURE, sFlayer, lSummon)); break;

            case 1: DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_CREATURE, sIronGolem, lSummon)); break;

            case 2: DelayCommand(3.0, CreateObjectVoid(OBJECT_TYPE_CREATURE, sSilverback, lSummon)) ;break;

        }

Comments

  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited December 2022
    First thing to check is that you are using each creatures resref and not its tag. You can find this by looking in the downloadable lexicon under Resources/Creatures and selecting the type of creature that you want (e.g. Constructs for Iron Golem). If that isn't the problem, double check you don't have any trailing spaces in the resref.

    FWIW If you are always going to have only 3 options try switch (d3()) instead of switch (Random(3)). You'll have to change your case statements as d3() returns 1, 2 or 3 though.

    TR
  • ZephiriusZephirius Member Posts: 411
    I had a duplicate resref. Too much copying and pasting - shite! Anyway I am using d3() now too and it is working... :smiley:
  • meaglynmeaglyn Member Posts: 146
    There's no reason to switch to d3(). What you had was fine.
  • WilliamDracoWilliamDraco Member Posts: 175
    In fact random(3) is slightly (very very very tiny bit slightly) better, because d3() just does random(3)+1
Sign In or Register to comment.