Author Topic: Is their a StringToObject command?  (Read 558 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Is their a StringToObject command?
« on: February 08, 2011, 03:44:25 am »


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

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #1 on: February 08, 2011, 03:53:50 am »


               object SETFLAG1 = CreateItemOnObject(DROP1);//create item on mob

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

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #2 on: February 08, 2011, 04:03:29 am »


               Just tested it and you have saved me a line! .. Thank you very much.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #3 on: February 08, 2011, 04:09:42 am »


               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);
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #4 on: February 08, 2011, 04:18:03 am »


               

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 '<img'>

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 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #5 on: February 08, 2011, 05:06:01 am »


               

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 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Is their a StringToObject command?
« Reply #6 on: February 08, 2011, 02:26:59 pm »


               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.