How do I create a text log generator?

0 favourites
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • What i basically need is for my program to generate some text every few seconds.

    I need it to be probability based as well, meaning that every 10 seconds it generates a string of text from a group. However each group has different text inputs. For example:

    Group 1:

    cats

    dogs

    humans

    Group 2:

    cheese

    meat

    drinks

    How do i create a generator whereby the program has a 30% chance of generating the text from group 1 and a 70% chance of generating text from group 2?

    (Beginner here, need explanations to be just a bit more detailed, thanks!!!)

  • I would use JSON to format all possible options for all possible groups (for your example, it would be like this:

    [quote:1ueplfm8]

    {

    "c2array": true,

    "size": [3,1,1],

    "data": [[["cats"]],[["dogs"]],[["humans"]]

    }

    Then you can import this text into C2 Array (Array > Load > input text) and choose a random entry like: Array.At((random(Array.Width)-1))

    You can rinse and repeat for as many arrays as needed. Like on Array > Load in the "JSON" slot you would put:

    [quote:1ueplfm8]"{""c2array"": true,""size"": [3,1,1],""data"": [[[""cats""]],[[""dogs""]],[[""humans""]]}"

    NOTE: If you are inputting raw text directly into the C2 you must use "" for all quotation marks in your string.

  • I would use JSON to format all possible options for all possible groups (for your example, it would be like this:

    [quote:2brufpoq]

    {

    "c2array": true,

    "size": [3,1,1],

    "data": [[["cats"]],[["dogs"]],[["humans"]]

    }

    Then you can import this text into C2 Array (Array > Load > input text) and choose a random entry like: Array.At((random(Array.Width)-1))

    You can rinse and repeat for as many arrays as needed. Like on Array > Load in the "JSON" slot you would put:

    [quote:2brufpoq]"{""c2array"": true,""size"": [3,1,1],""data"": [[[""cats""]],[[""dogs""]],[[""humans""]]}"

    NOTE: If you are inputting raw text directly into the C2 you must use "" for all quotation marks in your string.

    Thank you! That gives me a rough idea on how to proceed. However, any ideas on changing the probability? Thanks:)

  • Another way would be to put the lists into text variables. Then use another variable to store a random value from 0 to 1, and if it's lower than 0.3 set the text to a random value from the first list, or if it's greater then that's the other 70%, so the other list would be used.

    Global text group1="cats,dogs,humans"
    Global text group2="cheese,meat,drinks"
    Global number probability=0
    
    Every 10 seconds
    --- set probability to random(1)
         probability<0.3
         --- set text to tokenat(group1, int(random(tokencount(group1, ","))), ",")
         Else
         --- set text to tokenat(group2, int(random(tokencount(group2, ","))), ",")[/code:2y22kkf8]
  • Another way would be to put the lists into text variables. Then use another variable to store a random value from 0 to 1, and if it's lower than 0.3 set the text to a random value from the first list, or if it's greater then that's the other 70%, so the other list would be used.

    Global text group1="cats,dogs,humans"
    Global text group2="cheese,meat,drinks"
    Global number probability=0
    
    Every 10 seconds
    --- set probability to random(1)
         probability<0.3
         --- set text to tokenat(group1, int(random(tokencount(group1, ","))), ",")
         Else
         --- set text to tokenat(group2, int(random(tokencount(group2, ","))), ",")[/code:3sgs1693]
    

    Sounds a little complicated for someone without coding background ;( I'm always willing to learn, but what's the best way to go about this if my list has a lot of items? say about 100 in each group?

  • If your lists are large it makes no difference. You can set the text variables in the same way, but it may not look the cleanest with the event view. Another way is to have the lists in a text file included in the files folder of your project, and loading it with the Ajax object.

    The only complicated looking thing is the tokenat and tokencount expressions but the manual explains them.

  • If your lists are large it makes no difference. You can set the text variables in the same way, but it may not look the cleanest with the event view. Another way is to have the lists in a text file included in the files folder of your project, and loading it with the Ajax object.

    The only complicated looking thing is the tokenat and tokencount expressions but the manual explains them.

    It looks like I'll have to do a bit of research on the tokenat and tokencount expressions then. Am I right to say that probability is only achieved using Java? (having to use code)

  • No, those are just expressions used in C2. You don't use JavaScript unless you are making plugins.

  • No, those are just expressions used in C2. You don't use JavaScript unless you are making plugins.

    Oh, my bad. But thank you for all the help so far. So I'm assuming I'll just have to read the manual on the different expression C2 has to offer, right?

  • So I'm assuming I'll just have to read the manual on the different expression C2 has to offer, right?

    I would have thought the manual would be anyone's first step, followed by a few tutorials to understnd how the C2 Event System works.

    After that, you should be able to at least get close to what you want to achieve, and also be able to ask more detailed and targetted questions.

    Good luck, and have fun.

  • > So I'm assuming I'll just have to read the manual on the different expression C2 has to offer, right?

    >

    I would have thought the manual would be anyone's first step, followed by a few tutorials to understnd how the C2 Event System works.

    After that, you should be able to at least get close to what you want to achieve, and also be able to ask more detailed and targetted questions.

    Good luck, and have fun.

    Yeah, you're right. I actually did poke around with the software a little after watching a few tutorials for C2 basics. I figured the manual would be difficult to digest before knowing how everything roughly works. Does the manual offer explanations for all the expressions C2 has?

  • The simple stupid way to change the probabilities of any given entry in a straight list is to have multiple entries of each one you want to appear more.

    Like:

    [

    [cat]],[[cat]],[[dog]],[[human]],[[human]],[[human]],[[human]]

    then just use Array.At(random(Array.Width))

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The simple stupid way to change the probabilities of any given entry in a straight list is to have multiple entries of each one you want to appear more.

    Like:

    [[cat]],[[cat]],[[dog]],[[human]],[[human]],[[human]],[[human]]

    then just use Array.At(random(Array.Width))

    I don't think that would be a good way because I have a list of over 100 items and honestly they're phrases not words. But thanks though!

  • Yea, there are other more sophisticated ways of doing it too, like what R0j0hound pointed out. You can use statistical distributions to change the way random functions pull indices out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)