Jump to content

[LE] Help with renaming lots if items with the same alias on saved game reload


Recommended Posts

Hello,

 

Long post incoming, sorry for that, but unfortunately every detail matters.

 

The aim:

Every now and again, on a periodic update, Books which contain text replacement are spawned in (max 5 at a time, and later sent to the player). The aim is to rename the title of these books from the script that spawns them and then for them to keep this name throughout the game.

The number of books spawned is indefinite, as it depends on player input.

 

The method:

Because the books contain text replacement, SetDisplayName() will not work on them correctly according to this thread, and I too can confirm that text replacment gets broken if SetDisplayName is used on it.

 

Therefore the only alternative I know for renaming is using aliases and message titles.

Because the overall number of Books is definite, it's not really possible(*) to create an alias for each and store them permanently. They must be cleared and be re-used for the next cycles.

 

 

So we have a Message, and a TitleSetterAlias on a quest, and the Message is set as the display name for this alias. Clears name when removed is unchecked. The renaming after the spawning then happens like this:

MessageProperty.SetName("title for the next book")
TitleSetterAlias.ForceRefTo( bookReference)
Utility.WaitMenuMode(0.2)
TitleSetterAlias.Clear()

The problem(*) with this: because the Books share the underlying MessageProperty as their names, when several are spawned in together, they each get the title of the last one renamed.

Elaborating on this:

 

 

Let's say we spawn 3 books, they have titles: titleA, titleB, titleC.

We spawn book 1, set message to titleA, and fill the alias. The name of the message is titleA, so the alias renames the book to the message name, titleA. Alias is cleared.

We then spawn book 2 and set message to titleB. The name of the message is now titleB, and the name of book 1 is the message, so it's now titleB. Reusing the message also renames book 2 to the message, titleB.

Book 1 is now mixed up, Book 2 is correct.

We then spawn book 3 and set message to titleC. Both books 1 and 2, whose name is the message, get renamed to titleC. Reusing the alias renames book 3 to titleC.

 

In the end, all books get renamed to titleC.

 

 

 

This problem was possible to overcome by having 5 aliases and 5 messages (since the max number of books spawned at the same time is 5), and each gets its own alias.

 

Surprisingly enough, when the next cycle comes, and the next bulk of books get spawned in and renamed, the books from the first cycle keep their name. Even though now book 1 from cycle 1 shares the Message with book 1 from cycle 2, their displayed name in the game is different and correct.

Now to be clear, I'm not exactly sure why this works. The minimum interval for these cycles is 24 in-game hours.

 

 

The Problem:

The unsolved problem lies with saved game reloads. SetName() for the Message is not kept between saved games, that's a fact, so each Message returns to their starting CK name on a save reload, and thus each book also resets to this default CK name (of their respective underlying Message).

 

Triggering an update on names is not a problem, they are stored as strings, also the objectreferences of the books are available for the event when a saved game is loaded. No issue with that.

 

The problem lies with the Book names getting mixed up all over the place because of their shared messages, similar to what I described at (*).

Because if I refresh the name of Message1 to titleA, all books that share this as their name will display title1.

For example, let's say we have:

Book number 1 with underlying MessageA and supposed titleA from cycle 1

Book number 1 with underlying MessageA and supposed titleB from cycle 2

Book number 1 with underlying MessageA and supposed titleC from cycle 3

 

If I rename MessageA to titleA for the first book, since it is used by all first books from all cycles, all three of them get renamed to this, which is incorrect, since they each have their own titles.

The same is true for book number 2, 3, 4, and 5.

 

 

I tried several things, like waiting time between renamings, forcing the books in and out of aliases to get them to forget "their past association" with their Message, and get new ones, similarly how the spawning works. But for now, no matter how I tried to shuffle the aliases, I couldn't get it to work consistently.

