URL expected but getting string instead? (SOLVED)

In the game i’m working on i’ve made a function that will log which tile the player is standing on and output it into the colsole.

the code looks like this:

	pos = go.get_position()
	x_tile = math.ceil(pos.x/16)
	y_tile = math.ceil(pos.y/16)
	tile = tilemap.get_tile("main#level1#tilemap", "level", x_tile, y_tile)
	if not (self.last_tile == tile) then
		print(tile)
		self.last_tile = tile
	end

For some reason i’m getting the following error:

For reference this is where the tilemap is located in my project:
assets_panel

Have a read about how URLs are constructed in Defold, particularly this section:

Note that your last screenshot is not relevant. The Assets pane on the left is just a representation of the files on your computer. It is the structure in the Outline pane on the right that matters.

well the problem is i’m not even trying to get a url returned i should be getting a number?

You’re misunderstanding the error message. It says something on line 103 is expecting a URL but is given a string instead.

See this entry for tilemap.get_tile() for a hint:

1 Like

but its written out correctly as a url, no? if i put an incorrect URL it will say that the URL was not found, so why would it return a string instead of a number?

It’s close, but not correct.

This is your URL:

	tile = tilemap.get_tile("main#level1#tilemap", "level", x_tile, y_tile)

Now compare it to the examples on the page I linked to earlier.

2 Likes

i changed it to:

tile = tilemap.get_tile("main:/level1#tilemap", "level", x_tile, y_tile) 

but i now get the error:
error70

Okay. What have you tried so far? Have you confirmed that that’s the correct URL as per the Outline pane on the right?

i origionaly moved it out of a folder called environment to the main folder before calling it ealier. I have just moved it back and tries to access it using the following:

**tile = tilemap.get_tile("environment:/level1#tilemap", "level", x_tile, y_tile)

But just got an error saying: function called can only access instances within the same collection.

should i just make a new tilesource and map in the main folder and try again?

No, as mentioned previously the folder structure (Asset pane on left) does not matter. It’s how the components and objects are deployed in the Outline pane (on the right) that matters. If you click on the component it should show you part of the URL (just not the collection).

Here’s an example from my project:

2 Likes

I dont have a properties panel only a changed files panel. Look i really appreciate the help but i kinda feel like i’m being messed with lol

You don’t have that section on the right?

1 Like

Ight i got it for some reason i changed its id from the name of the tilemap, thank you so much

1 Like