Aller au contenu

Photo

Is their a StringToObject command?


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
Is their a cleaner way to do this? Is their a way to combine the last three lines?


string DROP1 = GetLocalString(OBJECT_SELF, "DROP1");//get item from VAR on mob
CreateItemOnObject(DROP1);//create item on mob
object SETFLAG1=GetItemPossessedBy(OBJECT_SELF, DROP1);
SetDroppableFlag(SETFLAG1, TRUE);//Make item droppable


((BTW: thanks for all the help.. Very glad to see the NWN1 forums still around and active.))

#2
Shadooow

Shadooow
  • Members
  • 4 471 messages
object SETFLAG1 = CreateItemOnObject(DROP1);//create item on mob

SetDroppableFlag(SETFLAG1, TRUE);//Make item droppable

#3
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
Just tested it and you have saved me a line! .. Thank you very much.

#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Hmm,  Am I missing something the Title here is.  " Is there a StringToObject command" 

The answer to that is No.  Well unless nwnx has one as an extention.  

There is a ObjectToString function.  But the only thing it really does to convert the dynamic object ID to a hex string. 

ShaDoOow did a good job of answering your question in the post. 
You could cut it down to one line if you wanted. 


   
SetDroppableFlag( CreateItemOnObject( GetLocalString(OBJECT_SELF, "DROP1") ) , TRUE);

#5
Shadooow

Shadooow
  • Members
  • 4 471 messages

Lightfoot8 wrote...
You could cut it down to one line if you wanted. 

SetDroppableFlag(CreateItemOnObject( GetLocalString(OBJECT_SELF, "DROP1") ) , TRUE);

Yes, it might be a little bit more effective but other scripters often critique this as its not very transparent and in case of bigger scripts it really not easy to understand such script and change/fix there something. I suggest a little compromise between two extremes :)

Also, there is a way to make StringToObject function without NWNX, I posted it in past into old scripting thread Homebrew functions. Basically I created a new ObjectToString function that except normal functionality saved the object on module at given string. So I was able to retrieve it later, however it works only on objects, that you convert into string first and I haven't been able to find a big usage for it myself so...

Modifié par ShaDoOoW, 08 février 2011 - 04:19 .


#6
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

ShaDoOoW wrote...

 So I was able to retrieve it later, however it works only on objects, that you convert into string first and I haven't been able to find a big usage for it myself so...


Yes,  That limitation make it about useless, The power of the function without that limitation would be a lot more powerfull.   For example, We know that the module itself is loaded as Object ID 0.  No great gain there we already have a function to retrive the module object.   The next object loaded however are the areas.  Object ID's 1- number of areas.    So if we had working function  StringToObject("00000001") would return the first area in the module.  you can see where that woud add some benifit. 

The only uses I have found for the ObjectToString function is either in Debuging odd problems.  Like the GetIsPCInArea function thread bad on the old BioBoards. 

Or for setting a unique LocalVar name on an Object. 
SetLocalInt(OBJECT_SELF,ObjectToString(GetPCSpeaker()),TRUE);

Modifié par Lightfoot8, 08 février 2011 - 05:08 .


#7
Baaleos

Baaleos
  • Members
  • 1 330 messages
nwnx_funcs does have a StringToObject function

basically scans memory for objects that have that offset, and then returns it as an object reference that is usable in nwscript.