#Type error
39 messages · Page 1 of 1 (latest)
But I first check if it is said subtype before checking for the button_index
so is this just GDScript acting up?
try casting it first:
if !mouse_event: return
print(mouse_event.button_index)```
so if casting fails it just becomes false?
if it fails it will be null... nill... what'eva godot uses for that, but it will evaluate to false, yeah 🙂
hm seems like a weird quirk of the language
why doesn't it just infer the type from the check
because thisll become quite verbal if you have several input types...
that's C++ I guess, was weird to me too coming from TypeScript, but must have good reason regarding memory management under the hood... am new to godot, so just guessing
yea i also come from TS and new to godot
thats why I wanted static typing
but ig it be like that
this still fails the vibe check
use isMouseEvent.button_index instead of event
oh mb
you could just not type event if it bothers u
so func _input(event) -> void: instead
errors cuz i enabled enforced static typing
but ill use this quirky way instead then
until it gets fixed (i assume others have this issue as well)
so it forces you to static type everything?
ye
maybe if you check the second condition within a second nested if loop it'll work without doing the other stuff? no entirely sure though
func _input(event: InputEvent) -> void:
var mouse_button_event: InputEventMouseButton = event as InputEventMouseButton
var mouse_motion_event: InputEventMouseMotion = event as InputEventMouseMotion
if(mouse_button_event):
if mouse_button_event.button_index == MOUSE_BUTTON_LEFT:
startingCoordinates = mouse_button_event.position
if mouse_button_event.button_index == MOUSE_BUTTON_WHEEL_UP:
self.zoom = clamp_cam(self.zoom + Vector2(scaling_factor, scaling_factor))
if mouse_button_event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
self.zoom = clamp_cam(self.zoom - Vector2(scaling_factor, scaling_factor))
if (mouse_motion_event && isPressed):
self.position += -(mouse_motion_event.position - startingCoordinates) * 0.2
its now this
which is alright ig
the if check is now just done by casting first
not the way i'd prefer it but so be it
i haven't tested it out but maybe if you do
if (event is InputEventMouseButton):
if (event.button_index == MOUSE_BUTTON_LEFT):
...
It will type it automatically? If that's something you'd prefer over what you're using currently.
already checked and it doesnt work
I just remember doing that once but idk if i'm remembering correctly
oh okay nvm then
¯_(ツ)_/¯
you could also flip it:
var button_event: InputEventMouseButton = event as InputEventMouseButton
...
elif event is InputEventMouseMotion:
var motion_event: InputEventMouseMotion = event as InputEventMouseMotion
...```
or send it to other functions:
```if event is InputEventMouseButton:
_handle_button_event(event as InputEventMouseButton)
elif event is InputEventMouseMotion:
_handle_motion_event(event as InputEventMouseMotion)```
yea this is fine for now