Invalid set index movespd(on base string) with value of type float

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lucilfer
extends Node

onready var player = "res://entities/player.tscn"


const validcommands = [

func _ready():

func set_speed(movespd):
movespd = float(movespd)

if movespd >= 1 and movespd <= 5:
    player.movespd = movespd
    return str("success", movespd)
return("set lower")
:bust_in_silhouette: Reply From: jgodfrey

I assume you intended to create an instance of that player scene, but you haven’t done that. So, right now, your player variable is simply a string containing a path to a scene. And, since a string doesn’t have a movespd property, that causes your error.

I’d assume you’re trying to do something like this:

onready var player_scene = preload("res://entities/player.tscn")
var player

   player = planer_scene.instance()

With that, player is now an instance of the player _scene. So, assuming that scene has a script attached that provides the referenced movespd property, that should fix your error.

Yep, likely still a PackedScene.

avencherus | 2020-12-03 01:08