Type cast int to string

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

Ogg77777(Posted 2005) [#1]
TileNumbers are stored in an array (TileNumber[0. 0] = 1), And are used To Print the map.
To avoid using a lengthy Select Case statement, I am trying To convert the integer value
from the TileNumber array To a String And use String concantenation To draw the image To
the screen as follows. I am getting the error message "Unable to convert from 'String' to
'TImage'"


Images are loaded as follows
Local Tile1 = LoadImage("Incbin::grassTile.bmp")
Local Tile2 = LoadImage("Incbin::rockTile.bmp")
Local Tile3 = LoadImage("Incbin::sandTile.bmp")


The screen is printed using the following loop.
For x = 0 To 24
For y = 0 To 17
Number = Int TileNumber[x, y]
TileString = String(Number)
DrawImage "Tile"+TileString, x*32, y*32
Next
Next


semar(Posted 2005) [#2]
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.


Yan(Posted 2005) [#3]
Either load the images into an array or put them into one large bitmap and use that as an animimage.


FlameDuck(Posted 2005) [#4]
What they mean is:
Local Tile:TImage[3]
Tile[0] = LoadImage("Incbin::grassTile.bmp")
Tile[1] = LoadImage("Incbin::rockTile.bmp")
Tile[2] = LoadImage("Incbin::sandTile.bmp")

For x = 0 To 24
  For y = 0 To 17
    DrawImage Tile[TileNumber[x, y]], x*32, y*32
  Next
Next 



Dreamora(Posted 2005) [#5]
I think what they mean is string parsing into variable names, which is only possible in script languages.


Azathoth(Posted 2005) [#6]
If he really wanted he could use a hashtable, someone made one in blitzmax.