Author Topic: Issues accessing a location's variables  (Read 245 times)

Legacy_Ckrauser

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Issues accessing a location's variables
« on: September 30, 2014, 07:38:51 am »


               

I am trying to manipulate a location's field, but keep getting errors. The compiler throws an error when I try to manipulate a vector given a location



location crate_1_loc = GetLocation(GetObjectByTag("crate_1"));
crate_1_loc.vPosition.x += 1.0; // This is not valid

The error is:


ERROR: LEFT OF STRUCTURE PART NOT STRUCTURE


 


I noticed on the NWNwiki and the NWN lexicon, they specifically say that the vector can be manipulated using the dot operator, but it doesn't say whether it's possible for a location. I can take the long way around by getting the object's vector, manipulating that, then creating a location from there; but I was curious if using the dot operator on a location is even possible.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Issues accessing a location's variables
« Reply #1 on: September 30, 2014, 08:05:34 am »


               

location crate_1_loc = GetLocation(GetObjectByTag("crate_1"));


vector v = GetPositionFromLocation(crate_1_loc);
v.x += 1.0;


crate_1_loc = Location(GetAreaFromLocation(crate_1_loc),v,GetFacingFromLocation(crate_1_loc));


 


etc.


 


could be wrote differently but now you see whats needed



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Issues accessing a location's variables
« Reply #2 on: September 30, 2014, 08:19:42 am »


               

To the best of my knowledge, you have to go the long way round, using GetPositionFromLocation to extract the vector, and the Location function to build the new location from the modified vector.


 


The vector structure certainly has fields .x .y and .z of type float. I don't think the location structure format has been published, nor is it trivial to deduce the field names. I imagine it might well contain a field of type vector.


 


Incidentally, if anyone does know the format of the internal structures, it would be useful to know.


 


EDIT : What Shadooow said.



               
               

               
            

Legacy_Ckrauser

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Issues accessing a location's variables
« Reply #3 on: September 30, 2014, 08:30:35 am »


               

Hmm ok thanks for the replies. I would assume it could be accessed, but as you said it's not something that can be deduced very easily. I've tried the obvious variations on vPosition, but none of them work. I'm using code similar to what Shadooow posted and it works fine, so I'll stick with that for the time being.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Issues accessing a location's variables
« Reply #4 on: September 30, 2014, 05:21:04 pm »


               

Location is a custom struct with different data types buried within it. NWN has a few of these and you need to access them using the functions provided with the script engine. So with location you need to extract the three pieces of data (each a different type) and then work with them independently. Then you use the Location function to plug them all back in again.