Skip to content

Get Random Delay

Can different actions be assigned to each number between the minimum and maximum numbers?
float GetRandomDelay(float fMinimumTime = 0.4,float fMaximumTime = 1.1);


Comments

  • MelkiorMelkior Member Posts: 204
    edited October 2023
    Not directly, and there are easier ways to get what you want, such as with a custom function.
    int GetRandomRange(int iMinVal=1, int iMaxVal=10)
    {
      int iDiff=iMaxVal-iMinVal;
      if(iDiff<1) return 0;  
      return iMinVal+(Random(iDiff));
    }
    
    I'm not sure this will do exactly what you want, but it'll be a good starting point at least.
    Then you use the value output by this function in a "switch-case" command in order to select a different action for each number.
    .....
    int iVal=GetRandomRange(2,5);
    switch (iVal)
    {
    case 2: //something to do
    break;
    case 3: //something else to do
    break;
    case 4: //still another thing to do
    break;
    case 5: //yet another thing to do
    break;
    }
    .....
    
    (The one thing I'm not sure about in the function is whether or not the math allows every number from iMinVal to iMaxVal to appear, or if one of the extremes is excluded from the range)
  • TerrorbleTerrorble Member Posts: 179
    What kind of actions?

    GetRandomDelay() returns a single float value between those numbers and you won't know what it is, other than it's in that range.
    In a cutscene where I have several NPCs speaking to each other, I use DelayCommand() to time their speaking parts, movements, and facing - all using DelayCommand(float,AssignCommand()). You could easily throw in DelayCommand(GetRandomDelay(),AssignCommand()).

    Hopefully that helps.
  • TheTinmanTheTinman Member Posts: 74
    Thanks for the replies. I got it sorted now.
Sign In or Register to comment.