Hi @wchc,
I’ve added some print() functions like this:
func change_fire_rate(value, shipcolor):
#fire_rate_timer.wait_time /= (1 + value)
print("Value at change_fire_rate(): ", value)
fire_rate_stat.fire_rate_mult += value
print("fire_rate_mult at change_fire_rate(): ", fire_rate_stat.fire_rate_mult)
fire_rate_timer.wait_time = base_wait_time * fire_rate_stat.fire_rate_mult
print("base_wait_time at change_fire_rate(): ", base_wait_time)
print("Weapon fire_rate_timer at change_fire_rate(): ", fire_rate_timer.wait_time, " on ", shipcolor, " side")
There’s another print() print("Fire rate value: ", value)
from an earlier signal, just to check if value
changes between signals being called. There’s also a print() function for each weapon under ready() that tells me their initial base_wait_times:
func _ready():
muzzle_flash.visible = false
var fireraterefresh = 1 / fire_rate_stat.fire_rate_mult
fire_rate_timer.set_wait_time(fire_rate_timer.wait_time * fireraterefresh)
#base_wait_time = fire_rate_timer.wait_time
print("BASE WAIT TIME: ", base_wait_time)
They gave me this output, which is correct for what I’m going for:
BASE WAIT TIME: 0.5
BASE WAIT TIME: 0.2
However, the first time I activated the upgrade (initially equipping it), the print() functions under change_fire_rate
gave me this output (this weapon should have a base_wait_time of 0.5):
Fire rate value: 0.5
Value at change_fire_rate(): 0.5
fire_rate_mult at change_fire_rate(): 1.5
base_wait_time at change_fire_rate(): 0.5
Weapon fire_rate_timer at change_fire_rate(): 0.75 on 0 side
This is where the initial weirdness seems to come from. It’s using the correct base_wait_time
, but I think the line fire_rate_timer.wait_time = base_wait_time * fire_rate_stat.fire_rate_mult
(0.5 * 1.5) is turning wait.time
into 0.75. I’m not sure if making value
negative instead of positive would help (and vice-versa for when the upgrade is de-activated)? Let me know what you think.
When I switched to a different weapon with a base_wait_time of 0.2 (un-equipping and deactivating the upgrade), I got this output:
Fire rate value: -0.5
Value at change_fire_rate(): -0.5
fire_rate_mult at change_fire_rate(): 1
base_wait_time at change_fire_rate(): 0.5
Weapon fire_rate_timer at change_fire_rate(): 0.5 on 1 side
Again, the line fire_rate_timer.wait_time = base_wait_time * fire_rate_stat.fire_rate_mult
(1 * 0.5) seems to be turning wait_time
into 0.5.
When I switched back to the first weapon (re-activating it), I got this:
Fire rate value: 0.5
Value at change_fire_rate(): 0.5
fire_rate_mult at change_fire_rate(): 1.5
base_wait_time at change_fire_rate(): 0.2
Weapon fire_rate_timer at change_fire_rate(): 0.3 on 0 side
Strangely, the base_wait_time
now seems to match that of the second weapon. 1.5 x 0.2 = 0.3, hence the new wait_time
. I’m not sure why base_wait_time
would change like this. The actual firing speed of the weapon on-screen also changes after this; to my eyes, it looks like it’s firing a bullet every 0.5 seconds, rather than every 0.3 seconds as the code might suggest.
I have a feeling that all the print()
functions after the upgrade is initially activated are called right before the weapon actually switches, which means they output the variables for the previous weapon… This doesn’t explain the strange behaviour, though, so I might be wrong.
Switching to the second weapon again, I got this:
Fire rate value: -0.5
Value at change_fire_rate(): -0.5
fire_rate_mult at change_fire_rate(): 1
base_wait_time at change_fire_rate(): 0.5
Weapon fire_rate_timer at change_fire_rate(): 0.5 on 1 side
What’s really weird is that on-screen, this time the weapon looks like it fires a bullet every 0.3 seconds, rather than every 0.5 seconds as the fire_rate_timer
would have us believe. This makes me more suspicious that it’s outputting the variables for the previous weapon, but they’re still acting strangely. It might need to go back and check when exactly the switch_weapon()
signal is called elsewhere in the code…
Another theory is that there might be another function somewhere else that changes the wait_time
just after change_fire_rate
is called. I don’t think this is the case because change_fire_rate()
doesn’t call any global signals that would change the , but I’ll double-check this if it becomes necessary to do so.
The wait_time
for re-activating the first weapon seemed to stabilise after this, because switching back to it a couple more times still gave me 0.3:
Fire rate value: 0.5
Value at change_fire_rate(): 0.5
fire_rate_mult at change_fire_rate(): 1.5
base_wait_time at change_fire_rate(): 0.2
Weapon fire_rate_timer at change_fire_rate(): 0.3 on 0 side
The values from switching back to the second weapon also stabilised in the same way.
Very strange behaviour and output going on here; let me know what you think!