Print str function doesn't work

Godot Version

Godot 4.0

Question

I defined a function: func jump(): print(str("start jumping ", velocity.y )) velocity.y -= 0.1 #jump_vel print(str("ending jumping ", velocity.y ))

the problem is that the second print never get to be executed…mmm, any idea why does this happen?? after first print I just tryed to indicate:
velocity.y -=jump_force
with ump_force having this value: 0.1
But nothing changed

Dude, you have to give a bit more context in order for us to help you. :smiley:

your function not running could have a multitude of causes. The line is not reached, but we can’t magically know why it isn’t reached.

You are right. I am going to attach all my script then:

extends CharacterBody2D
###################
@export var speed = 50.0
@export var jump_vel =2000.0
@export var gravity_mul=1.0
@export var jump_count = 2
@export var jump_height:float
@export var jump_time_to_peak:float
@export var jump_time_to_descent:float
##################
#@onready var jump_heigth_timer = $JumpHigthTimer
#@onready var jump_buffer_timer = $BufferTimer
@onready var jump_velocity:float = ((2.0*jump_height)/jump_time_to_peak)*-1.0
@onready var jump_gravity:float = ((-2.0*jump_height)/(jump_time_to_peak*jump_time_to_peak))*-1.0
@onready var fall_gravity:float = ((-2.0*jump_height)/(jump_time_to_descent*jump_time_to_descent))*-1.0
var move_speed = 40.0
@onready var is_jumping = false

var last_direction=Vector2(1,0)

var gravity= ProjectSettings.get_setting("physics/2d/default_gravity")
######################
	
func _physics_process(delta):
	######var direction= Input.get_vector("go_left","go_right","go_up","go_down")
	var direction = Vector2(
	Input.get_axis("go_left", "go_right"), # The x component of the Vector2 is the value returned to manage horizontal movement
	0.0 # The y component of the Vector2 is the value returned to manage vertical movement : NO MOVING
	)
	velocity.x = direction.x*speed
	######### velocity=direction*move_speed #<------CHECK THIS
	
	if not is_on_floor():
		print('falling down')
		velocity.y += gravity * delta
	else:
		print('ON FLOOR. sei atterato')
	##FORCE TO SET POSITION INSTEAD THA UODATE VELOCITY VECTOR
	
	
	velocity.y += get_gravity_val()*delta
	
	
	velocity.y +=get_gravity_val()*delta
	if Input.is_action_just_pressed("Jump") and is_on_floor():
		player_jump(delta,0.1)
		#jump()
	
		
	move_and_slide()	
	#var direction= Input.get_vector("go_down","go_up","go_right","go_left")
	
	#move_and_slide()
	

	#move_and_collide(velocity * delta)
	if direction.length() > 0:
		last_direction = direction
		walk_anim(direction)
	else:
		idle_anim(last_direction)
	move_and_slide()

#jump function
func jump():
	print(str("start jumping ", velocity.y ))
	velocity.y -= 0.1 #jump_vel
	print(str("ending jumping ", velocity.y ))
	
	
	

func player_jump(_delta,jump_force):
	#jump_heigth_timer.start()
	print(str("starting height ", velocity.y ))
	velocity.y -=jump_force
	print(str("ending height ", velocity.y ))
	
func get_gravity_val() -> float:
	return jump_gravity if velocity.y < 0.0 else fall_gravity
	
func  walk_anim(direction):
	if direction.x > 0:
		$AnimatedSprite2D.play("walk_rigth")
	elif direction.x < 0:
		$AnimatedSprite2D.play("walk_left")
	elif direction.y > 0:
		$AnimatedSprite2D.play("walk_down")
	elif direction.y < 0:
		$AnimatedSprite2D.play("walk_up")

func idle_anim(direction):
	if direction.x > 0:
		$AnimatedSprite2D.play("idle_rigth")
	elif direction.x < 0:
		$AnimatedSprite2D.play("idle_left")
	elif direction.y > 0:
		$AnimatedSprite2D.play("idle_down")
	elif direction.y < 0:
		$AnimatedSprite2D.play("idle_up")

can you post the console output of this file?

Doesn’t seem like you ever call jump. You might see “ending height” then the velocity.y

Small note: you do not need the str function, you can print with multiple arguments

print("ending height ", velocity.y)
1 Like

the outup in concole is just:
starting height 0.88888889551163

yeah that was my guess, you don’t call jump() at all because it’s commented out.

In your original question you said it was about function ‘jump’. But “starting height” appears to be about ‘player_jump’.

Which function is not printing correctly?

yeah, it was just a typo; even after i uncomment the jump() call, the result is the same… It just show in the console:

start jumping 0.88888889551163

Does the game continue? Do you get an error message? I can only think you’ve accidentally set a breakpoint by a red-dot in the line numbers gutter.

Yes the game continue without any concerns…I didnt set any breakpoint…

Can you try this and tell us the console output:

func jump():
	print("This is the jump function.")
	print("Starting velocity.y is ", velocity.y)
	velocity.y -= 0.1
	print("Ending velocity.y is ", velocity.y)

if Input.is_action_just_pressed("Jump") and is_on_floor():

probably one of these is false, which is why it never reaches jump() ?

multiple arguments should be fine here, it just adds them up to one string.

“Converts one or more arguments of any Variant type to a String in the best way possible.”

1 Like

@burning-banana I just tested it. I was surprised.

So I take that back. It did work.

func _ready():
	print(str("hello ", "world"))

outputs

hello world

I checked and no one of those values is False

I tried this and on the console output just print:
Starting velocity.y is 0.88888889551163

Did it print “This is the jump function”?

1 Like

no…strange.isn’t it?

Maybe you are running an old copy of your script then