Jump to content

Using timers help


Recommended Posts

So, I want to use timers for certain features.

 

Just about all I know is that the game measures time in milliseconds 1000 of which equals 1 whole second.

 

 

How do I use timers in code though, as in, how do I reference a timer that gets updated every frame or millisecond or whatever? I've been looking through Raven's code a bit but I'm not sure how timers are programmed to update so I'm therefore not sure how to make my own...

Link to comment

^Yeah the level.time thing seems to be used a lot.

 

Raven seems to be really simple about it, for example they use an if statement that says something like "if ( ps.forceRageRecoveryTime < level.time )" to check if an entity is still in the cooldown after Force Rage to have weaker saber attacks, but that seems overly simple... as that's literally all it says in most instances where level.time is used. Perhaps forceRageRecoveryTime does some of it's own calculations to figure when the entity first used Rage and when it ended?

 

How do I know what things are frame-by-frame operations, or how do I know just in general the interval at which a function is called or a piece of code is used besides just guessing? Is there some somewhat clear way to tell in C/C++? Or it's all purely studying the code? I feel like that sort of thing would be useful to have an understanding of. That's my main stumbling block right now, and also my game crashes on saber clashes, which maybe some simple error, but if I caused some sort of update/timing conflict somewhere I wouldn't know it yet. I was splitting parts of the saber combat code into two: one old, one that checks for a cvar to run a modified version, and I have the slight feeling I could've messed up something that all needs to run without conflict in a single frame or something like that without branching off into pieces...

Link to comment

I got it.

 

Here's what I found: for rageRecoveryTime or whatever it's called, the moment Dark Rage ends for someone that's used it, rageRecoveryTime is set to "level.time + 10000" or whatever the current time is +10 seconds. And then other parts of the code keep the weakness period going until level.time is greater than rageRecoveryTime.

 

Using this knowledge, I put some code in the function that is responsible for Force point regeneration, and that checks the timers in the same way as for Dark Rage.

 

And I resolved the crash ;)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...