I have encountered a problem with my poison logic

so i have a bit of a problem with my poison damage logic, the problem right now is that after a few ticks, the game just crashes

func applypoison(target, damage):
	damage = target.maxhealth / 100
	for i in range(99999999999999):
		if is_instance_valid(target):
			poisontimer.start()
		await poisontimer.timeout
		if is_instance_valid(target):
			
			target.health -= damage
			Damagenumbers.displaynumber(damage,target.global_position,false)
			if is_instance_valid(target):
				poisontimer.start()

any idea why this happens?

also to clarify i am familiar with most of godot’s stuff like signals, debuggers, globals, and other stuff

How does the game crash? Or do you mean a debugger/stack trace appears in the editor? If so what does your error message say?

If you have a poison timer then you should use it’s timeout signal to handle this logic, instead of a wildly large for loop.

it kinda just stops : /

sorry that i am still a beginner so i dunno how or why stuff happen a lot of the time

Hey I could be wrong but I’m pretty sure this is way beyond the maximum value for an int32, you should either find a different solution to this problem as pointed out, or first try a much, much smaller value and see if the game still crashes.

Basically, do not go above 2147483647

Why is an int32 relevant here? GDScript uses int64

Ah, did not know that, sorry. Still I feel like this solution is not exactly ideal.

If your game halts and freezes that may be the editor pausing it and showing you a stack trace, these help you to debug the game, it will point out a line where an error occurred with a message about the error.

You are using the timeout signal from your poisontimer, but you are using it for await instead of connecting to it. You can probably connect this signal in the editor, by selecting the Timer node, go to the “Signals” tab, and connecting to timeout.

the thing is it didnt show any errors in the output which i found weird cuz i got into. a habit of game freeze = error but that doesnt seem to apply here which confused me

so a bit like this?

func applypoison(target, damage):
	damage = target.maxhealth / 100
	poisontar = target
	damage = poisondmg
	for i in range(2147483647):
		if is_instance_valid(target):
			poisontimer.start()
	



func _on_poisontimer_timeout() -> void:
	if is_instance_valid(poisontar):
		poisontar.health -= poisondmg
		Damagenumbers.displaynumber(poisondmg,poisontar.global_position,false)
		if is_instance_valid(poisontar):
			poisontimer.start()

It may be in your debugger panel, not the output panel.

If you have other massive loops they could halt the program too, without the await keyword this loop would certainly freeze the game up while it processes 9 trillion iterations when it at most needs to process 100.

cool ill try it

Almost, but you still have that massive for loop, in fact this one may be worse by re-starting the timer 2 trillion times when it only needs to start the timer once, allow the timer to loop by disabling “One Shot” if you have it enabled.

after further observing, i found that the problem is that after a bit of the poison effect applying on multiple enemies, it pauses the game.

What does your code look like now? And if there is an error message what it is?

everyone! i have realised i have stupid syndrome. the reason of this bug was that i was applying fire and poison at the same time, which confused the global of the status effect data or something i dunno