+2 votes

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.

in Engine by (137 points)
edited by

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

1 Answer

+3 votes
Best answer

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: https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html#operators )

by (52 points)
edited by

Thanks man. You really solved my problem.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.