Game Development Community

Where to run initPersistFields() dependent functions?

by Steven Peterson · in Torque Game Engine · 09/17/2005 (3:30 pm) · 9 replies

I have a class that gets alot of it's initial class members from an initPersistFields() object. But there are several variables that are set by functions dependent on the first group of variables.

So these setMyVar(); functions have to be called pretty much right after initPersistFields(); What would be a good place / way of calling them?

I could put them in consoleObject.h around line 326 but since thats a very global space and these are class specific functions it just seems an inappropriet thing to do. [edit] Tried this, it doesn't compile that way [/edit]

I tried putting them in the class constructor but that seems to happen before initPersistFields is called (makes sense) so I don't get the right values.

Any Ideas?

thanks,
Raven

#1
09/17/2005 (3:58 pm)
Try onAdd()...if I follow what you are trying to do that would be a good place.
#2
09/17/2005 (4:08 pm)
Why cant you just do it right after iniPersistFields like you say...
#3
09/17/2005 (4:24 pm)
I'll look up onAdd() and give that a try. Sounds like it's what i'm looking for.

I tried after iniPersistFields, and it wouldn't even compile :-( dunno why really...
#4
09/17/2005 (6:26 pm)
InitPersistFields is called at static initialization time, WAY before any objects are actually created.

So you probably want to use onAdd() like Matt said.
#5
09/17/2005 (6:42 pm)
Ah ok :)
#6
03/05/2007 (11:40 pm)
Okay so while this is a really old thread, hopefully someone is watching as I've got a follow up question...

If onAdd() is where to call our "setter" functions, what happens when someone goes back into the World Editor to change one of these properties? How do we handle updating after the object has been created?

Thanks,

Ben
#7
03/05/2007 (11:50 pm)
Sorry for spamming the list. I think I answered my own question. inspectPostApply(), yes? I also assume we should call our setter function both in onAdd() and inspectPostApply(). Please correct me if I'm wrong.
#8
03/05/2007 (11:59 pm)
The addField() macro in initPersistFields() ties the script variables directly to the C++ variables so you don't need to "set" them when they are changed in the editor. *But* they will need to be persisted across the network to keep your server and client objects in sync. Generally this is done by setting one or more netflags in inspectPostApply() which triggers a packUpdate() and a corresponding unpackUpdate().

There are a couple good articles on TDN that go a lot further in-depth into the why/what of the networking.
#9
03/06/2007 (10:11 am)
Thanks a bunch Matt.