1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

using Timer() and cleanup

Discussion in 'Programming' started by MouldyCheese, Aug 17, 2003.

  1. MouldyCheese

    MouldyCheese New Member

    Joined:
    Aug 17, 2003
    Messages:
    11
    Likes Received:
    0
    Reading the relic source code I tried to make a simple regeneration mutator. Since I don't add anything to the inventory, is there any cleanup required? Also, the Timer function does not seem to be called every second, or at all.
    Code:
    Class HpRegen extends Mutator;
    
    function PostBeginPlay()
    {
      Super.PostBeginPlay();
      Settimer(1.0, true);
    }
    
    function Timer() 
    {
      if((Owner != None) && Owner.bIsPawn)
      {
        if(Pawn(Owner).Health < 100)
        {
          Pawn(Owner).Health = FMin(100, Pawn(Owner).Health +3);
        }
      }  
      Super.Timer();
    }
     
  2. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    Urm... The health addition code is correct, but the 'owner' part is completely out of it. (Not sure you can _be_ the 'owner' of a mutator, and even so, it would only be for the owner itself that your effect happens, not all the pawns in the world)

    Instead, what you want in your time is a quick search through the level's pawnlist, and running your health addition check on those pawns, without any 'owner' data.

    As for super.Timer(), if the superclass has a timer, and its not called on a per tick - second basis, overwriting like that will completely mash compatability: remember, each class gets one timer and one timer only.
     
  3. Mychaeel

    Mychaeel New Member

    Joined:
    Oct 3, 2001
    Messages:
    3,830
    Likes Received:
    0
    Mutators aren't owned by any player.

    No. Each actor (every instance, not every class) has a timer, and one timer only. For that matter, there's no timer used in class Mutator, so making one in a custom subclass isn't a problem.
     
  4. MouldyCheese

    MouldyCheese New Member

    Joined:
    Aug 17, 2003
    Messages:
    11
    Likes Received:
    0
    1) Is this what you mean; If I subclass a class that has a Timer() function, and my class will have one too, I should add Super.Timer() in the Timer() function?

    Incase anyone is interested, I got the regeneration code to work. I am in the middle of make a window to be able to edit 3 of the variables, but without the window, the mutator still works
    Code:
    Class HpRegen extends Mutator config(Monkey);
    
    var() globalconfig int HpMax;
    var() globalconfig int HpRegenAmount;
    var() globalconfig float HpRegenSpeed;
    
    function PostBeginPlay()
    {
      Super.PostBeginPlay();
      Settimer(HpRegenSpeed, true);
    }
    
    function Timer() 
    {
      //AllActors() takes too much time
      local Pawn myPawn;
    
      for(myPawn = Level.PawnList; myPawn != None; myPawn = myPawn.NextPawn)
      {
        if(myPawn.Health < HpMax)
        {
          myPawn.Health = FMin(HpMax, myPawn.Health+HpRegenAmount);
        }    
      }
      
      Super.Timer();
    }
    
    defaultproperties 
    {
      HpMax=100
      HpRegenAmount=3
      HpRegenSpeed=1.0
    }
    2) When I get the menu working, do you think I should add it to the WiKi with, or without the configure menu? (I know there already is a regen and config tutorial, but the regen is for UT2003, and the config doesn't tie it into a mutator)
     
  5. Mychaeel

    Mychaeel New Member

    Joined:
    Oct 3, 2001
    Messages:
    3,830
    Likes Received:
    0
    If any superclass of your own class uses a timer, you should neither call SetTimer nor implement Timer without knowing how exactly that class sets and uses the timer.

    GameInfo, for example, sets a timer with a one-second interval. In GameInfo subclasses you can overwrite the Timer function without a problem, but you shouldn't change the timer interval or stop the timer, and you absolutely should call Super.Timer lest important parts of the base code stop working (such as the game time or the part of the code that prevents chat spamming).
     
    Last edited: Aug 18, 2003

Share This Page