Author Topic: When must resrefs be unique?  (Read 557 times)

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
When must resrefs be unique?
« on: November 17, 2011, 02:01:29 am »


               I was just glancing at a post in a thread on a different topic (this one) and noticed this:

When you make anything in NWN, area, placeable, item, it needs to have
its own unique resref. If you have multiple same resrefs you get
problems, just like you are experiencing.

Now I know that a module can have, for example, a creature and and item with the exact same resref (as I recently noticed when looking over Elidrin's scriptsfor figurines of wondrous power in RDG9f). So, what are the rules for resref uniqueness? I suspect that the restriction is that no two objects that have the same resource file type can have the same resref, because that might muck up how they are stored in the ERF format (used for ERFs, MODs, SAVs, etc.). So, one could have a creature (file type UTC) with the same resref as an item (UTI) and perhaps a store with the same resref as a merchant (UTM and UTC). Is that really how it works or is there some other known consideration that may cause trouble in a module if not observed?
               
               

               


                     Modifié par MrZork, 17 novembre 2011 - 02:04 .
                     
                  


            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
When must resrefs be unique?
« Reply #1 on: November 17, 2011, 02:47:47 am »


               I think you're right about how it works.  It seems to me the toolset is good about denying you the ability to make problematic resref duplications - so, you can't mess up.

<...thinking a little further>
 In scripting, if you want to reference an object, tags are generally used - so no confusion there.  And, if you're trying to create an object, CreateObject() requires you to specify the type of object you are creating (e.g. OBJECT_TYPE_PLACEABLE, OBJECT_TYPE_CREATURE, ..._STORE, ...ITEM) - so I don't think duplicate resrefs across resource types would confuse that either.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
When must resrefs be unique?
« Reply #2 on: November 17, 2011, 02:51:49 am »


               There are no rules for resrefs, at least not commonly agreed ones. Each PW has its own and I havent seen anyone mention same resrefs for different object. The advice you quoted is pointed to the importing and overwriting issues, this doesnt happen with this. There shouldnt be any issues with this unless there is some custom content tag-based scripting system for both creature and item for example. But I do use same resrefs for things that are related to each others without any issues. But you should give them different tags otherwise you wont be able to use GetObjectByTag and similar tag based functions properly or you would have to always check object type.
               
               

               


                     Modifié par ShaDoOoW, 17 novembre 2011 - 02:53 .
                     
                  


            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
When must resrefs be unique?
« Reply #3 on: November 17, 2011, 05:01:04 am »


               There are no rules for resrefs, other than the toolset will not let you make same resref things. You can't have 2 areas with resref area1, or 2 items with resref item1. If you import a already used resref, it will ask you if you want to overwrite what you have. What that translates to, is you can have one blueprint for an item with resref item1, however you can have 16000 instances of it in your mod. Its the same blueprint, so its only 1 resref.

What resref is for, is the blueprint. Think of it as that. For scripting, you may want to get item by tag, or area, or whatever, but if you want to spawn in something, your going to want to use the blueprint. The reason is simple, there can be only 1. even if you spawn it in 16000 times.

Some new builders can get hung up on this, and it can be a hard lesson to learn. The thing I have found over the years, is, make the blueprint, place the blueprint in the mod if that is what your plan is,
And, if you need to change it, do so in the pallet, not where you placed it. The update instances, to effect changes. the reason is simple, changing it in the mod, does not transfer back to the pallet.

I copy the resref to the tag for my items, placeables, merchants, and if needed triggers. The reason is simple, if less to figure out later when scripting is added. Just about everyone here that builds, will tell you they have their own "naming conventions" that they use. Some maybe better than others, But most are comfortable for the one who uses it. I tend to make all my items that are tag based scripting, have the oai_ prefix. it just helps keep things neat.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
When must resrefs be unique?
« Reply #4 on: November 17, 2011, 05:04:32 am »


               

MrZork wrote...
 I suspect that the restriction is that no two objects that have the same resource file type can have the same resref, because that might muck up how they are stored in the ERF format (used for ERFs, MODs, SAVs, etc.). So, one could have a creature (file type UTC) with the same resref as an item (UTI) and perhaps a store with the same resref as a merchant (UTM and UTC). Is that really how it works or is there some other known consideration that may cause trouble in a module if not observed?

Yes, that's how it works. The only other relevant thing you MUST do is name your item script the same thing as the items TAG, IF and ONLY if you are using tag-based scripting. 

On HG, we find it handy to name all the things in the same area group with the same prefix for ease of finding and ease of mass editing, but that's a matter of convenience, not one of necessity.

Funky
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
When must resrefs be unique?
« Reply #5 on: November 17, 2011, 07:23:21 am »


               Thanks for the very clear responses, everyone. It seems I was thinking about this correctly. I just wanted to make sure there wasn't some other complexity to look out for. Or to exploit! ;-)