0 votes

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:
    $EnemyTimer.set_wait_time(0.6)
elif score >= 50 and score < 150:
    $EnemyTimer.set_wait_time(0.5)
elif score >= 150 and score < 200:
    $EnemyTimer.set_wait_time(0.4)
else:
    $EnemyTimer.set_wait_time(0.3)
print($EnemyTimer.wait_time)
func _on_ScoreTimer_timeout():
score +=1
$HUD.update_score(score)

func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
$HUD.update_score(score)
$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 (12 points)

1 Answer

+1 vote
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

or

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 (2,838 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.