How do I create a text log generator?

Get help using Construct 2

Post » Tue Jan 12, 2016 7:05 am

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!!!)
B
3
Posts: 9
Reputation: 193

Post » Tue Jan 12, 2016 9:07 pm

I would use JSON to format all possible options for all possible groups (for your example, it would be like this:
{
"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:
"{""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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,317
Reputation: 4,628

Post » Wed Jan 13, 2016 3:13 am

gumshoe2029 wrote:I would use JSON to format all possible options for all possible groups (for your example, it would be like this:
{
"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:
"{""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:)
B
3
Posts: 9
Reputation: 193

Post » Wed Jan 13, 2016 4:03 am

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.

Code: Select all
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, ","))), ",")
B
85
S
27
G
85
Posts: 5,073
Reputation: 57,880

Post » Wed Jan 13, 2016 4:22 am

R0J0hound wrote: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.

Code: Select all
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, ","))), ",")


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?
B
3
Posts: 9
Reputation: 193

Post » Wed Jan 13, 2016 4:56 am

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.
B
85
S
27
G
85
Posts: 5,073
Reputation: 57,880

Post » Wed Jan 13, 2016 6:50 am

R0J0hound wrote: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)
B
3
Posts: 9
Reputation: 193

Post » Wed Jan 13, 2016 8:16 am

No, those are just expressions used in C2. You don't use JavaScript unless you are making plugins.
B
85
S
27
G
85
Posts: 5,073
Reputation: 57,880

Post » Wed Jan 13, 2016 8:41 am

R0J0hound wrote: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?
B
3
Posts: 9
Reputation: 193

Post » Wed Jan 13, 2016 9:26 am

Alsttr wrote: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.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
126
S
29
G
73
Posts: 5,099
Reputation: 52,018

Next

Return to How do I....?

Who is online

Users browsing this forum: bbjGames, bigcatrik, Exabot [Bot], jpstudio, Lordshiva1948, mekonbekon, menos30, newt, tarek2 and 12 guests