#Invalid operands 'Vector2i' and 'Callable' in operator '<'

32 messages · Page 1 of 1 (latest)

lavish raven
#

Hi, total noob here.

I'm trying to make a script that, when you push a button, the window gets bigger to fit your screen and then enters fullscreen.
When I try pushing the button, the instance immediately stops responding and I get the error message aforementioned in the title.



func _pressed() -> void:
    print("Button clicked")
    var paranoiaZoom = Vector2(DisplayServer.window_get_size())
    while(paranoiaZoom < DisplayServer.screen_get_size):
        paranoiaZoom = paranoiaZoom*2
        DisplayServer.window_set_size(paranoiaZoom)
    DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)```

`while(paranoiaZoom < DisplayServer.screen_get_size):` seems to return the error.

I have no prior knowledge of GDscript or C#/C++ or anything, and no clue what I'm doing
silk axle
#

Your while loop is trying to compare a vector with a function, not the output of it. Is the rough translation of your error.

You need brackets after DisplayServer.screen_get_size
This asks the function to actually run

lavish raven
#

Ah

#

I added the Vector2 part to the var paranoiaZoom =… line after I got the error, was that necessary or should I change it back

silk axle
#

Not needed, that method already returns a vector2
What you are doing there is telling it 'this vector must be a vector'...which isn't really that useful 😄 (although admittedly, not harmful either, especially if you can't be sure)

lavish raven
#

That worked

#

Is there some sort of wait function? The animation I'm trying to do isn't happening and I'm pretty sure it's due to it happening all at once or something

#

I can't seem to find it

silk axle
#

what are you trying to do, and how are you currently trying to do it?

lavish raven
#

I want the window to exponentially get bigger, and then go into fullscreen

#

right now it's just going into fullscreen immediately

#

when I unfullscreen it, the window is the bigger size, though

lavish raven
silk axle
#

how big are you starting the window?

lavish raven
#

however big it is by default

silk axle
#

so the issue is probably that it starts so big one loop is making it max size

lavish raven
#

well even if I make it smaller it does the same thing

silk axle
#

try turning the 2 down to something smaller

lavish raven
#

I changed it to 1.1 and now I got an error

Invalid operands 'Vector2' and 'Vector2i' in operator '<'.

#

from the line
DisplayServer.window_set_size(paranoiaZoom)
it seems like?

silk axle
#

I should've expected that, it hough it might play nice, but no
surround the DisplayServer.screen_get_size()
with a new Vector2() like:
Vector2(DisplayServer.screen_get_size())
this will 'cast' the vector to a float version, meanig it now can deal with this comparison
(or do 'Vector2i()' around your paranoiazoom)

lavish raven
#

In the while line?

silk axle
#

yes

#

a cast when done like this essentially tells godot to pretend those numbers are a different type until its done (its a bit fancier in the real process, but not by too much)

lavish raven
silk axle
#

oh....i see

#

do the same cast on the intial setting, and know that now we've dont it twice theres almost certainly a better option 🙂

lavish raven
#

im sorry I read that and it did not make sense in my brain

silk axle
#

var paranoiaZoom = Vector2(DisplayServer.window_get_size())
like you had to begin with....you;d solved a problem you didnt have yet 😛

lavish raven
#

so I should put the Vector2 for the definition of the variable?

silk axle
#

yes

lavish raven
#

should I remove the Vector2 from the '<' expression or no