Jump to content
  • entries
    74
  • comments
    426
  • views
    1446507

IntToObject


Rob McGinnis

2765 views

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.

8 Comments


Recommended Comments

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?

Link to comment

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...

Link to comment

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

Link to comment

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

Link to comment
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

Link to comment

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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...