Getting string reference from reference table

I am trying to get a string reference from reference table.
I must use the INDEX to select the proper string because I’m bound from another script.
I just need the localizedstring to set the value of MAX in the string shown to the player. but I cannot get the string from the string table, I cannot figure out the code to do it.
(Also why I have to set the local variables in the LocalizedString instead of the LocalizedStringEvent since they are shown there?)

    public void FillWithMission(MissionBase m, MissionUI owner)
    {
        //descriptionText.text = m.GetMissionDesc();

        // get index of mission and max to reach from the mission entry
        int index = Array.IndexOf(Enum.GetValues(typeof(MissionType)), m.GetMissionType());
        float value = m.GetMax();

        //tries to get the correct entry from a given entry table given the index provided in the function above (string entries in the table follows the same patterns)
        StringTable descriptionsTable = missionDescTable.GetTable();
//THIS LINE GIVES ME THE ERROR:
        LocalizedString localizedString = descriptionsTable.GetLocalizedString(index); 

        descriptionEvent.StringReference.SetReference(missionDescTable.TableReference, descriptionsTable.SharedData.Entries[index].Id);

        // sets the value found in missions to the smart string
        FloatVariable floatToSet = null;
        if (!localizedString.TryGetValue("quantity", out var variable))
        {
            floatToSet = new FloatVariable();
            localizedString.Add("quantity", floatToSet);
        }
        else
        {
            floatToSet = variable as FloatVariable;
        }

        floatToSet.Value = value;

StringTable does not have a method called GetLocalizedString, thats why you get an error.
There’s some confusion in the code around LocalizedStrings.
I would not recommend using indexes to access the string tables, the items may not be in the order you expect. For your example, you could name the entries after the Enum names or assign the enum values as the entry ids (except for 0).

Although this should work if the indexes are correct:

public void FillWithMission(MissionBase m, MissionUI owner)
{
    // get index of mission and max to reach from the mission entry
    int index = Array.IndexOf(Enum.GetValues(typeof(MissionType)), m.GetMissionType());
    float value = m.GetMax();

    StringTable descriptionsTable = missionDescTable.GetTable();
    descriptionEvent.StringReference.SetReference(missionDescTable.TableReference, descriptionsTable.SharedData.Entries[index].Id);

    // sets the value found in missions to the smart string
    FloatVariable floatToSet = null;
    if (!descriptionEvent.StringReference.TryGetValue("quantity", out var variable))
    {
        floatToSet = new FloatVariable();
        descriptionEvent.StringReference.Add("quantity", floatToSet);
    }
    else
    {
        floatToSet = variable as FloatVariable;
    }

    floatToSet.Value = value;

The variables are part of the LocalizedString, the LocalizeStringEvent is showing the LocalizedSring property drawer. If you add a LocalizedString to your class you will see the same editor.

1 Like

I see… I just needed to grab the LocalizedString from the LocalizedStringEvent in order to set variables on it… it was not needed to “extract” it from a StringTable. Well that works thanks! I know the ID stuff is not that good but it’s working, and otherwise I have to modify a lot of the code in other scripts (that are not inheriting to monobehaviour, so I an’t even reference public stuff from there). Anyway It’s working, thanks!

1 Like