• 3D
  • Not all arguments converted during string formatting in operator %

I'm making a space shooter game and I'm trying to add score to it. I added a ready signal to the bullet sprite that's connected to a label. The code of the bullet and label is below. Please help!

Label code:

extends Label


var score = 0


func _on_Bullet_ready():
	score += 100
	String(text)
	text == "Score: " %score

Bullet code:

extends KinematicBody

var velo = Vector3()
var KillParticles = load("res://haha space go shoot/KillBOOOOOm.tscn")
onready var main = get_tree().current_scene
onready var explodeSound = $EnemyExplode
onready var score = $ScoreLabel
onready var text = $ScoreLabel.text

func _physics_process(delta):
	move_and_slide(velo)

func _on_Area_body_entered(body):
	if body.is_in_group("Enemies"):
		var particles = KillParticles.instance()
		main.add_child(particles)
		particles.transform.origin = transform.origin
		body.queue_free()
		explodeSound.play()
		visible = false
		$Area/CollisionShape.disabled = true
		emit_signal("ready")

func _on_LightTimer_timeout():
	$OmniLight.visible = false

Hi,

I'm not sure what that code is suppose to do, but it looks pretty strange:

extends Label

var score = 0

func _on_Bullet_ready():
    score += 100
    String(text)
    text == "Score: " %score

score += 100 adds 100 to score, it seems ok, but String(text) is just casting text to string and probably it already is string and anyway you don't do anything with that cast result. Last line is also strange text == "Score: "%score that seems to be some comparison, not even assignment.

You probably need something like:

extends Label

var score = 0

func _on_Bullet_ready():
    score += 100
    text = "Score: %s" % score

You probably need something like:

extends Label

var score = 0

func _on_Bullet_ready():
    score += 100
    text = "Score: %s" % score

It seems to kind of work but the only problem is that the text overlaps each time the bullet hits the enemy.

Do you have more than one label node? If there is only a single label node, it shouldn't overlap with anything.

(I deleted my reply, since it doesn't explain the symptom.)

Maybe try giving the ScoreLabel a CanvasLayer as a parent?

@Plextora said: That's the only label node I have.

It looks like the label is part of the bullet. Are you instancing multiple bullets and thus multiple labels?

I fixed that problem, but now the label won't add to the score.

It's hard to solve that without seeing your project.

lemme just put it in my project .zip then

Yes, that is preferred. Our own hosting here is a fairly basic package since this forums hosting isn't sponsored or up keep covered by ads or anything.

I was able to download and run the project.

You're updating the label in _on_Bullet_bullet() in ScoreLabel.gd. But I couldn't find any call to that function, or any signal connected to it.

You're updating the label in _on_Bullet_bullet() in ScoreLabel.gd. But I couldn't find any call to that function, or any signal connected to it. I recall trying to create my own signal to see if the score works but it didn't. So I just tried connecting a ready signal to the ScoreLabel but it didn't work. All that happened was that at startup the score was automatically set to 100. And if you blasted an enemy nothing would happen. Below I've attached the google drive file for the Project.zip

https://drive.google.com/file/d/15U6P9giuvc_tzfgLxa1fZKdK5MI_eA5F/view?usp=sharing

Why are you using the "ready" signal, instead of your own signal?

I'm not clear on how the game works. Are the cubical objects the bullets? Are the red-and-pink moving objects the enemies that the bullets are supposed to hit to increase the score?

Why are you using the "ready" signal, instead of your own signal? Because I tried using my own signal but it didn't work. I'm fairly new to Godot and GDScript so I don't really know about signals.

I'm not clear on how the game works. Are the cubical objects the bullets? Are the red-and-pink moving objects the enemies that the bullets are supposed to hit to increase the score? Yup, that's how the game is supposed to work.

I added a print statement in the function _on_Area_body_entered just after emit_signal("ready"), and nothing is printed. Are you sure a bullet is hitting something?

Print statements or debugger breakpoints are very useful in diagnosing problems.

And I don't know if the "ready" signal is appropriate here.

I added a print statement in the function _on_Area_body_entered just after emit_signal("ready"), and nothing is printed. Are you sure a bullet is hitting something? I don't know what happened on your end, but for me, it prints the statement I gave when the bullet hit.

And I don't know if the "ready" signal is appropriate here.

I really don't know. maybe I'll dig more into the Godot wiki to see the mistake I'm making.