#Invalid assignment of property or key 'RespawnPoint' with value of type 'Vector2' on a base object

71 messages · Page 1 of 1 (latest)

past escarp
#

it won't let me change variables because it's type nil.
i'm making a save system and this part in particular is bugging out. heres the error message, is there a fix for this?
im using .tres to save files

Invalid assignment of property or key 'RespawnPoint' with value of type 'Vector2' on a base object of type 'Nil'.

i'm gonna go to sleep hopefully someone replies in the morning

slender jackal
past escarp
slender jackal
#

if not can you provide your code?

past escarp
#

the engine's still loading hold on

#

okay

past escarp
#

extends Area2D

func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("Player"):
print("wrong body actually :'(")
SaveData.RespawnPoint = get_node("SpawnPoint").global_position
print(SaveData.RespawnPoint)

#

and for SaveData

#

extends Resource

class_name SaveDataResource

@export var HasResize = false
@export var Dashes = 0
@export var RespawnPoint = Vector2(1,1)

slender jackal
#

where are you loading save data resource?

past escarp
#

its an autoload

slender jackal
#

shouldn’t you be using ResourceLoader and ResourceSaver? (I learned about those yesterday trying to reproduce your problem lol)

past escarp
#

im pretty sure those load files, not scripts

#

might be wrong tho

slender jackal
#

I think you’re misunderstanding how a resource works, you don’t modify the script itself, you make a new resource that extends from your custom resource and change that

past escarp
#

so how do i access said resource from other scripts

slender jackal
past escarp
#

so i load the resource at the start of the script i assume

slender jackal
#

resourceloader is a class with method load where you can load a resource

#

I don’t really know as to how to implement this since I actually just learned this yesterday

#

Honestly I used JSON in user:// for my saving but it seems this is easier

past escarp
#

I WAS GOING TO USE JSON TOO 😭

#

atp should i swap back to json

#

actually i learned somewhere that json doesnt work with vector2s

slender jackal
#

but if they provide you with a solution like ResourceLoader and Saver that was made with the literal intention for saving then that one is probably much easier

slender jackal
past escarp
#

would there be some way to "translate" json to vector2

slender jackal
#

You can store it as a list [0, 0] with 0th element being X and 1st element being Y

#

Then in Godot you can just say Vector2(pos[0], pos[1])

past escarp
#

well guess i'll set up that json save system again gddeadinside

slender jackal
#

looking at a few examples resources actually look much better than json, as long as you know how to use them

past escarp
#

ok so

#

go back to the start

#

is there a way to start funtions ONLY when the game is ready?

slender jackal
#

idk I’ve just been looking around

slender jackal
past escarp
#

okay so if resources arent safe then i'm DEFINITELY using json

#

even if it's not that big of a game

slender jackal
#

Yea it’s not that hard with FileAccess

#

I’d be glad to send some of my code (when im home)

past escarp
#

thanks

past escarp
slender jackal
#

annd this is how i save, note that its obviously not the same

past escarp
#

if you dont mind telling me- how do i connect variables to the JSON file?

past escarp
#

Invalid assignment of property or key 'RespawnPoint' with value of type 'Vector2' on a base object of type 'Node (Save-Load.gd)'.

#

i followed a tutorial on how to set JSON up and this is happening when i try and use Vector2d

slender jackal
#

you set it as a key

#
{
  "This is the actual variable name": "Variable Value"
}
past escarp
#

like this/

#

?

#

@slender jackal

slender jackal
#

yea

#

thats perfect

past escarp
#

k

#

is there a way to access dictionaries in other scripts?

#

@slender jackal sorry for pinging

slender jackal
#

stored in json? yes