Jump to content

Rename an object reference


Recommended Posts

Hi people. I'm working on a little mod, and I'm having problems with something. Basicly, I need to rename a container when I put a specific item inside, and restore the name when the item is not longer present. The item already has a script attached, but this has to work with any container in the world. I looked for answers on the internet, and I found two ways to do this:

The first option is to use a Reference Alias. As far as I know, If I create a quest with an alias, any reference attached to that alias will take it's properties, including the name. However, I don't know how to attach an object reference to an alias dynamically, and also I don't know if I can attach the same alias to more than one reference. I could use "Find Matching Reference" as described in this tutorial: https://www.creationkit.com/index.php?title=Dynamically_Attaching_Scripts , but this requires me to refresh the quest constantly, and that will probably reset the name of the reference for an instant every time I restart the quest. Isn't there a way to attach a reference to an alias with a script function?

The other option is to use SetName(), a function of F4SE, but that changes the name of the base object (an thus all the references). There's also a SetDisplayName(), but It's not documented, so I don't know how it works.

Any other ideas?

Link to comment
Share on other sites

An object can be held by as many aliases as you want. For example, an actor can be placed in 10 aliases on the same quest. And you can conditionalize aliases to not be filled by the same reference as another alias.

 

ForceRefTo is the scripting function to force an object into in the called alias. http://www.creationkit.com/index.php?title=ForceRefTo_-_ReferenceAlias

Edited by Lisselli
Link to comment
Share on other sites

An object can be held by as many aliases as you want. For example, an actor can be placed in 10 aliases on the same quest. And you can conditionalize aliases to not be filled by the same reference as another alias.

 

ForceRefTo is the scripting function to force an object into in the called alias. http://www.creationkit.com/index.php?title=ForceRefTo_-_ReferenceAlias

Yeah but the problem with aliases is that they can hold only one reference at a time, so If I want to rename 10 objects, I need 10 aliases, or I need to script a way to dynamically change the reference every few ticks.

 

However, I found another solution. There's a function called ApplyToRef, which applies the Alias data to an Object Reference, without pointing the Alias to that reference. This allows you to have more than one object using the data from a single Alias. The data can be removed with RemoveFromRef. If the Alias was flagged to clear names on removal, the name of the reference will be restored when the Alias data is removed. Keep in mind the Alias has to be flagged so it can apply data to non-aliased references. These functions seem to be new to Fallout 4, as they are only documented in the Fallout 4 part of the CK wiki.

 

I did a quick test and those functions effectively allow me to rename an infinite amount of objects with the same alias. I don't know if there are other risks or side effects of these functions, but for now it seems to be exactly what I need. Anyway, thanks for the reply.

Link to comment
Share on other sites

I believe RefCollections can hold more than one reference

 

Oh, I forgot about RefCollections, I never use them. I tested it and it works fine too, it's probably better than using ApplyToRef because I can clear the alias anytime, restoring all the names. The only limitation is that you can't have more than 255 references in a RefCollection, but that probably won't be a problem. Thanks again Lisselli.

Link to comment
Share on other sites

 

I believe RefCollections can hold more than one reference

 

Oh, I forgot about RefCollections, I never use them. I tested it and it works fine too, it's probably better than using ApplyToRef because I can clear the alias anytime, restoring all the names. The only limitation is that you can't have more than 255 references in a RefCollection, but that probably won't be a problem. Thanks again Lisselli.

 

 

Nothing says you have to only use 1 RefCollection. Though depending on the code scenario using more than 1 might be cumbersome.

 

I saw a mod before that did that. I forget the name of the mod I looked at, but the quest it used had something like 30 RefCollections. I didn't look at the script but I'd presume it used an array of the RefCollections. Then a custom lookup function that just cycled through them all till it found the one it wanted and returned a single RefAlias. A custom setting function just looking at the sizes as it looped the array looking for a free spot. Then a removal function doing the same.

 

I'd arguably say anyone needing to house that many Ref's at once might have other concerns. Specifically regarding persistence.

Edited by BigAndFlabby
Link to comment
Share on other sites

 

 

I believe RefCollections can hold more than one reference

 

Oh, I forgot about RefCollections, I never use them. I tested it and it works fine too, it's probably better than using ApplyToRef because I can clear the alias anytime, restoring all the names. The only limitation is that you can't have more than 255 references in a RefCollection, but that probably won't be a problem. Thanks again Lisselli.

 

 

Nothing says you have to only use 1 RefCollection. Though depending on the code scenario using more than 1 might be cumbersome.

 

I saw a mod before that did that. I forget the name of the mod I looked at, but the quest it used had something like 30 RefCollections. I didn't look at the script but I'd presume it used an array of the RefCollections. Then a custom lookup function that just cycled through them all till it found the one it wanted and returned a single RefAlias. A custom setting function just looking at the sizes as it looped the array looking for a free spot. Then a removal function doing the same.

 

I'd arguably say anyone needing to house that many Ref's at once might have other concerns. Specifically regarding persistence.

 

 

Yeah, in my case the containers can be renamed to 18 different names, so I have 18 RefCollectionAliases. I doubt players would have more than 255 containers of the same type, and since the Alias is just there to change the names, the worst that could happen if they go over the limit is that the containers stop renaming, while the rest of the mod works fine. Just in case I could add an extra RefCollection for every name, and do a simple check to add the reference to the second one if the first is full, but no more than that.

Edited by MaxShadow09
Link to comment
Share on other sites

You don`t really need to keep them in alias all the time. There is an option in alias that allows to rename things. You create a message and set it title to any name you need. Then in alias you select the message as alias name and check "stores text" and "uses stored text" ( maybe only of them is necesserary to check, but I checked both). Then you can clear the alias but the reference will stay renamed.

Link to comment
Share on other sites

Yeah but then I can't restore the name, and I need that to be possible. I have to flag the alias to clear names when the ref is removed. I haven't tried it yet, but perhaps if I do what you say, and then I try to add the reference to another alias with "<BaseName>" as text, it would restore it's original name. That way I would only need two aliases.

Edited by MaxShadow09
Link to comment
Share on other sites

Yeah but then I can't restore the name, and I need that to be possible. I have to flag the alias to clear names when the ref is removed. I haven't tried it yet, but perhaps if I do what you say, and then I try to add the reference to another alias with "<BaseName>" as text, it would restore it's original name. That way I would only need two aliases.

This is exactly what I meant. You can use aliases to rename things/npc back. I have not tested it with renaming a reference multiple times, but I suppose it should work the same way. I used this way to make some nameless objects interactive ( who would think it`s possible). Though if you use it on a nameless object it will still look nameles, but you will be able to activate it.

Edited by kitcat81
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...