How do i fix this problem? it says The function 'move_and_slide()' returns a value, but this value is never used

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ali axco

extends KinematicBody2D
class_name Actor

func _physics_process(_delta):
var velocity: = Vector2 (400, 0)
move_and_slide (velocity, Vector2(400, 0))

:bust_in_silhouette: Reply From: archeron

It’s not really a problem if you don’t actually need the return value, e.g. to see if there was a collision. If you want to get rid of the warning, you can write

var _ignore_collision = move_and_slide(.....)

or turn of the whole class of warnings (unused return value) in the settings (I wouldn’t, though, until you know your way around Godots API). You can configure which warnings you want to see; there’s lots of options there.

Another option is to click the yellow warning sign at the bottom of the script editor and then click ignore which will put a comment before the line with the warning to ignore it.

exuin | 2021-03-23 14:55

Another other option is to use call("move_and_slide", "......")

if move_and_slide(......):

Wakatta | 2021-03-24 00:20

or the following, which might also not generate any overhead because the GDScript bytecode compiler could easily optimize it away (don’t know if it does, though), and reads nicely:

move_and_slide(...) and "ignore return value"

or even this, which is very short, but rather cryptic:

move_and_slide(...) or false

exuins solution is probably best.

(BTW, with the above “and”/“or” options, you’ll get another warning, “standalone expression”… so that might not be too useful; it’s just a way to convert one warning into another one :slight_smile:

archeron | 2021-03-24 00:38