0 votes

Hello everyone! I'm having a small issue with my code. I want to start a timer ($ReelTimer) when another timer stops. However, when the other timer stops and I call a true statement to run the function, it runs, but the timer does not start, and I do not know why.

Here is the code. (Some parts may have been removed so it's shorter):

extends KinematicBody2D

const moveSpeed = 150.0

var timesToTap = 10

var hasThrownLine = false
var caughtFish = false

var randomCatchTimer = rand_range(5, 30)
var randomFishGenerator = randi()%4+1

func _ready():

func _input(event):
    if Input.is_action_just_pressed("catch") && !hasThrownLine:

func _process(delta):   
    if caughtFish:
    elif !caughtFish:
        return null

func FishEncounterTimeout():
    caughtFish = true

func PickRandomFish():
    randomFishGenerator = randi()%3+1
    print("From PickRandomFish(), it generated " + str(randomFishGenerator))

    match randomFishGenerator:
            global.goldfishAmount += 1
            global.salmonAmount += 1
            global.garfishAmount += 1

func CaughtFish():


    if Input.is_action_just_pressed("catch"):
        timesToTap -= 1
        print("Tapped the catch button upon catching fish. Taps left: " + str(timesToTap))

        if timesToTap <= 0 && !$ReelTimer.is_stopped():
            timesToTap = 10


            caughtFish = false
            hasThrownLine = false

        if $ReelTimer.is_stopped():
            print("Can no longer reel.")
            timesToTap = 10


            caughtFish = false
            hasThrownLine = false
in Engine by (163 points)

How do you checke timer did not start? Could it be that the $ReelTimer.is_stopped() is called inside if Input.is_action_just_pressed("catch"): , so you won't enter the if $ReelTimer.is_stopped(): unless you just pressed "catch"? If i understand correctly your code, i would instead create a function on_ReelTimer_timeout() and connect $ReelTimer.timeout() to it. If this does not help, would you please explaina little more how you expect the game to work?

An observation about your code.

if Input.isactionjust_pressed("catch"):

This line will only be true on the frame the "catch" action is pressed. One frame early or one frame late and it won't reach the block. Is that your intention? In your tests are you calling this function every frame?

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.