Type cast int to string

BlitzMax Forums/BlitzMax Beginners Area/Type cast int to string

Tile1 is a variable name.

You can't do something like MyVar$ = "Tile" + "1"
and then
DrawImage MyVar

You can refer to a variable with the name, but you can't 'build up' a variable string that points to that variable.

Tile1 is a pointer to a location memory, while "Tile1" is a string variable, and points to a different memory location.

What you can, is something like:
- rename your tiles like tile1.png, tile2.png,...,tileN.png
- make a loop to load the tiles in an array of images:
for n = 1 to num_of_tiles
arr(n) = loadimage("tile" + n + ".png")
next

- then you can access to it from within a loop:
for n = 1 to num_of_tiles
drawimage arr(n),x,y
next

Hope it helps,
Sergio.