Rabishan
Member
|
saving/loading problem
hi everyone,
i get problem loading the objects from Enemy class.
Code:
void Enemy::save(File &f){
if(alive){
super::save(f);
}
}
Bool Enemy::load(File &f){
if(super::load(f)){
return true;
}
return false;
}
the save seems to work properly. but when loading, super::load(f) always returns false. i have other classes like npcs and players(both of them inherits from same class as enemy) and they all load properly. but in case of enemy it does not load.
Anyone might have any idea about what might be causing this.
thanks in advance,
|
|
04-10-2013 01:00 PM |
|
fatcoder
Member
|
RE: saving/loading problem
Possibly has something to do with that if(alive) statement in the save() function. When reloading it cannot check if the object was alive or not before loading, so it may end up reading incorrectly. I could be wrong as I don't know the rest of your code.
|
|
04-10-2013 03:29 PM |
|
Rabishan
Member
|
RE: saving/loading problem
hi fatcoder,
It was like you said. but its from Enemy Item class. Since it cannot load the Enemy Item, loading of Enemy fails too. I choose not to save the Items unless it is from Players as in the code below. But while loading it tries to load unsaved items too. So do you know what should i do to save only selected items.
Code:
void DummyItem::save(File &f){
if(owner && owner->type()==OBJ_PLAYER){
super::save(f);
}
}
Bool DummyItem::load(File &f){
if(super::load(f)){
return true;
}
return false;
}
|
|
04-11-2013 07:41 AM |
|
fatcoder
Member
|
RE: saving/loading problem
To be honest, you should be letting EE decide what to save. Having conditional saving (i.e. the if statement in your save) is a no no. You will end up with a discrepancy between the number of objects EE "saved" and what actually got saved, which will screw your loading.
If there is stuff you don't want saved, you need the logic outside the saving, before you even call save. How you do that is going to be up to you and your specific situation.
|
|
04-11-2013 11:57 AM |
|
Rabishan
Member
|
RE: saving/loading problem
Quote:To be honest, you should be letting EE decide what to save. Having conditional saving (i.e. the if statement in your save) is a no no. You will end up with a discrepancy between the number of objects EE "saved" and what actually got saved, which will screw your loading.
yeah that is what happening now. guess i will be saving everything then.
thanks for the help fatcoder.
|
|
04-11-2013 12:20 PM |
|