Cannot convert argument from object to vector 2i

Godot Version

4.3

Question

why is godot specifically working against me to do this “cannot convert argument from object to vector 2i” is not an error that should show up im using a variable as in i want vector2i to be “object” it works if im using mouse click and nothing else… why cant vector2i be whatever i want to call it? i cant get a straight answer from godot website because my code works in any other context. im trying to do something specific not wipe crap allover my canvas and call that a game

literally need to know why i cant not that i cant none of the errors are helpful if i have to look up what you mean by them as if they don’t speak English

Can you show your script and the specific line that error appears on? You’re right the errors aren’t speaking in english, machines only know how to speak in code :upside_down_face:

the people that wrote the error messages are supposed to be people
its the same code i was working with the last time
if random < 0:
var _land = Vector2i(0,0)
print(0)
set_cell(_mouse, 0, _land)
elif random < 1:
var _land = Vector2i(1,0)
print(1)
set_cell(_mouse, 0, _land)
its saying land cant be an “int” but i know it can because the same code works when mouse is my mouse position but when i try to use this in any other context such as trigger zone raycast it says i cant do it with no other explanation why

just random logic apparently

How is _mouse defined? Seems like _land is pretty cut-and-dry a Vector2i, unless there is another definition, it’s hard to tell without the indentation. Make sure to paste between three ticks

```
type or paste code here
```

my character has a raycast the raycast when not interacting with land loads the layer with the random set cell logic and it errors and says it cant do that

its only _mouse because i keep switching the code back to see if its working in that context im trying everything at the moment mouse is viewport

but thats in the tile layer so it places in the tile location in that context but thats fine if i can get the tile to place with the players script but it doesn’t like that

So if mouse is a viewport that can’t be translated to a Vector2i without explict conversion. There are at least 8 potential Vector2 values that a Viewport contains, which one could you mean? Godot will not pick .get_mouse_position() for you out of the others, Godot doesn’t know what your intentions are.

Still, it would help to paste the _mouse definition. Seems like last time you had this line:

Which does end up a Vector2i. So what do you have now?

it only called mouse because im switching it back to see if its working wich it is know. now, what it isnt doing is when i switch it to inside the raycast to call the other script with the rng in it.

func _physics_process(_delta: float) → void :
if is_colliding():
print (true)
else :
preload (“res://layer_0.gd”)
it now calls form the player giving me the "cannot do this "
im not using mouse thats just to prove that works im switching the var so it works for what i try but it wont let me because raycast doesn’t have set cell function





# Called when the node enters the scene tree for the first time.
func _physics_process(_delta: float) -> void :
	if is_colliding():
		print (true)
	else :
		preload ("res://layer_0.gd")

extends TileMapLayer

func _physics_process(_delta: float) -> void:
		var random = randi_range(0,6)
		var _mouse = local_to_map(get_global_mouse_position())
		if random < 0:
			var _land = Vector2i(0,0)
			print(0)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 1:
			var _land = Vector2i(1,0)
			print(1)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 2:
			var _land = Vector2i(2,0)
			print(2)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 3:
			var _land = Vector2i(3,0)
			print(3)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 4:
			var _land = Vector2i(4,0)
			print(4)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 5:
			var _land = Vector2i(5,0)
			print(5)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")
		elif random < 6:
			var _land = Vector2i(6,0)
			print(6)
			set_cell(_mouse, 0, _land)
			preload ("res://ray_cast_2d.gd")

mouse doesn’t matter at the moment i just need it to spawn from player walking off the edge ill fix the location after i know it works

all these things work on their own so there must be a way i can do it

The preloads are strange, I’m not sure what you intend to do with those. preload only loads a resource, when used on it’s own line (not assigned to a variable) it’s pretty much useless. Do you need to get a reference to the TileMapLayer from the RayCast or vice-versa? I believe we went over doing this from RayCast to TileMapLayer via get_collider()?

I don’t see a reason to go the other way from TileMapLayer to RayCast, but you could use @export or show your scene tree so I can help devise a path with $.


Might be helpful to go over a tutorial on the scene tree, maybe go through the “Dodge the Creeps” tutorial and pay close attention to anything with the get_node symbol $

well the other day you said i could use two scripts together i was trying that because a raycast node cant do what a tile layer can do and a tile layer node cant do what a raycast can do. i mean how hard is it to spawn a block at a location not triggered by the mouse i feel im making perfect sense here. not painting a map spawning blocks with walls on them when there is no floor layer. simple

if i use get collision its reverse of what i want thats combining the “is colliding” with the location giving me a location i don’t need where there is a block

So what location do you want? The player’s position? No raycast needed if that’s the case.

I don’t think you’ve stated what you really want from this, please do explain what you intend to happen. We might be having an XY problem communicating.

this scene only runs as a mouse clicker at the moment so showing the error wouldn’t do it justice youll see a mouse clicker that works. the reason im trying all this is it doesn’t work in a raycast to use set cell

But why a raycast? Let’s dig deeper, what are you really trying to do?