Sending Datablocks
by Fabio Luis Stange · in Technical Issues · 03/06/2007 (10:34 pm) · 0 replies
I have created a new datablock, but the client is never receiving it. The client running in the same machine as the server can correctly echo(TestCard.name), but the remote client never receives the data. I've read somewhere that ALL datablocks are automatically sent to the client on mission load; is this only for datablocks actually used by a StaticShape or other game entity on the mission? Am I missing something here, or should the following code do the trick?
This code is run on the server:
This is the C++ code:
initPersistFields was called once, the constructor was called 3 times (both on the server and on the client)
This code is run on the server:
datablock PangaCardData (TestCard)
{
name = "Test";
};This is the C++ code:
class PangaCardData : public SimDataBlock
{
typedef SimDataBlock Parent;
public:
StringTableEntry mName;
// ...
PangaCardData();
static void initPersistFields();
void packData (BitStream* stream);
void unpackData(BitStream* stream);
DECLARE_CONOBJECT(PangaCardData);
};//...
IMPLEMENT_CO_DATABLOCK_V1(PangaCardData);
PangaCardData::PangaCardData() {
mName = "";
}
//--------------------------------------------------------------------------
IMPLEMENT_CONSOLETYPE(PangaCardData)
IMPLEMENT_GETDATATYPE(PangaCardData)
IMPLEMENT_SETDATATYPE(PangaCardData)
void PangaCardData::initPersistFields() {
Parent::initPersistFields();
addField("name", TypeCaseString, Offset(mName, PangaCardData));
}
void PangaCardData::packData(BitStream* stream) {
Parent::packData(stream);
stream->writeString(mName);
}
void PangaCardData::unpackData(BitStream* stream) {
Parent::unpackData(stream);
mName = stream->readSTString();
}initPersistFields was called once, the constructor was called 3 times (both on the server and on the client)