Public property changes in 2.0?
by Viktor Rumanuk · in Torque X 2D · 04/01/2008 (8:22 pm) · 3 replies
I had some code working in 1.5, basic _delayRemaining stuff for shooting. I had it set up so that the delay was a public property, the only way I could think of to reset the delay was to set it back to the value of the actual property
Thanks, Viktor
public Double /*Resetting to ShotDelay ->*/ShotDelay
{
get { return _delayRemaining; }
set { _delayRemaining = value; }
}This worked great in 1.5, but now when I set a breakpoint I see that _delayRemaining and ShotDelay are equal. Any way I can go about fixing this? Thanks, Viktor
#2
04/02/2008 (4:29 pm)
Thanks. I was basicly just trying to change the delay between each shot to a public property. It seemed like in 1.5 the name of the property exposed to TXB remained the same and only the private variable changed, but maybe it was only a coincidence. I've got it working now, it was easy after I realized, from your post, that I just needed another variable. Thanks again.
#3
Glad I could help either way!
04/02/2008 (7:25 pm)
NP. I was kind of wondering if that was your intent but with the variable names compared to what they are in the tutorial I wasn't sure. Glad I could help either way!
Torque Owner Matthew Shapiro
First let's get a handle on what you are trying to do. I am assuming from the tutorials and the name of the variables that you want ShotDelay to set the minimum time between shots and _delayRemaining as a variable to determine when it is ok to make the next shot. You will need at least two variables not one (not counting ShotDelay) to implement a delay in between shots. The main reason for properties used like this is so that TXB can see and interface with the properties.
The first variable you already have, but are using incorrectly (or if you are intending to use it that way you need another property to do what you want). If you use the tutorial as a reference and are using the variables how I assumed in the last paragraph, then you need a new Double protected variable called _totalDelay. This variable will store the minimum time between shots. Replace _delayRemaining with the _totalDelay variable (or whatever you call the new one).
Now in your ProcessTick function for the component, you need to check if _delayRemaining is less than zero. If it is allow the player to fire another projectile and reset _delayRemaining to equal _totalDelay, otherwise subtract _delayRemaining by the amount of time that has passed since the last tick (usually variable dt that is passed in).
Hope that made sense. The Blaster tutorial does exactly what I am pretty sure you are trying to do, so check it out!