pause menu wont work...

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

im working on a game where you can change the speed and jump accelerations during game. i was working on a pause menu for the game, the pausing works but i cant resume back to the game for example the game pauses but when i press resume it wont unpause.
script:
extends KinematicBody2D

var motion = Vector2()
const UP = Vector2(0,-1)
var speed = 100
var jump_height = 300
onready var anim = $Sprite
var paused = false
onready var powerup = get_node(“res://scenes/powerup.tscn”)

func _physics_process(delta):
motion.y += 10
if Input.is_action_pressed(“ui_right”):
motion.x += speed
anim.play(“right”)
anim.flip_h = false
elif Input.is_action_pressed(“ui_left”):
motion.x -= speed
anim.play(“left”)
anim.flip_h = true
elif Input.is_action_just_pressed(“ui_accept”) and is_on_floor():
motion.y = -jump_height
else:
motion.x = 0
anim.play(“idle”)

if Input.is_action_pressed("e"):
	speed = 10
	$"text/speed changed(fast)".hide()
	$"text/speed changed(slow)".show()
elif Input.is_action_pressed("q"):
	speed = 100
	$"text/speed changed(slow)".hide()
	$"text/speed changed(fast)".show()
	
motion = move_and_slide(motion, UP)
pass

if Input.is_action_pressed("ui_escape"):
	get_tree().paused = true
	$"Control/skilltree".show()
	$"Control/resume game".show()
	paused = true

func _on_detection_node_body_entered(powerup):
jump_height = 1000
pass # Replace with function body.

func _on_skilltree_pressed():
$“Control/high jump”.show()
$“Control/running powerup”.show()
pass # Replace with function body.

func _on_CheckButton2_button_down():
speed = 10
pass # Replace with function body.

func _on_CheckButton2_button_up():
speed = 100
pass # Replace with function body.

func _on_CheckButton_button_down():
speed = 10
pass # Replace with function body.

func _on_CheckButton_button_up():
speed = 100
pass # Replace with function body.

func _on_resume_game_toggled(button_pressed):
get_tree().paused = false
paused = false
$“Control/skilltree”.hide()
$“Control/high jump”.hide()
$“Control/running powerup”.hide()
$“Control/resume game”.hide()
pass

func _on_resume_game_pressed():
if _on_resume_game_pressed():
get_tree().paused = false
paused = false
$“Control/skilltree”.hide()
$“Control/high jump”.hide()
$“Control/running powerup”.hide()
$“Control/resume game”.hide()
pass # Replace with function body.

Have you made sure the pause_mode-property of the node this script is attached to is set to “Process”? Otherwise _on_resume_game_toggled and _on_resume_game_pressed won’t be called - thus the game won’t unpause.

njamster | 2020-07-19 11:37

thanks it worked

Zubayer | 2020-07-20 13:36

:bust_in_silhouette: Reply From: Simon

Hi, the resume is not working because is paused. You can fix it changing the pause property (in the inspector of the your resume node) from Inherit to Process.