0 votes

Why godot doesn't let me access the position of the input event(event.position) of the _input() function after I enter this condition: if event is InputEventScreenTouch or if event is InputEventScreenDrag ?

Godot version 3.3
in Engine by (52 points)

Thanks for your explanation :) . Anyway, it doesn't read the keyword "as", but "is" does.

nono, I am talking aboiut two different keywords.
IS checks for class, returns true or false :

 if myvar is RigidBody :
           print("yes")

AS is added to variable to force compiller to bahave, like this variable is of certain class. If You wrote :

mywar = get_node("boom") as RigidBody

compiller will finish your sentences, just like myvar would be of class rigidbody, even if in reality it is another class.

So with the last operation you force the "boom" node to be of type or class rigidbody and assign it to the variable "myvar"?

You force editor to treat it as it would be class RigidBody, but real class is not changed. This is useful when , for example, node doesn't have child "boom" at the start of project, it is added in some conditions later on runtime, but You have functions that refer to this child in your code. This way You can let editor know, that when this getnode("boom") will exist, it will be of class RigidBody, and it will make referring to this node easier, and "let" you use applyimpulse, add_torque and other rigid body stuff. However if You write RigidBody methods but lie to editor and actually "boom" will be another class, it will crash with error :)

I read in passing. I thank you anyway for the explanation :)

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 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.