News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 2nd Jul 2008, 03:55 AM   #1
gedassan
Registered User
 
Join Date: Jun. 25th, 2008
Posts: 18
Programming delay in function execution

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!
gedassan is offline   Reply With Quote
Old 3rd Jul 2008, 09:54 AM   #2
Ninja_Theory
Registered User
 
Join Date: Jul. 2nd, 2008
Posts: 4
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?
Ninja_Theory is offline   Reply With Quote
Old 3rd Jul 2008, 11:03 AM   #3
gedassan
Registered User
 
Join Date: Jun. 25th, 2008
Posts: 18
Post

Quote:
Originally Posted by Ninja_Theory View Post
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?
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
}
gedassan is offline   Reply With Quote
Old 4th Jul 2008, 10:13 AM   #4
Xaklse
Relics freak
 
Xaklse's Avatar
 
Join Date: Sep. 21st, 2005
Location: Madrid, Spain
Posts: 44
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.
__________________
To rule them ALL!

Ashura: Dark Reign
Heaven of Relics / Relic Madness
Xaklse is offline   Reply With Quote
Old 4th Jul 2008, 01:57 PM   #5
gedassan
Registered User
 
Join Date: Jun. 25th, 2008
Posts: 18
Quote:
Originally Posted by Xaklse View Post
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.
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.
gedassan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer