Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SDGN16 |
I’ve been trying to make a running game with simple shapes for a few days. I’ve done most of it, but the score is not updated when the character touches the cubes spawn on the screen. I am trying to increment the score variable in the main_script.gd file from the spawn_cube_script.gd file and print it on the screen.
link of my project:
Use excerpts of code, rather than linking your entire project. Edit it into your question so people can just look at the relevant bits rather than having to dig through a whole project.
psear | 2021-02-06 15:50
I am sorry I could not fully explain my problem. My English is not good. The error in the project sounds like the link between the two scripts.
main_script.gd
extends Spatial var obj = load("res://scenes/cube.tscn") onready var label = $score_label var score = 0 func increase_score(): global.score += 1 label.text = "SCORE " + str(global.score)#ERROR SECTION!!!
spawn_cube_script.gd
extends StaticBody var v = Vector3(0,1,-40) var node = load("res://scripts/main_script.gd").new() func _process(_delta): if v.z > 5: self.queue_free() else: v.z += 0.1 self.set_translation(v) func _on_Area_body_entered(_body): node.increase_score()
errors:
debugger tab:
Invalid set index ‘text’ (on base: ‘Nil’) with value of type ‘String’.
0 - res://scripts/main_script.gd:8 - at function: increase_score
1 - res://scripts/spawn_cube_script.gd:12 - at function: _on_Area_body_entered
Errors tab:
get_node: Node not found: score_label.
SDGN16 | 2021-02-06 16:39