Modme Forums
Menu:

Help create a random variable

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: xdferpc
I want to create a random variable choose between several things

things = array( "+=1", "+=2", "+=3");
level.everything = things[ randomInt( things.size ) ];
	if(level.everything == 1)
	{
	PrintLnBold("1");
	level.everything = 0;
	}
if(level.everything == 2)
	{
	PrintLnBold("2");
	level.everything = 0;
	}
else
        {
        PrintLnBold("3");
        level.everything = 0;
        }


ModmeBot:

Reply By: Crateer

xdferpc
I want to create a random variable choose between several things things = array( "+=1", "+=2", "+=3"); level.everything = things[ randomInt( things.size ) ]; if(level.everything == 1) { PrintLnBold("1"); level.everything = 0; } if(level.everything == 2) { PrintLnBold("2"); level.everything = 0; } else { PrintLnBold("3"); level.everything = 0; }


Well, "level.everything" will never be 1, 2, or 0 in your code. It will be one of the strings in your Array.

Also it's not clear to me what you want to achieve, better describe your Problem next time, else nobody will be able to help you out.

things = array( "+=1", "+=2", "+=3");
level.everything = things[ randomInt( things.size ) ];

if( level.everything == things[0] )
{
     PrintLnBold("1");
}
else if( level.everything == things[1] )
{
     PrintLnBold("2");
}
else
{
     PrintLnBold("3");
}

level.everything = 0;