Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit) (+1)

You could calculate the index you need. This will require some consideration of the tile size:

Be careful of overflow. If you have lots of tiles, you might need to add to i multiple times. This technique also gets a bit fiddlier if you aren't using a power-of-two size, but it's still doable.

Another option is to just use pre-multiplied values as your tile IDs. If you don't have many tiles, this makes looking one up trivial!

In some situations, you could consider using self-modifying code to rewrite the address in an `i := NNN` or `i := long NNNN` instruction. This gets a bit fiddly, but if you have lots of tiles, or tiles that take up a lot of memory (like full-color tiles) it might be the most efficient option. There are some examples of these sorts of techniques in the FAQ, when discussing pointers.

Edit: Oh, and one other thing- while writing a loop like you did there does work, it would be more idiomatic to do something like:

Using == or != instead of < is more efficient when you can get away with it.