Why does this script not work?

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

extends Area2D

var in_area = true

func _on_Jumppad_body_entered(body: Node) → void:

func body_in_area():
while in_area == true:
if not Input.is_action_pressed(“ui_up”):
get_parent().get_node(“Player”).movement.y = -2000

func _on_Jumppad_body_exited(body: Node) → void:
in_area = false

We can’t see the picture. It appears to be a broken link

godot_dev_ | 2023-05-23 15:53

Just post the script itself (as formatted code) into the forum. That’ll avoid any issues with linking of an image and make the code easier to read.

Also, you’re going to need to provide some more details. What does “not work” mean? Are you getting an error? If so, what’s the error? Does it just not do what you want? In that case, what is it doing and what should it be doing?

Without at least some of the above, it’s very difficult to provide you with useful input.

jgodfrey | 2023-05-23 16:08

It is hard to read the code. Please format it using this post as a guide to post formatting

godot_dev_ | 2023-05-23 19:21

:bust_in_silhouette: Reply From: godot_dev_

Although the code is poorly formatted, my guess is your error is an infitnite loop caused by the while inarea == true: statement in your bodyinarea function. It appears at no point do you set inarea to false in the bodyinarea function, which means your code will hang. Your onJumppadbodyexited function appears to be the only place that would stop this inifite loop, but the function won’t get called since you will need the physics engine to finish a physics step to detect collisions, which won’t be possible with an infinite loop.