objGetUNID ?

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
ptbptb
Militia Lieutenant
Militia Lieutenant
Posts: 143
Joined: Mon May 10, 2010 7:34 pm

Is there a way to find the UNID of a given spaceObject ?

For example, the three types of Titanium Barricade 'station' all have the same name (Titanium Barricade) . I need to be able to tell which one you are docked to, and the UNID would be the obvious choice (to me).

I'm pretty sure I can work around it, but I thought I'd check first.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

http://xelerus.de/index.php?s=functions&function=256

objGetUnid would be a better name for it though. Maybe George will add it. I think all it would take is

Code: Select all

(setq objGetUnid (lambda (theObj) (
(if (objisShip theObj) (shpGetClass theObj) (staGetType theObj))
)))
in a global somewhere. No changes to the compiled code needed.
User avatar
ptbptb
Militia Lieutenant
Militia Lieutenant
Posts: 143
Joined: Mon May 10, 2010 7:34 pm

Atarlost wrote:http://xelerus.de/index.php?s=functions&function=256

objGetUnid would be a better name for it though. Maybe George will add it. I think all it would take is

Code: Select all

(setq objGetUnid (lambda (theObj) (
(if (objisShip theObj) (shpGetClass theObj) (staGetType theObj))
)))
in a global somewhere. No changes to the compiled code needed.
Thanks a lot! (and let the campaign for 'objGetUnid' begin :D )
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Having it in the engine would be better. For now it is just good to remember there are always differences between ships and stations. I agree that it could be clearer, but that would mean deprecating a bunch of functions (eg. if we moved to only obj* functions)
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

In this case, though, UNIDs are something both ships and stations have, and both are space objects. There's no reason to keep two separate functions that take the same arguments and return the same thing. What we've got now is like having to use different functions to add floats and integers. All languages I've seen that have both data types overload arithmetic functions.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

For example, the three types of Titanium Barricade 'station' all have the same name (Titanium Barricade) . I need to be able to tell which one you are docked to, and the UNID would be the obvious choice (to me).
If you want to uniquely identify an Obj, then you want to use the ID and not the UNID (multiple identical spaceObj have the same UNID but different ID)

SO the functions that I believe you need are:

(objGetID obj) -> objID
(objGetObjByID objID) -> obj
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Yeah, Digdug is right about that. If I may add something to that:

When you get a reference to an object (commonly referred to as a spaceObject) you have an integer (like 98273524) that points to a single object in the current system. Throughout the time in the system, this spaceObject can be used to refer to that particular object (unless it is destroyed, in which case that spaceObject becomes a dangerous value that can cause the game to crash if used). As soon as you leave the system, the value becomes invalid. In the system you enter, that number may or may not refer to an object. Never use spaceObjects across systems. If you return to the same system you had the spaceObject from originally, the object it was pointing to will most likely have another spaceObject, so again, don't use it across systems.

Now, if you want to have a unique pointer to an object that should last across the game, use the functions DigDug pointed to. the objID that you get from them is stable and can always be transformed into the spaceObject (if the object pointed to by the objID is in the current system). You can not use the objID for anything else than getting a spaceObject. It can in other words not be passed to functions in general.

.]
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

I don't think he wants a unique pointer. He said all three types of barricade have the same name. He wants to know whether a given barricade is single, double, or quad and the name doesn't tell him. UNID is exactly the right thing to use.
User avatar
ptbptb
Militia Lieutenant
Militia Lieutenant
Posts: 143
Joined: Mon May 10, 2010 7:34 pm

Atarlost wrote:I don't think he wants a unique pointer. He said all three types of barricade have the same name. He wants to know whether a given barricade is single, double, or quad and the name doesn't tell him. UNID is exactly the right thing to use.
Yep, you're right. You can see what I used it for in the Moveable Barricades mod. It turned out pretty nice, if I do say so myself. :wink:
Post Reply