I want to make my code logicial.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Montasir Raihan

Hello guys, I’m making a top down survival shooter game. I configured my player, enemies, environments and all of them are working perfectly. But I want to make my code more logical. I mean, when the player reaches 25, 50, 75, 100, … kills, enemies will leave an item for the player. But the problem is, the enemies stop leaving items after a certain amount of kill. I don’t want that. So, Please help me or give me some advice.

Here is a short amount of code:

if player.kill == 25 or player.kill == 2*25:
   var ammo = ammunition.instance()
   world.add_child_below_node(path, ammo, true)
   ammo.position = body.position
body.queue_free()

Thank you for everything.

If you need to check more of my code, just ask me. Thank you.

Montasir Raihan | 2020-10-11 21:14

:bust_in_silhouette: Reply From: trey

So you want it to happen every 25 kills indefinitely? You will probably want to use a modulo operator and check if the result is 0, something like:
if player.kill % 25 == 0:

(edit: It’s called the “Remainder” operator in the Godot docs: GDScript reference — Godot Engine (stable) documentation in English )

Thanks man. You really solved my problem.

Montasir Raihan | 2020-10-11 22:30