Invaild assignment of property

func generate(map:TileMap, map_Width, map_Height, minRoomSize, maxRoomSize):

var potentialRooms:int = 3#figuring out max number of rooms by checking how many max size rooms can fit
var rooms:Dictionary
var room:Room
var position:Vector2

var start:Vector2
var end:Vector2

var modifier:int

var key:String


# Fill map with solid tiles, adding a border of solid tiles around the map
for r in range(-1, map_Height + 1):
	for c in range (-1, map_Width + 1):
		map.set_cell(0, Vector2i(c, r), 0, Vector2i(Tiles.SOLID, 0))

room.position = Vector2(0, 0)#setting the position of the first room

Question

when the program hits the “room.position = Vector2(0, 0)” line I get the error “Invaild assignment of property or key ‘position’ with in the value of type ‘Vector2’ on base object of type ‘Nil’” which does not make sense because I’m trying to set its value.

Within your example room is never assigned a value and is by default nill.

Try

var room:Room = Room.new()

1 Like

that give the error “Expected end of statement after variable declaration, found “(” instead”

What godot version?

its on 4.0

Do not copy paste just type it out.

done both multiple times

Try:

@onready var room:Room = Room.new()

Well the class Room no longer is documented in 4.0. so it could be an error related to a missing class. But the code would not have gotten to the setting on nill error in the first place if that was the case.

Anyway this is common syntax, i think you probably have some hidden white space issue. Like Tabs vs spaces