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.
dipi
Posts: 10 Joined: Tue Feb 26, 2008 6:16 pm
Post
by dipi » Wed Sep 02, 2009 7:06 pm
I'm trying to make an online flygame. I have one question can you make an array of Iscenenodes?
Here's my example from in the program:
Code: Select all
core::array<scene::ISceneNode *> planes;
if(!(plrid == playernr))
{
std::cout << "player added" << playernr << plrid;
players[plrid] = plrid;
planes[plrid] = smgr->addMeshSceneNode(vliegtuigje);
}
But when I compile it VC++ give no errors or warnings. But when I start the game (and an other one -> creating new player in network) this code is "activated" and the program crashes.
Do you know an answer or is there another way to link playersid's to an object for exemple to do
Code: Select all
playerid->setRotation(core::vector3df(10,10,10));
Nadro
Posts: 1648 Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland
Post
by Nadro » Wed Sep 02, 2009 7:14 pm
You must usage Irrlicht core::array similar to std::vector, so when You created ISceneNode You have to push it on Your array eg:
Code: Select all
core::array<scene::ISceneNode*> planes;
ISceneNode * my_node = smgr->addMeshSceneNode(vliegtuigje);
planes.push_back(my_node);
for manage player You can create integer eg. PlayerID or someting and next:
Code: Select all
planes[PlayerID]->setPosition(vector3df(0,0,0));
dipi
Posts: 10 Joined: Tue Feb 26, 2008 6:16 pm
Post
by dipi » Thu Sep 03, 2009 8:09 am
It still crashes
B@z
Posts: 876 Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary
Post
by B@z » Thu Sep 03, 2009 8:39 am
are you sure that the playerID doesnt point out from the array?
for example you put players into the array like this
playerID = 0
pushback
playerID = 1
pushback
playerID = 2
pushback
then you remove the playerID 1, and you point the array as playerID 2
then it will crash, because
array[0]->playerID = 0
array[1]->playerID = 2
array[2] = NULL
you should make a variable what you can rely on
for example
Code: Select all
ISceneNode* myNode = smgr->addMeshSceneNode("something");
myNode->setID(playerID);
planes.push_back(myNode);
then later
Code: Select all
for (u32 i = 0; i < planes.array(); i++)
if (planes[i]->getID() == playerIDWhatYouWant)
{ do your things; break }
then it wont crass impo
JP
Posts: 4526 Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:
Post
by JP » Thu Sep 03, 2009 8:52 am
Just run your code in the debugger and it will be clear why it's crashing! You've not even provided us enough code to try and figure out the problem for you.
BlindSide
Admin
Posts: 2821 Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!
Post
by BlindSide » Thu Sep 03, 2009 10:23 am
Use core::map or std::map for this purpose. e.g.
Code: Select all
core::map<int, ISceneNode*> myNodeMap;
myNodeMap[playerId] = smgr->addMeshSceneNode(vliegtuigje);
ShadowMapping for Irrlicht!:
Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net