0 votes

Hi all. I'm nearly done with the code for a game I've been making this past week. Just a few more things to do before I get to spriting, and levels.

I've a Signal called 'game_over', and I'd like to disable the code that listens for Input when the signal fires. The below code is from LazerGun.gd.

extends KinematicBody2D

const LAZER = preload("res://player-side/EnergyShot.tscn")
const ROTATION_SPEED = 0.5

signal fire
var rotation_Direction


func _ready():
    pass

func get_input():
    rotation_Direction = 0.0
    if Input.is_action_pressed('test_up'):
        rotation_Direction -= 1.0
    elif Input.is_action_pressed('test_down'):
        rotation_Direction += 1.0

    if Input.is_action_just_pressed('test_fire'):
        fire()


func fire():
    var lazershot = LAZER.instance()
    lazershot.start($LazerSpawn.global_position, rotation)
    get_parent().add_child(lazershot)


func _physics_process(delta):
    get_input()
    rotation += rotation_Direction * ROTATION_SPEED * delta
    rotation = clamp(rotation, deg2rad(-45), deg2rad(45))

func _on_game_over():
    pass # replace with function body

Again, I'd like to disable the 'getinput()' function when 'gameover' fires. I can figure out how to get the gun working after a game over.

in Engine by (197 points)

the more obvious answer is just

var playing = true

func _on_game_over():
  playing = false

func _physics_process():
  if playing:
    get_input()

but im not posting it as answer because there may be a better way of doing it

Thanks, RazorSh4rk. This works.

Could you post as an answer so others can se its solved?

1 Answer

+2 votes

Answer by RazorSh4rk

The more obvious answer is just

var playing = true

func _on_game_over():
    playing = false

func _physics_process():
    if playing:
        get_input()

but im not posting it as answer because there may be a better way of doing it.

by (3,871 points)

This is not my answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.