![]() |
|
|
#1 |
|
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 ();
}
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 |
|
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?
|
|
|
|
|
|
#3 | |
|
Registered User
Join Date: Jun. 25th, 2008
Posts: 18
|
Quote:
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 |
|
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 | |
|
Registered User
Join Date: Jun. 25th, 2008
Posts: 18
|
Quote:
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. |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|