I’m trying to create a system that generates a sentence based on a list of structures and words. I begin by calling a method in a generate script that picks a string from the structure list. From there, the structure list also picks a string from the words list to fit into the places it needs. But there seems to be a problem I’m not understanding in the structure list. It does successfully place a string into the spots it’s called for. But recalling the “CreateSentence” method does not seem to generate a new word. It just spits out the first word it outputted for that particular string. Does anyone know why this is occurring? Is it a bug? Or just something I’m not understanding right? Here are some example scripts of what my code looks like

public class Generate : MonoBehaviour
{
    public Text onScreenText;
    public void CreateSentence()
    {
        string finalString = Structure.strucures[Random.Range(0, Structure.strucures.Length)];
        onScreenText.text = finalString;
    }
}

public class Structure
{
    public static string[] strucures = new string[]
    {
        "Your look " + List.wordList[Random.Range(0, List.wordList.Length)] + " today.",
        "You looked " + List.wordList[Random.Range(0, List.wordList.Length)] + " yesterday.",
        "You will look " + List.wordList[Random.Range(0, List.wordList.Length)] + " tomorrow."
    };
}

public class List
{
    public static string[] wordList = new string[]
    {
        "nice",
        "beautiful",
        "okay",
        "ugly",
        "awful"
    };
}

When you get the string from the static array, it wont call a new method everytime. It’s already done that when the array was initialized. Because it’s static, there’s only one of it. So you basically get the same string over and over again.

This solves it

    private static string[] prefixes = new string[]
    {
        "You look ",
        "You looked ",
        "You will look "
    };

    private static string[] suffixes = new string[]
    {
        " today",
        " yesterday",
        " tomorrow"
    };

    public static string GetRandom()
    {
        int index = Random.Range(0, prefixes.Length);
        string prefix = prefixes[index];
        string adjective = List.wordList[Random.Range(0, wordList.Length)]
        string suffix = suffixes[index];
        return prefix + adjective + suffix;
    }

Thank you @myzzie and @Namey5 I like both of these answers. But I can’t figure out how to use them if I want to have random amount of words to be filled in. Take for example, we want to make a food item that has the food item, adjectives, and a that statement after words, but we want the adjectives and that statement to be optional. So something like “mouth-watering cheese burger that has extra ketchup” or “tenderized, well seasoned chicken breast” or even just “T-bone steak” How I did this before was have a list of all of these things, and call a method that would pick, choose which and how many adjectives and that statements were used and place everything for me, and just return the value. I’d also not want my array to follow the same structure every time. Maybe sometimes it’s “I want to eat (Food)” or “I want to sit at (Location) while I eat my (Food)”. Would I be able to recreate this with a string.format system? Is it possible to remove the static from my lists and still make them easy to access if I have 10+ of them? Thanks for the help!

thank you for sharing through this i’ve solve my shop and save near me our go saveshop store problems.