Game Development Community

Shared Engine/Script variable of type 'object'?

by David Schwanke · in Torque Game Engine · 06/17/2004 (2:11 pm) · 6 replies

Not sure if I said that right.

I get long winded so I bolded the questions that are direct to the point.

In the link here I asked about making a linked list in script and actually about sharing this list between the engine and the scripting.

The thread got a little sidetracked (in a cool way though. :D) but I thought it might make more sense to ask this question in a simpler form here:

Is there a way to declare an object in the class/engine code and have it transfer as a minupulatable field in the script code?

That is, can I do something similar to declaring in the class:

Item anItem;

and then someway get intPersistFields to addField anItem?

I didnt see any references of this type anywhere in the addFields in the engine code so I suspect not.

If not, would it work then to cheat and write a consoleFunction addAnItemObject(obj); to pass the object to the class and set it? (I see objects get passed through console functions such as the console function isObject(object);)

Would then the engine be able to use everything that was stored in that object? Even stuff only defined by scripts? Or would it loose some granularity of information because its no longer in the scripting domain? (Like If I create an Item then change the Item properties, add new fields, etc, do those fields get transfered? Or are they lost?)

If I did this, I presume for the pack and unpack Update functions I would have to include a read/write(object) if i wanted to have this object passed to the client.

Can you read/write an entire object via the bitstream?

#1
06/17/2004 (3:52 pm)
To answer your questions:

Is there a way to declare an object in the class/engine code and have it transfer as a minupulatable field in the script code?

Of course. There's a TypeSimObjecPtr for this very reason.

Would then the engine be able to use everything that was stored in that object? Even stuff only defined by scripts?

Check out SimFieldDictionary. Because of the nature of C++ as a compiled language, you can't access them as real fields but you can look up values given a key.

Can you read/write an entire object via the bitstream?

Every object is responsible for its own serialization. So you'll have to write pack/unpack stuff for anything you want to move over the network.

You should really take some time to get familiar with NetObjects before you worry too much about passing objects over the network.
#2
06/17/2004 (4:33 pm)
Well I dont really know how to get familiar with anything without trying to just do something with it. Unfortunately reading code for the sake of reading code doesnt do anything for me usually. Especially around here when the code is so deep in extensions that the only thing I recognize is the braces :D.

TypeSimObjectPtr and even SimFieldDictionary are virtually unused in the default engine code so I dont really have any way of 'learning them' through example and as I took a look at the source they seem to be a bit way over my head to learn just by reading. (Hashtables scare me. :D)

I might be able to fake TypeSimObjectPtr just because it seems intuitive for some reason. (Declare ptr, modify associated initPersists and packs/unpacks). Only question is, does the referenced object need to have its own pack/unpack called or is it automagically ghosted by virtue of being inside of another ghosted object? I'm guesing by your serializatoin comment that I have to somehow manually ghost the sub objects. But I think I can wait on that code for a while since haveing the client access the data was a future endeavor in the development plan anyway.

The hard part is that the objects I'm having to ghost to the client are never visible in the client so they dont fall under the standard scoping rules. I have to manually scope them to the client.

Thanks for the insight though. More is welcome. :D
#3
06/17/2004 (9:29 pm)
SimFieldDictionary are actually used in several places - most importantly, the GUI code. The script engine also uses it. Quite frankly, it's REALLY easy to use. Tried doing a forum search on the word? You get three hits, one of which is this, which contains a pretty good example.

Why the heck do you want to FAKE TypeSimObjectPtr? That's like faking an unsigned integer. Just make a member that's of type SimObjectPtr and you're set.

I think you really need to read the engine overview and maybe the Tribes 2 networking white paper. I believe I posted links to the one in another reply to you. The whitepaper is at www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=331. You can learn a LOT more about the networking model by reading the TNL docs (which don't entirely apply, but are pretty close) - you can find them at www.opentnl.org.
#4
06/18/2004 (11:14 am)
Fake had nothing to do with the code. I meant fake as in "I'm sure I can figure it out if I try hard enough and I might not always understand what I'm doing but it will work."

:D

Thank you for this extra help by the way and the willingness to post mutliple places. And at this point thank you for putting up with my rant in the other forum if you dont decide to give me the boot for being such a schnozz.

I did do a forum search on SimFieldDictionary and I dont know why I didnt get that link. Since it would sound stupid to say "Are we sure the forum search works?" :D I am going to assume its more of that elusive bug in my own search system.

Well I just redid the search and I figured a good guess as to why.

"FxShapeReplicator" doesnt mean anything special to me. A question on it has no real relationship to my question that I can see. If I had done that search after having done about 5 other searches on SimSets SimGroups TypeSimObjectPtrs and anything else I was searching that day, I probably would not have given it enough weight to dig into the thread. Especially since the mention of SimFieldDictionary didnt occur until half way down the thread.

I guess thats a new trick I can add. I didnt think until now to try to search for the search word in the forum thread and look for it there. I was just assuming that the forum gave a false positive or someone was giving a one word "have you lookd at" again. :(
#5
06/18/2004 (11:15 am)
I'm learning, slowly. :D
#6
06/18/2004 (3:12 pm)
That's good. Otherwise we'd have to consider you insane. :P