string variables are not working in my game?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

string variables are not working in my game?

Post by Jim121 »

string variables are not working in my game?
I am using namespace std; and including <iostream> but this error comes up: `string' does not name a type
thanks in advance
Open Conquest Developer
web site:
http://openconquest.webs.com/
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

For optimal assistance for your problem, it would be helpful for you to post your code here, or at least an abbreviated version which illustrates the problem lines. Without code, we can only make guesses as what is actually happening.

Also, is there any reason why you need to use the standard strings as opposed to irrlicht strings (check the core namespace in the docs)?
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

Post by Jim121 »

I was using the standard C++ string.
there's the code up to the error.
I hope that helps.

#include <irrlicht.h>
#include <iostream>
#include <string>
#include <sstream>
#include <zoidcom.h>
#include <stdlib.h>
#include <stdio.h>
#include <zoidcom.h>
#include <irrKlang.h>
#include <fstream.h>
#include <windows.h>
#include <gl/gl.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace std;

//# include <SDL/SDL.h>
//# include <SDL/SDL_mixer.h> dosent exist

//
// the client class
//

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
#include "other.cpp"

LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);


int e,a;
int start = 0;
string s; <- there is the error
Open Conquest Developer
web site:
http://openconquest.webs.com/
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

"string" is defined in both the irrlicht namespace irr::core:: and the std:: namespace, causing an ambiguous symbol error. You need to not use either the "core" namespace or the "std" namespace. My recommendation is to drop the std namespace and just go with irrlicht strings.

Also, you're including "zoidcom.h" twice :wink: .
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

Post by Jim121 »

thanks

What is the function for a string in irrlicht e.g.
string s;

using std.
Open Conquest Developer
web site:
http://openconquest.webs.com/
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

core::stringc("Hello") or stringc("test")+core::stringc(myintvar)...
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

Post by Jim121 »

The problem is that in the same program it will need to open and read & write for a text document. I was using std:: but this conflicts with irr::core:: so I stopped using std::. But this means that the program can't read or write text documents what should I do? thanks in advance
Open Conquest Developer
web site:
http://openconquest.webs.com/
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can simply avoid the 'using namespace std' and use std:: everywhere in the code. Or you use the IFileSystem from Irrlicht, which will also allow to read from zip files and other nice things, though without the handy sscanf/stream functions from the stdlibs.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Or in place of the std::string use a core::string.. they behave in the same way and have pretty much the same functions as far as i can remember!
Image Image Image
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

Post by Jim121 »

Are there any good IFileSystem examples?
Open Conquest Developer
web site:
http://openconquest.webs.com/
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I don't think so... strange that... but ask and ye shall receive...

what are you trying to do?
Image Image Image
Jim121
Posts: 21
Joined: Sat Oct 11, 2008 2:23 am

Post by Jim121 »

I'm basically wanting to read files and write files.
I need to read and write files in my game for two reasons.
1. I will need some way of storing data like player health, weapons, e.g.
2. Because the game is a online rpg I need to transfer data but the game would pause while transferring data. I thought easy way fix that would be to make a another program to download the data and write the data to a text document. Then the game would read that file quickly and not pause. It's quicker to read from a text document than with the internet.
thanks
Open Conquest Developer
web site:
http://openconquest.webs.com/
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well there's two options i guess. You can either come up with your own format, something like a text file containing the following:

Player 1
100
Axe
Sword

Which is of the format

Player name
Player Health
Weapon 1
Weapon 2
...
Weapon N

Or you could look into using irrlichts XML reader/writer, which would be much easier for you. If you look at the MeshViewer example there's a nice snippet for reading in XML files which should be clear how you can adapt it to the data you require to be stored, writing out the XML is done pretty similarly and can be read about in the API or feel free to ask again when you get to that stage!
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Jim121 wrote:I'm basically wanting to read files and write files.
I need to read and write files in my game for two reasons.
1. I will need some way of storing data like player health, weapons, e.g.
2. Because the game is a online rpg I need to transfer data but the game would pause while transferring data. I thought easy way fix that would be to make a another program to download the data and write the data to a text document. Then the game would read that file quickly and not pause. It's quicker to read from a text document than with the internet.
thanks
You may want to revisit your assumptions.

What will "pause" while transferring data? The server? The client?

Why would either of them "pause" while doing this? All (real time) games use either non-blocking sockets or threaded blocking sockets. Your main thread should never get blocked.

What you seem to be proposing is a horribly inefficient version of IPC when there's no need for it.

If you use a decent network library like Raknet then it will take care of sending and receiving available network data for you.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Why don't you use threads...

Threading allows you to run multiple chunks of code simultaneously, meaning that if you have a file loader (or network handler) in a separate thread and have it take the time it needs without causing the rest of your program to cease functioning.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Post Reply