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.

UE2 - UT2kX Programming delay in function execution

Discussion in 'Programming' started by gedassan, Jul 2, 2008.

  1. gedassan

    gedassan New Member

    Joined:
    Jun 25, 2008
    Messages:
    18
    Likes Received:
    0
    Hello,

    I am having difficulties trying to program a delay in execution.


    My objective

    1. Hide an object on Touch (actor Other)
    2. Wait
    3. Unhide the object

    My problem

    I tried two methods for doing it (SetTimer->Timer and Sleep, using states). I was able to achieve the desired functionality except that the waiting time is always 4 seconds or less. This is not long enough for me, I want a waiting time of 30 seconds or more (to simulate a respawning resource).

    Here is part of my code using SetTimer

    Code:
    
    function Touch (actor Other)
       {
           if (bHidden == false)
             {
                SetTimer(4.0,false);
                bHidden = true;
              }
        }
    
    function Timer ()
       {
           bHidden = false;
       }
    
    

    Here is part of my code using Sleep with a state

    Code:
    
    function Touch (actor Other)
       {
     	if (bHidden == false)
     	   {
        	      GotoState ('RespawnNectar');
     	   }
       }
    
    
    state RespawnNectar
       {
           function Hide ()
             {
                 bHidden = true;
              }
    
     function Unhide ()
           {
               bHidden = false;
           }
    
     Begin:
    
     Hide ();
     Sleep (4);
     Unhide ();
    
    }
    
    
    Results

    Both of these codes successfully hide an object on Touch, and unhide it again in 4 seconds. However, trying to increase the waiting time to anything between 5 seconds and 10 seconds only hides the object on Touch, and does not unhide it.

    Can you please help me understand what is going on :)?

    Cheers!
     
  2. Ninja_Theory

    Ninja_Theory New Member

    Joined:
    Jul 2, 2008
    Messages:
    4
    Likes Received:
    0
    I can't see any reason why that shouldn't work. Are you sure that something else isn't happening between 4 and 5 seconds later which changes the state of your actor causing it then not to unhide?
     
  3. gedassan

    gedassan New Member

    Joined:
    Jun 25, 2008
    Messages:
    18
    Likes Received:
    0
    Thank you for the idea. I have narrowed the time limit by testing. The object still unhides at 4.9 second sleep time, and does not unhide if the sleep time is equal to 5.0 seconds or more.

    I checked through all classes that could potentially do something at 4.9-5.0 seconds. The class I have problems with is called NectarPiece.


    1. The spawning class. It simply spawns the the NectarPiece at PostBeginPlay at a defined position (no loops, just spawn once).

    2. The classes that can touch the NectarPiece.

    One of these is Player. I test the map without starting the match (I have the "Press fire to start" blinking and I can fly). That way I never touch the NectarPiece during testing. That rules out the Player having to do with it.

    The other class is BeeScoutGameTest, which is derived from Pawn. BeeScoutGameTest only changes its own properties on touching the NectarPiece. So this class is also ruled out of being a problem.

    3. The NectarPiece class itself. I have tried basing it on FlakAmmoPickup, ASTurret_BallTurret, and now trying to use the classes based on Decoration.uc (found in C:\UT2004\Engine\Classes).

    Currently my code for the NectarPiece is also very simple. Maybe my problem is that I have only one state defined?

    Code:
    
    class NectarPiece extends DECO_SpaceFighter;
    
    function Touch (actor Other)
    {
     if (bHidden == false)
     {
      GotoState ('RespawnNectar');
     }
    }
    
    state RespawnNectar
    {
     function Hide ()
     {
      bHidden = true;
     }
     function Unhide ()
     {
      bHidden = false;
     }
    
     Begin:
     Hide ();
     Sleep (30.0);
     Unhide ();
    }
    
    defaultproperties
    {
         DrawScale=0.300000
         bHidden=false
         bUseCylinderCollision=true
         CollisionHeight=128
         CollisionRadius=44
         bBlockActors=false
         bStatic=false
    }
    
    
     
  4. Xaklse

    Xaklse Relics freak

    Joined:
    Sep 21, 2005
    Messages:
    44
    Likes Received:
    0
    Would be better to have two states: 'auto state Shown' and 'state Hidden'.

    After you call Unhide() once, you don't leave the state RespawnNectar.

    I suggest you to use Pickup class as a parent class, it may be easier for you as it has good subclasses for reference.

    I don't know what's up with the 5 seconds thing.
     
  5. gedassan

    gedassan New Member

    Joined:
    Jun 25, 2008
    Messages:
    18
    Likes Received:
    0
    I would like to thank you for the two states pointer. With the class I had based on Decoration.uc, the functionality was still limited by the magical 4.9 second number.

    Then I took the rest of your advice and went back to the Pickup class.

    Decided to try the simplest solution first. I simply changed the parent class to a subclass of UTAmmoPickup called FlakAmmoPickup. It worked!

    So here is the final working code where I used a 1 minute long "respawn cooldown".

    Code:
    class NectarPiece extends FlakAmmoPickup;
    
    function Touch (actor Other)
    {
     if (bHidden == false)
     {
      GotoState ('Hidden');
     }
    }
    
    auto state Shown
    {
      function Unhide ()
      {
       bHidden = false;
      }
    
      Begin:
    
      Unhide ();
    }
    
    
    state Hidden
    {
     function Hide ()
     {
      bHidden = true;
     }
    
     Begin:
    
     Hide ();
     Sleep (60.0);
     GotoState ('Shown');
    }
    
    
    defaultproperties
    {
         DrawScale=1.0
         bHidden=false
         bUseCylinderCollision=true
         CollisionHeight=128
         CollisionRadius=44
         bBlockActors=false
         bStatic=false
    }
    

    There are obviously some properties in the Decoration class that clash with the Sleep function, while the Pickup class does not have this limitation.

    I want to thank you both for your insights! Now I know more about states.
     

Share This Page