|
passing a string to textprinf_ex |
notwist
Member #8,248
January 2007
|
I want to store a description inside of a map tile structure array and display it on the screen. so i create this structure type: struct tile define it with: floor.desc="Stone floor."; move a little '@' left and right along a single horizontal line if (key[KEY_4_PAD]&& player.x>0){ and everything falls apart when i add the line textprintf_ex(screen, font, 0, 8, makecol(map[player.x].colorR, map[player.x].colorG, map[player.x].colorB), -1, "%s", map[player.x].desc); |
DanielH
Member #934
January 2001
|
Is player.x within the parameters of map? Is desc defined of map[ player.x ].desc? what is desc? what type of variable is it. You said string. Is it a C string or a C++ string? std::string desc or Without seeing more code, that's all I say about that. |
notwist
Member #8,248
January 2007
|
struct Player tile map[80]; |
DanielH
Member #934
January 2001
|
Now I see that map is of tile and tile is of Is player.x defined before you use it? And when is each tile in map defined? |
notwist
Member #8,248
January 2007
|
player x is defined and set to 0 before it is referenced this is the main screen drawing loop for(x=0;x<80;x++) |
LennyLen
Member #5,313
December 2004
|
Quote: and everything falls apart when i add the line Care to explain what you mean by 'falls apart'?
|
DanielH
Member #934
January 2001
|
Do this and tell me what happens if ( map[player.x].desc ) } textprintf_ex(screen, font, 0, 8, makecol(map[player.x].colorR, map[player.x].colorG, map[player.x].colorB), -1, "%s", map[player.x].desc); { else { textout_ex(screen, font, "null", 0, 8, makecol(map[player.x].colorR, map[player.x].colorG, map[player.x].colorB), -1 ); } And I should have said it earlier, but use 'code' brackets when displaying code on this website. [code] |
notwist
Member #8,248
January 2007
|
sure, it compiles, and runs i can iterate the character and it will display the string, however the string doesnt coorelate to the tile the character is standing on the pointer appears to iterate beyond the array, as it will display strings of desc then it starts to display random symbols then the app freezes //same thing happens when i replace my map[].desc with the given conditional display
|
DanielH
Member #934
January 2001
|
EDIT I know that you can put structure declarations inside the function, but !!!NO!!! map[ x ] = grass; What is that? How about map[ x ].walkable = grass.walkable; map[ x ].img = grass.img; map[ x ].colorR = grass.colorR; map[ x ].colorG = grass.colorG; map[ x ].colorB = grass.colorB; map[ x ].desc = grass.desc; Or you could do tile *map[ 80 ]; map[ x ] = &grass; |
notwist
Member #8,248
January 2007
|
if grass is and map[x] are the same data type can't you just assign the values of grass to the array node x? |
gnolam
Member #2,030
March 2002
|
1) Edit your posts to use code tags. They're nigh unreadable without indentation. 2) Quote: floor.desc="Stone floor."; There's your problem. -- |
LennyLen
Member #5,313
December 2004
|
And in case you don't know what gnolam means, that line should be: strcpy(floor.desc, "Stone floor");
|
|