Announcement

Collapse
No announcement yet.

Randomly toggle Boolean?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Randomly toggle Boolean?

    I've got Four Booleans:

    Code:
    bPerkAmmo;
    bPerkRegen;
    bPerkVelocity;
    bPerkBounce;


    Currently, I have the AI bot, on Possession of the Pawn, Rattling off a function (in this case, a function that teleports the pawn to a PathNode).

    Code:
    function PossessedBy(Controller C, bool bVehicleTransition)
    {
    	Super.PossessedBy(C, bVehicleTransition);
    
        //Check Wether the Pawn is controlled by an AI
    	if (C !=None)
    	{
    		`log ("Controller is A" @ C);
    
    		if (C.IsA('UTBot') )
    		{	
    			// Toggle a random perk boolean
    			Teleport(Self);
    
    		}
    	}
    	else
    		`log("No Controller?");
    
    
    
    }
    How can I go through the booleans, and randomly set one of the four to true when it Posesses the pawn?

    #2
    Code:
    simulated function randombool()
    {
    
            local int whichbool;
    
    				
    				  whichbool = rand(4);
                                      if (whichbool == 1)
                                              {
    
                                              }
    
    
                                      if (whichbool == 2 )
                                              {
    
                                              }
    
    
                                      if (whichbool == 3 )
    				          {
    
                                              }
    
                                      if (whichbool == 4 )
    				          {
    
                                              }
    }
    just call the function and set 1 bool to true in each of the four empty brackets.

    Comment


      #3
      sorry,i cant edit my posts.it should be

      Code:
      whichbool = rand(4)+1;

      Comment


        #4
        Worked perfectly, thankyou!

        Though, since I'm a stickler for best practices..

        Code:
        simulated function RandomPerk()
        {
        	local Controller C;
        	local int perknum;
        
        	C = Controller;
        
        	
        
        		perknum = rand(3);
        
        		if (perknum == 0)
        		{
        			bPerk0 = True;
        			`log("Bot" @ C @ "Has Selected Perk 0");
        		}
        
        				if (perknum == 1)
        		{
        			bPerk1 = True;
        			`log("Bot" @ C @ "Has Selected Perk 1");
        		}
        
        				if (perknum == 2)
        		{
        			bPerk2 = True;
        			`log("Bot" @ C @ "Has Selected Perk 2");
        		}
        
        				if (perknum == 3)
        		{
        			bPerk3 = True;
        			`log("Bot" @ C @ "Has Selected Perk 3");
        		}
        
        }
        Ints always start at 0, after all.

        Comment


          #5
          your welcome,and good to see your thinking.

          Comment

          Working...
          X