Script does thing before thing

Godot Version

4.3

Question

my script executes a step before another one
it’s me ,again, so i have an issue, my script checks if there are bodies before i move the bodies, here’s part of it :

func _physics_process(delta):
	if Input.is_action_just_pressed("roll"):
		inspect()
		$CharacterBody2D.position.x -=40
		$CharacterBody2D2.position.x -=40
func inspect():
	if $Area2D.has_overlapping_bodies():
		one = true
		much += 1

how do i change this?

what is the order of operations you expect vs what really happens?

What are you expecting the order too be

it should check if there are bodies AFTER it moves , not before it moves

Would this work then? Make sure to use proper nouns, it’s hard to tell which “it” you are referring to (and "thing"s)

func _physics_process(delta):
	if Input.is_action_just_pressed("roll"):
		$CharacterBody2D.position.x -=40
		$CharacterBody2D2.position.x -=40
		inspect()
1 Like

nope , still does the operators in the same order

Let me lay out the operations as you have it in this example and you can help clarify which operations need moving around.

Given this:

func _physics_process(delta):
	if Input.is_action_just_pressed("roll"): # 1
		inspect()
		$CharacterBody2D.position.x -=40  # 3
		$CharacterBody2D2.position.x -=40 # 4
func inspect():
	if $Area2D.has_overlapping_bodies(): # 2
		one = true # 2a
		much += 1  # 2b

Every frame the game will check in this order:

  1. if action “roll” pressed; else do nothing
  2. if $Area2D is overlapping bodies
    2a. set one to true
    2b. add to much
  3. Move $CharacterBody2D to the left
  4. Move $CharacterBody2D2 to the left