How to change bool state

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Exile152

Someone help

onready var player = $“…/player”
var _player = false

func _ready():
pass

func _physics_process(delta):
if _player == true:
var dir = (player.global_position - global_position).normalized()
move_and_collide(dir * run_speed * delta)

func _on_Areadoperigo_body_entered(body):
if body.name == “player”:
_player = true

func _on_Areadoperigo_body_exited(body):
if body.name == “player”:
_player = false

func _on_Sim_area_entered(area):
vida = vida - dano
emit_signal(“tomardano”)

I’m not sure I know what you mean - could you please elaborate on your issue, and update the question. This will make it more likely for your question to be answered.

Snail0259 | 2021-08-16 03:10

Snail is totally right, please: if you have questions then tell us something about what’s (not) happening so that we can help you better. Questions without the essential details will very often never get answered.

That said, I can see from your code the issue that you’re probably having.

func _physics_process(delta):
if player == true:

var player is missing an underscore here.
If you need your if statement to be affected by the variable _player then it should be:

func _physics_process(delta):
if _player == true:

Is that correct?

Yuminous | 2021-08-16 03:24

I’m sorry for borrowing your time but i just fixed my problem thank you anyway!

Exile152 | 2021-08-16 18:39

That’s good to hear, however you should create an answer (also select it as the best answer) explaining what you did to solve this problem, so that other people can solve this problem too.

Snail0259 | 2021-08-16 22:23