It's important that here it's not possible to wait 24 in-game hours between alias shuffling and message renaming, like in the case of the cycles at (*). That was possible for the spawning of the books, but this is a saved game reload, and this is about maintaining the existing books, which should be performed as quickly as possible.

To experiment, I tried waiting as long as up to half a minute real time though. It did not work, renaming the message still affected the other books it shared.

 

 

So at the moment the only solution I see is to indeed have as many aliases and messages as there are books. (*) It's not true that this is not possible, but it's immensely inconvenient. Because their number is indefinite, the number of aliases and messages would have to be 128, the hard limit for the arrays which the scripts use. (and also thus the theoretical hard limit for books). But then each book would have its own message and alias, leaving no room for confusion.

However, I don't want to flood my mod with 128 aliases on a quest and 128 messages, unless absolutely necessary.

 

If someone has any idea about how to fix the saved game updates, that'd be a huge welcome!

And thanks for reading the post :smile:

Link to comment
Share on other sites

Workaround as follow:

- create a master quest with one alias wich refers to the player, use script with event OnPlayerLoadGame() for update

- create a quest with five aliases for messages you need

- duplicate this quest as many as you need to spawn books, so you have mutiple quests and each has five aliases; they may be filled with ObjectReference or not

- create a new script for the aliases to hold the message and the string

- use an array to store the quests

 

ww42BookAliasScript

 

Scriptname ww42BookAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/10450638-help-with-renaming-lots-if-items-with-the-same-alias-on-saved-game-reload/

  Message PROPERTY Bookmessage auto
  String  PROPERTY Bookname    auto

 

 

 

next script is only a base, not fully working for your aim.. and it's using function GetAlias() which required to adjust the alias numbers (if not in order from 0..4 or 1..5)

 

ww42MSGUpdatePlayerAliasScript

 

Scriptname ww42MSGUpdatePlayerAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/10450638-help-with-renaming-lots-if-items-with-the-same-alias-on-saved-game-reload/

  Quest[] PROPERTY myQuests auto    ; filled by CK with the quest you have created
 
  Bool bUpdate   ; [default=False]


; -- EVENTs -- 3

EVENT OnInit()
    Debug.Trace(" OnInit() - has been called for .. " +self)
    RegisterForSingleUpdate(1.0)
ENDEVENT

EVENT OnPlayerLoadGame()
    bUpdate = TRUE
    Debug.Trace(" OnInit() - has been called for .. " +self)
    RegisterForSingleUpdate(1.0)
ENDEVENT


EVENT OnUpdate()
    IF ( bUpdate )
        myF_Action()
    ENDIF
ENDEVENT


; -- FUNCTIONs --

;--------------------
FUNCTION myF_Action()
;--------------------
    int n = myQuets.Length            ; get array length

int i = 0
    WHILE (i < n)
        quest q = myQuets[i]
        IF ( q )                ; && q.IsRunning()

            int j = 0
            WHILE (j < 5)
                referenceAlias RA = q.GetAlias(j) as ReferenceAlias        ; make sure "j" as alias number is valid !!!
                IF ( RA )
                    objectReference oRef = RA.GetReference()
;;                    IF ( oRef )
                    
                    message m = (RA as ww42BookAliasScript).Bookmessage
                    string  s = (RA as ww42BookAliasScript).Bookname
                    
;;                    ENDIF
                ENDIF
                j = j + 1
            ENDWHILE

        ENDIF
        i = i + 1
    ENDWHILE
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Thanks, but I fail to see how that's still not just making an alias for each Book.

I'd still have make 128 messages and 128 aliases, only difference is that they'd be in groups of 5 on 26 quests. The method of duplicating quests may speed up the process of creating them, but I don't see what other advantages this would have over just putting 128 alias on 1 quest.

I'd also still have to manually set each alias to its respective message.

 

If possible I'd like to make it work by reusing the same aliases and messages, like during the spawning.

If no such workaround is possible, then yeah, I guess this is what we have.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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