C++ SDL TileMap System ERRORS! HELP! :P

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

JesseGuarascia
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Mon Dec 13, 2010 10:55 pm

Re: C++ SDL TileMap System ERRORS! HELP! :P

Post by JesseGuarascia »

VoidElite wrote:
N64vSNES wrote:
MrDeathNote wrote:You may want to update the code you posted so we have something to work on.
Exactly this^

Can you include Main.cpp too?
Main.cpp is the file being compiled it is irrelevant to these errors. I've updated it.

This statement in the tileFile function is the problem:

Code: Select all

sprite->file=("Tiles\\"+id+".bmp").str();
I'm pretty sure you're wrong there my friend. Because by the looks of your errors:

Code: Select all

In file included from src\Main.hpp:11,
                 from src\Main.cpp:1:
src\Tile.cpp:5: error: no `void Tile::TileFile(int)' member function declared in
class `Tile'
src\Tile.cpp: In member function `void Tile::TileFile(int)':
src\Tile.cpp:6: error: invalid operands of types `const char*' and `const char[5
]' to binary `operator+'
src\Tile.cpp: In constructor `Tile::Tile()':
src\Tile.cpp:10: error: `TileFile' was not declared in this scope
src\Tile.cpp: In constructor `Tile::Tile(int, int, int)':
src\Tile.cpp:17: error: `TileFile' was not declared in this scope
The problem is your function names. Because this:

Code: Select all

void Tile::TileFile(int id){
   sprite->file=("Tiles\\"+id+".bmp").str();
}
and this:

Code: Select all

void tileFile(int id);
Are not the same function. All of your errors (for the most part), are with the fact that you didn't make it a lowercase "T" on TileFile. That line should really be:

Code: Select all

void Tile::tileFile(int id){
    sprite->file = ("Tiles\\"+id+".bmp").str();
}
Also, if you're having problems with the string of characters, why not just use a std::string from the STL library?
-- Jesse Guarascia

I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: C++ SDL TileMap System ERRORS! HELP! :P

Post by VoidElite »

JesseGuarascia wrote:
VoidElite wrote:
N64vSNES wrote:
MrDeathNote wrote:You may want to update the code you posted so we have something to work on.
Exactly this^

Can you include Main.cpp too?
Main.cpp is the file being compiled it is irrelevant to these errors. I've updated it.

This statement in the tileFile function is the problem:

Code: Select all

sprite->file=("Tiles\\"+id+".bmp").str();
I'm pretty sure you're wrong there my friend. Because by the looks of your errors:

Code: Select all

In file included from src\Main.hpp:11,
                 from src\Main.cpp:1:
src\Tile.cpp:5: error: no `void Tile::TileFile(int)' member function declared in
class `Tile'
src\Tile.cpp: In member function `void Tile::TileFile(int)':
src\Tile.cpp:6: error: invalid operands of types `const char*' and `const char[5
]' to binary `operator+'
src\Tile.cpp: In constructor `Tile::Tile()':
src\Tile.cpp:10: error: `TileFile' was not declared in this scope
src\Tile.cpp: In constructor `Tile::Tile(int, int, int)':
src\Tile.cpp:17: error: `TileFile' was not declared in this scope
The problem is your function names. Because this:

Code: Select all

void Tile::TileFile(int id){
   sprite->file=("Tiles\\"+id+".bmp").str();
}
and this:

Code: Select all

void tileFile(int id);
Are not the same function. All of your errors (for the most part), are with the fact that you didn't make it a lowercase "T" on TileFile. That line should really be:

Code: Select all

void Tile::tileFile(int id){
    sprite->file = ("Tiles\\"+id+".bmp").str();
}
Also, if you're having problems with the string of characters, why not just use a std::string from the STL library?
Ok I've got rid of all errors and it compiles again but when run it flashes up the window then goes away. Thanks to my debug log(log.txt) I have been able to work out that the problem somewhere in Tile.cpp and I think it's because SDL cannot find the file meaning that it brings us back to tileFile:

Code: Select all

void Tile::tileFile(int id){
	std::stringstream idTmp;
	idTmp<<id;
	sprite->file="Tiles\\"+idTmp.str()+".bmp"; //error
}
Ideas?
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: C++ SDL TileMap System ERRORS! HELP! :P

Post by MrDeathNote »

I would suggest writing out that string to your debug file to see what its actually trying to load. Also try to load the file explicitly. And use the debugger.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

Re: C++ SDL TileMap System ERRORS! HELP! :P

Post by VoidElite »

MrDeathNote wrote:I would suggest writing out that string to your debug file to see what its actually trying to load. Also try to load the file explicitly. And use the debugger.
I've tried "debug->debug(tile->sprite->file);" but it compiles but I see no text outputted from this line in fact any form of interaction with the tile and it immediately kicks off. This is quite obvious due to the fact that tile hasn't been initialized but even when I try to initialize it it doesn't work.

It appears to me that there is some form of internal error in either Tile.cpp or Tile.hpp. Again here is their code:

Tile.hpp:

Code: Select all

#ifndef TILE_HPP
#define TILE_HPP
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include "SDL\SDL.h"
#include "Windows.h"
#include "Globals.hpp"
#include "Debug.cpp"
#include "Sprite.cpp"

using namespace std;

class Tile{
	public:
		Tile();
		Tile(int id2,int x,int y);
		~Tile();
		//destructor needed
		void tileFile(int id);
		Sprite *sprite;
		int id;
};
#endif
Tile.cpp:

Code: Select all

#ifndef TILE_CPP
#define TILE_CPP
#include "Tile.hpp"

void Tile::tileFile(int id){
	std::stringstream idTmp;
	idTmp<<id;
	sprite->file="Tiles\\"+idTmp.str()+".bmp"; //error
}
Tile::Tile(){
	id=0;
	tileFile(id);
	sprite->offset.x=0;
	sprite->offset.y=0;
	sprite->visible=true;
}
Tile::Tile(int id2,int x,int y){
	id=id2;
	tileFile(id);
	sprite->offset.x=x;
	sprite->offset.y=y;
	sprite->visible=true;
}
Tile::~Tile(){
	delete sprite;
	delete this;
}
#endif
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
Post Reply