Author Topic: Embedded variables and retrieval from profile  (Read 2712 times)

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Embedded variables and retrieval from profile
« on: May 04, 2021, 10:11:09 PM »
I have added a number of voices to Windows TTS, and I am trying to assign these voices to incoming messages in E:D and have them be persistent.  EDDI provides the variable
Code: [Select]
{TXT:EDDI message received from} and so I am trying to use an embedded
Code: [Select]
{TXT:{TXT:EDDI message received from} voice} which is set to one of the voices randomly and saved to the profile.

Even though I include a
Code: [Select]
Set text [{TXT:{TXT:EDDI message received from} voice}] to [Saved Value]
, the assigned voice doesn't persist across sessions.  When I start a new game session, the voices are reassigned.

My expectation is that there would a variable
Code: [Select]
{TXT:The Jet's Hole voice} or
Code: [Select]
{TXT:Cruise ship voice} saved to the profile that equals "David" or "Hazel" or whichever voice was originally assigned.

The goal is that every time I visit George Lucas or whichever station, or encounter the cruise ship or other NPC, the voice is the same.

Here is the entire command:

Code: [Select]
Append, ' {TXT:EDDI message received from}' to file 'C:\Users\username\Documents\message received.txt'
Begin Boolean Compare : [{EDDI message received player}] Equals False
    Set text [{TXT:{TXT:EDDI message received from} voice}] to [Saved Value]
    Say, 'Message from {TXT:EDDI message received from}'  (and wait until it completes)
    Begin Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Not set'
        Set integer [Voice used] value as random from 0 to 24
        Begin Integer Compare : [Voice used] Equals 0
            Set text [{TXT:EDDI message received from} voice] to 'David' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 1
            Set text [{TXT:EDDI message received from} voice] to 'Hazel' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 2
            Set text [{TXT:EDDI message received from} voice] to 'Zira' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 3
            Set text [{TXT:EDDI message received from} voice] to 'Catherine' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 4
            Set text [{TXT:EDDI message received from} voice] to 'George' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 5
            Set text [{TXT:EDDI message received from} voice] to 'Heera' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 6
            Set text [{TXT:EDDI message received from} voice] to 'James' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 7
            Set text [{TXT:EDDI message received from} voice] to 'Linda' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 8
            Set text [{TXT:EDDI message received from} voice] to 'Mark' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 9
            Set text [{TXT:EDDI message received from} voice] to 'Ravi' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 10
            Set text [{TXT:EDDI message received from} voice] to 'Richard' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 11
            Set text [{TXT:EDDI message received from} voice] to 'Sean' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 12
            Set text [{TXT:EDDI message received from} voice] to 'Susan' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 13
            Set text [{TXT:EDDI message received from} voice] to 'Eva' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 14
            Set text [{TXT:EDDI message received from} voice] to 'Matilda' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 15
            Set text [{TXT:EDDI message received from} voice] to 'Cosimo' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 16
            Set text [{TXT:EDDI message received from} voice] to 'Hedda' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 17
            Set text [{TXT:EDDI message received from} voice] to 'Stefan' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 18
            Set text [{TXT:EDDI message received from} voice] to 'Helena' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 19
            Set text [{TXT:EDDI message received from} voice] to 'Hortense' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 20
            Set text [{TXT:EDDI message received from} voice] to 'Julie' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 21
            Set text [{TXT:EDDI message received from} voice] to 'Katja' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 22
            Set text [{TXT:EDDI message received from} voice] to 'Laura' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 23
            Set text [{TXT:EDDI message received from} voice] to 'Pablo' (save value to profile)
        Else If Integer Compare : [Voice used] Equals 24
            Set text [{TXT:EDDI message received from} voice] to 'Paul' (save value to profile)
        End Condition
    End Condition
    Append, ' {TXT:{TXT:EDDI message received from} voice}' to file 'C:\Users\username\Documents\message voice.txt'
    Begin Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'David'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Hazel'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Zira'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Catherine'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'George'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Heera'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'James'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Linda'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Mark'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Ravi'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Richard'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Sean'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Susan'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Eva'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Matilda'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Cosimo'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Stefan'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Hedda'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Hortense'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Helena'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Julie'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Katja'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Laura'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Pablo'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    Else If Text Compare : [{TXT:{TXT:EDDI message received from} voice}] Equals 'Paul'
        Say, '{TXT:EDDI message received message}'  (and wait until it completes)
    End Condition
End Condition

Each of the "Say" commands is set to the corresponding voice.

The two write to file commands are to test the message sender vs voice assigned.

Any help is appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: Embedded variables and retrieval from profile
« Reply #1 on: May 04, 2021, 10:46:31 PM »
You're using the correct syntax when setting the variable, and when checking whether the variable has been set, but not when retrieving its value from the profile.

E.G. if the variable "EDDI message received from" has a value of "bob", you then set a variable with the name "bob voice" (which is what "{TXT:EDDI message received from} voice" will render as) to "David", and then save the variable "bob voice" to the profile.

However, when later retrieving the variable, you attempt to retrieve the value of a variable named "David", as that is what "{TXT:{TXT:EDDI message received from} voice}" will render as, because it retrieves the value of the variable "EDDI message received from" (which, again, let's say is "bob"), and then retrieves the value of the variable named "bob voice", which in this case would be "David", and presumably a variable by that name has not actually been set.

The outer token is only necessary in the condition actions because the "Variable Name / Token" field assumes you want to use literal text rather than having it retrieve the value of a variable, the moment it contains an opening and a closing brace, in that order.
This is not the case in fields that don't attempt to retrieve variable values, like the "Variable Name" field of the "Set a Text Value" action.


"{EDDI message received player}" is also not a valid variable name, nor a valid token. This can work because the token parser will strip those braces, but they serve no actual purpose there.

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Re: Embedded variables and retrieval from profile
« Reply #2 on: May 04, 2021, 11:26:03 PM »
Quote
"{EDDI message received player}" is also not a valid variable name, nor a valid token. This can work because the token parser will strip those braces, but they serve no actual purpose there.

This is a Boolean passed by EDDI.  From the docs for EDDI:

Code: [Select]
{BOOL:EDDI message received player} True if the sender is a player
But VA fusses about having colons in anything but TXT, so I set it how it is.

Quote
However, when later retrieving the variable, you attempt to retrieve the value of a variable named "David", as that is what "{TXT:{TXT:EDDI message received from} voice}" will render as, because it retrieves the value of the variable "EDDI message received from" (which, again, let's say is "bob"), and then retrieves the value of the variable named "bob voice", which in this case would be "David", and presumably a variable by that name has not actually been set.

So then I need to remove a pair of curlies?  Because if I drop from super cruise and enter the no fire zone of a station, I hear the message with an assigned voice.  When I request docking, the "docking request granted" voice is the same as "no fire zone entered".  If I quit playing after docking, go eat dinner, restart the game and undock, the message that I've left the no fire zone is assigned a different voice.  It is persistent across the session, but not between sessions.  Which would indicate that the variable itself is valid.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: Embedded variables and retrieval from profile
« Reply #3 on: May 04, 2021, 11:58:15 PM »
"{BOOL:EDDI message received player}" is not a variable name, it's a token wrapping a variable name. The token is used in EDDI's documentation to indicate the datatype of that variable.

This topic attempts to summarize the difference between the two.

Perhaps it will also make clearer to you what needs to be done in order to set the correct variable name, and why merely removing braces is not the correct course of action.

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Re: Embedded variables and retrieval from profile
« Reply #4 on: May 05, 2021, 12:41:38 AM »
Quote
"{BOOL:EDDI message received player}" is not a variable name, it's a token wrapping a variable name. The token is used in EDDI's documentation to indicate the datatype of that variable.

Which is why I have it set as it is, removing the BOOL piece.

But given that I'm recalling the voice variable from the profile at the beginning, why is it consistent within that play session but not after I leave the game and then come back?  Each time a message comes in, it is recalling any NPC message voices from the profile.  For example, the "Cruise ship" messages will often come in sequence of something along the lines of "This is the finest cruise ship blah blah blah" and then few seconds later "Talk to the cruise director blah blah" and then "We'll be delayed blah blah". If the variable is incorrect, each of those should end up a different voice.  But its only between gaming sessions that they change.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: Embedded variables and retrieval from profile
« Reply #5 on: May 05, 2021, 12:49:33 AM »
As I mentioned, you are not "recalling" the variable you think you are. That action is the problem, and also why it works within the same session.

The "BOOL piece" is not what makes it a token, the curly braces are. Those are what the token parser looks for. You have not removed the token, but replaced it with an invalid one, as there is no "{EDDI message received player}" token.
The token parser removes the braces rather than showing an error message, but the input is technically invalid.

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Re: Embedded variables and retrieval from profile
« Reply #6 on: May 05, 2021, 09:38:53 AM »
Okay, so instead of

Code: [Select]
Set text [{TXT:{TXT:EDDI message received from} voice}] to [Saved Value]
it needs to be

Code: [Select]
Set text [{EDDI message received from} voice] to [Saved Value]
and that would find the variable "The Jet's Hole voice" or "Low Orbital voice" or "Cruise ship voice" with a value of "David" or "Hazel" or "Sean" or whatever in the profile, or if it doesn't exist it would be "Not set"?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: Embedded variables and retrieval from profile
« Reply #7 on: May 05, 2021, 03:08:53 PM »
Yes.

As you still need to use the additional "{TXT:}" token in the condition that checks whether the variable has been set, due to the way the "Variable Name / Token" field works, you'll also need to stick to comparing against the literal text "Not set", rather than using the "Has Been Set" operator, as you're checking the value returned by the token (which, as always, is literal text), rather than the actual value of the variable