Jump to content

Welcome to Obsidian Forum Community
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!




Photo
- - - - -

IntToObject

Posted by Rob McGinnis , 06 March 2007 · 1544 views

Scripting
By: Rich Taylor

This is just a quick note to mention that I've added:
object IntToObject( int nInt );

and

int ObjectToInt( object oObj );

scripting functions for 1.06.




Rob,

Can you tell us exactly what the integer produced by ObjectToInt represents?

Some things I would be curious about:

- Is this the unique identifier for the object?
- What happens when it is used on a stack?
- What happens when the stack is split and it is used against each half?
- If I copy an object, will the numbers returned be different?
What sort of Int should be valid for an Object? o_O

May be that a "free" use of IntToObject() would create only errors and bugs... uhm... I'm curious to see in what manner will be usefull to use that...
Photo
SpectralHare
Mar 15 2007 10:37 AM
Yeah, I am interested in this new addition as well. I was wondering whether unique objects (like PCs, for example) could be passed through the Obj->Int->Obj filter and have it work so that I could later use the Obj to affect the PC. Similarly with the PC's posessions (turn them to Ints, store the Ints on the PC and destroy the items, later recreate the posessions from the local Ints and give them back to the PC).

J
The ObjectToInt() script funciton is just data conversion. The 'object' engine type in the scripting language is really just an unsigned int. Converting the 'object' type to 'int' type doesn't do anything special other than let you now manipulate the object ID as an int.

For example:

object oPC = GetFirstPC();
int nPC = ObjectToInt( oPC ); //nPC now equals the PC's object ID
string sPC = IntToString( nPC );//sPC is now a string that equates to the PC's object ID.

If you copy an object, then that object has a new ID, so ObjectToInt() on the new copy will return a different numeric value.

All this function really does is give you script access to the actual IDs that uniquely identify objects.

I hope this helps explain it a little.

-Rich
Yes ok... but doubts are about IntToObject() .
Isn't risky to manage manually unique IDs?
Photo
Zarathustra217
Mar 17 2007 01:45 AM
Neat. If nothing else, I could imagine using it for cycling through all objects in a module when initializing it.
QUOTE(Patcha @ Mar 16 2007, 04:53 PM)
Yes ok... but doubts are about IntToObject() .
Isn't risky to manage manually unique IDs?

The main reason for IntToObject() is because of some of the new UI callbacks that can pass an object ID along as a parameter to the gui script. Object IDs can't be passed into an executing script, so you have to pass them in as ints and then convert them to objects via IntToObject().

There isn't really anything majorly risky about using IntToObject() on dummy numbers. The worst that will happen is that functions will treat that object the same as if you passed in INVALID_OBJECT. To be safe, you can always use GetIsObjectValid() on the result from IntToObject().

Hope this helps. :)

-Rich
This is cool. In a NWN1 project, I recently used a solution to a scripting problem that made me wish such a function existed. Instead, within each affected object's OnSpawn I assigned the object a random string from a combination of integers and hoped they'd never get duplicated.

March 2019

S M T W T F S
     12
3456789
10111213141516
17181920 21 2223
24252627282930
31      

Recent Entries

Recent Comments