0 votes

Thanks for your reply.
Why do you say: What you're doing is calling the method 'unhandledinput' (which doesn't make any sense?
For example, I may want to have an unhandled input to be run after each frame.
I have an input 'uiright' and I want the Node to move position.x to, say, 100 pixels to the right.
The _process(delta) is called. The node does not stop at 100 pixels, though. Node keeps going right with every frame. How do I stop it? set
process(false) does not work.

Also, if I declare 'event' as a global on top, will it be recognised by _process(delta) as the special identifier 'event' as in _input(event)? Just as 'delta' has a special meaning in _process(delta), doesn't 'event' have a special meaning in _input(event).

I am not sure if I have been able to ask my doubt correctly or in the technical language would be required in such a question.
Thanks in advance.

in Engine by (100 points)

1 Answer

+1 vote

This is why the language of C is so beautiful (no type misunderstandings)

'event' is not a reserved keyword it is a variable instance of class InputEvent when called from the virtual functions _input(event : InputEvent): or _unhandled_input(event : InputEvent): and _gui_input_event(event : InputEvent):

rather than having to extend that class's functionality into a variable to use in the _process func

I'd recommend to use the Input class instead like for example

func _process(delta):
    if Input.is_action_just_released("ui_right"):
        node.position.x += 100
by (5,012 points)

Thanks a lot, Wakatta.
This is a great working solution. Had been struggling with this for so many days now.
Can you please explain what are virtual functions? How do they behave differently from inbuilt functions like, say, print() in Godot?

A topic too grand to detail here.
But simply put virtual functions change the functionality when called form a derived member class if you've noticed something done automatically when you create a Script.gd

extends Node

class GrandParent:
    func _show_bad_habits():
        print("horde heirloom")

class Parent extends GrandParent:
    func _show_bad_habits():
        ._show_bad_habits() # call inherited function
        print("Expect too much from kids")

class Child extends Parent:
    func _show_bad_habits(): # -> completely override
        print("Rebel without a cause")


func _ready():
    var parent = Parent.new()
    var child = Child.new()

    parent._show_bad_habits()
    child._show_bad_habits()

Thanks Wakatta, for your detailed explanation. Really appreciate.

What does the dot (.) before the call to showbad_habits() in class Parent represent? This is in the third line of class Parent.

Not sure what terms are used in Godot but that dot (.) represents Super
Used to superseded any overridden(Virtual functions) with the one defined in the base class

So because _show_bad_habits() func was changed in the Parent class if you wanted to still access the original functionality from the GrandParent class that's where the Super comes into play

! Please note that my explanations here are super simplified and does not express the full scope of use cases

Thanks again.
Simplified or not, this unlocks a lot of things for me.
So, if we don't insert the dot, will it become a recursive call?
When I removed the dot and ran the app, there was a stackoverflow.
Also, with the dot (.), shouldn't 'horde heirloom' print twice when the app is run?

BTW: I like your placards of Child, Parent and Grandparent.

BTW: I like your placards of Child, Parent and Grandparent.

Yeah its the best way to show class inheritance.

So, if we don't insert the dot, will it become a recursive call?

No. What would happen is _show_bad_habits() would be called only from the GrandParent class regardless of which class is initialized

Also, with the dot (.), shouldn't 'horde heirloom' print twice when the app is run?

No the output should be

parent._show_bad_habits()
# horde heirloom
# Expect too much from kids

child._show_bad_habits()
# Rebel without a cause

But if you added the ._show_bad_habits() to the child class then yes it would print

# horde heirloom
# Expect too much from kids
# Rebel without a cause

When I removed the dot and ran the app, there was a stackoverflow.

Removed from where? because that should not happen with this simple example

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 webmaster@godotengine.org with your username.