+1 vote

Hi, i'm trying to increase the frequency enemies spawns, based on the quantity of points (that is increasing constantly). First i tried using While but crashed my game, them i thought using _process(delta) but the if statement requires a value (if doesnt have one says "invalid operands 'Nil' and 'int' in operator '>='), so i set a value but since is in _process(delta) it keeps coming back to that value.

func _process(delta):
score = 0
if score >= 0 and score < 50:
elif score >= 50 and score < 150:
elif score >= 150 and score < 200:
func _on_ScoreTimer_timeout():
score +=1

func new_game():
score = 0
$HUD.show_message("Get Ready!")

i hope i explain my self properly, if you could help me it would be awesome.

Godot version 3.3.2
in Engine by (13 points)

1 Answer

+2 votes
func _process(delta):
    score = 0

Makes your score variable get reset to 0 on the start of every frame (happens more than 60 times a second), this is not what you want. Do that in the _ready() function or where you declare your score variable:

func _ready():
    score = 0


var score = 0

_ready() gets called one time shortly after the node enters the SceneTree which will make sure your score variable is initialized (non-Nil) before using it.

by (3,707 points)
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 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 webmaster@godotengine.org with your username.