Game Development Community

Item:: and %this.pickupName question

by Ralf Babbel · in Torque 3D Professional · 02/15/2010 (10:07 am) · 5 replies

file: scripts/server/item.cs

could someone explain to me why in the function Item::respawn
the %this.pickupName is always empty string and in Item::onPickup
its filled correctly?

thanks,
ralf

About the author

Recent Threads


#1
02/15/2010 (10:21 am)
I doubt that the respawn function has a pickup function related variable filled.
#2
02/15/2010 (10:28 am)
ok... so i missed here something, i thought this is all object oriented.
#3
02/15/2010 (11:57 am)
Hi Ralf,

This kind of thing always confused me at first, but it is to do with the difference between datablocks and objects. Datablocks are persistent (i.e. once they are loaded they exist until explicitly deleted and are not automatically deleted at unload of mission), while objects are not (i.e. they are often deleted and added during the game, and are deleted at unloaded of mission). This means that many object instances can use the same persistent datablock, so the datablock data may not be unique to the object.

Have a close look at the class of each function; you will notice the Respawn function is an object function (Item::respawn) and onPickup is a datablock function (ItemData::onPickup).

The script variable %this always refers to the class instance of the function, so in ::respawn it is the object instance and in ::onPickup it is the datablock. The pickUpName field is contained in the object's datablock, so in the respawn function you would need to get the id of the object's datablock to retrieve it (i.e. %this.getDatablock().pickUpName ).

Hope this helps
#4
02/15/2010 (12:23 pm)
just checked that with the debugger and now this all makes more sense to me. just that i need to get used to it :/

thanks david!
#5
02/15/2010 (12:32 pm)
No problem. Happy to help.