0 votes

Everytime i call set_text() for a label via global script, it creates a new label at 0,0. Its really frustrating bcs i am new to Godot and to me it should work. Maybe one of you could help me ^^

in Engine by (18 points)

That should not happen. Can you post your code here? I don't have enough information to help you.

I discribed it poorly. I meant if i create a function in a global script that set the text and i call that function in annother script it creates a new label. But anyway here is the code

  extends Label

var score = 0


func _on_Timer_timeout() -> void:
    update_score(1)


func _on_Score_tree_entered() -> void:
    score = 0
    set_text(str(score))


func update_score(addvalue):
    score += addvalue
    set_text(str(score))

And if i call update_score(1) in annother script it wont work :(

I don't see anything wrong with that code. What's the global script like?

I set this script global
Bcs i want to change the settext from another script with the updatetext function

What's the other script that you call this function from?

extends KinematicBody2D


var direction = Vector2.LEFT


func _physics_process(delta: float) -> void:
    var velocity = direction
    velocity.x = direction.x * 150
    move_and_slide(velocity, Vector2.UP)
    var collision = move_and_collide(velocity * delta)
    if collision:
        collision.collider.move_and_collide(velocity * delta)

func _on_VisibilityNotifier2D_screen_exited() -> void:
    queue_free()

func _on_Jump_over_Checker_body_shape_entered(body_id: int, body: Node, body_shape: int, local_shape: int) -> void:
    if body.name == "Player":
        Score.update_score(1)

it is for a enemy i call via preload

Im Stuck and frustrated. I really really Need help
:(

Please log in or register to answer this question.

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.