Error reporting and checking existence of tile

Need the ability for functions like 'type' that can refer to a tile by name to (optionally?) return an error value if a tile doesn't exist, rather than simply crash the game. This would potentially allow checking if a tile exists or not.

My game's win state is when all the enemies in the room are destroyed. I do it like this:

on interact do
  // [Destroying an enemy if the requirements are met]

  enemyCount = 0
  emit "rollCall"
  if enemyCount == 0 then
    fin "You win!"
  end
end

then in the enemy script

on rollCall do
  enemyCount++
end

This is how I know there are no tiles of this type.

1 Like

It's a neat little script, but a completely different use case to mine I'm afraid.

Here is my original question from the discord:

"So here's a question. Is there currently any way to check if a tile with a certain name exists?

So I'm trying to make an easy way to give my portraits different emotions without redrawing the entire face, just editing a few tiles. Currently I have my portraits at 6x6 tiles, named like "hina 00" to "hina 50" for line 1, "hina 01" to "hina 51" for line 2, and so on, with a little script that goes through and iterates through each number combo to put the right tiles in the right places without it needing 36 different draw commands.

What I want to do is to set a variable called say "hinaexpression" to something like "happy" and then the script check if the tile "hinahappy 00" exists, or if not use "hina 00". This will save me copying out and renaming 36 tiles every time I want to edit, like, a mouth.

Anyone know if this is possible? I tried using 'type', hoping it would come back with something like 'error' or 'n/a' but it just crashes..."

I was told it isn't currently possible and to post here as a feature request.

Ok, in this situation you'll likely need to have a tile for every combination, then use the mimic keyword to set up the placeholder ones.

on any do
  mimic "hina"
end

Edit: This might not do what you're hoping either, since that doesn't change the tile's sprite/drawing. Sorry.

The solution I have used is to draw the 'normal' face in its entirety, then check if a variable called "hinamotion" is set to "happy", and if it is, run a (much smaller than the full portrait) set of draw commands to change the required tiles.

Likewise I will have ones for Mad, etc. I might see if I can do this with tile frames instead just to make things easier to find, I dunno.

This was really helpful! Thanks @BoldBigflank

I know this answer is no longer needed, but as a solution to the problem initially posed I have had the same problem and have solved it by writing some safety functions as custom event handlers like this:

on getName do
	// Safely get tile name
	// _arg1 = x, _arg2 = y
	// returns name
	if _arg1<0 then
		_res = "undefined"
	elseif _arg1>24 then
		_res = "undefined"
	elseif _arg2<0 then
		_res = "undefined"
	elseif _arg2>14 then
		_res = "undefined"
	else
		_res = name _arg1,_arg2
	end
end
on isSolid do
	// Safely check if tile is solid
	// _arg1 = x, _arg2 = y
	// returns solid
	if _arg1<0 then
		_res = 1
	elseif _arg1>24 then
		_res = 1
	elseif _arg2<0 then
		_res = 1
	elseif _arg2>14 then
		_res = 1
	else
		_res = solid _arg1,_arg2
	end
end

And an example call, rather than calling directly

tileName = name x,y

which will throw an error if x,y is outside of the screen, I call my event handler

_arg1 = x
_arg2 = y
tell event.game to
	call "getName"
end
tileName = _res

For my purposes with solid returning 1 when off-screen was sufficient, but it could be e.g. -1 to denote non-existence.

Maybe this will be of use to someone searching and finding this thread :slight_smile:

1 Like