How do I dynamically replace text in this mechanic?

0 favourites
  • 4 posts
From the Asset Store
OpenAI TTS
$9 USD
10% off
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Hello friends,

    I have a little educational app where random, mix-n-match sentences are generated for students to practice reading.

    Here is the C3 file.

    The app creates sentences that include pronouns, and I want to implement a system where for the male names the pronouns are changed on the fly.

    The file above is a stripped-down version for the forum here. In the real implementation it has many names.

    A typical example is:

    Susan is happy because it's her birthday

    ...needs to become

    Peter is happy because it's his birthday

    ...when a male name is invoked

    If you open the project file it should be immediately clear how it's set up (it's very simple) and what the goal is. The sentence fragments that include the gender specific pronouns - I only want to write those once in one gender. I want the coding to handle changing the pronouns according to what name is being invoked.

    I have spent quite a bit of time trying to figure it out, but I'm just not that advanced. I think an array would probably be best - one column for female names and one for male, and then you'd just say if the name came from this or that column, change all "she" to "he" etc., but I can't get that working. Is it the 'len'? If it's an array with two names columns, it needs to still draw randomly from both columns to maintain the current functionality. The other approach it seems would be a condition where I just list all the male names and the system checks against the list each time.

    Thanks very much for any assistance. I greatly appreciate it!

  • One simple approach would be to define the gender randomly prior generating the text.

    That way you can easily differentiate which pronouns you need to use while generating the text.

    I made a quick very basic example to demonstrate this. Of course it could be further advanced.

    Another approach would be to use regex, to replace partial strings on the fly.

    But i'm sure there are smarter ways.

    Here's the example

  • Here is my version:

    dropbox.com/s/ga1lmu24525aas1/frankensentence2.c3p

    But instead of storing these texts in variables, I would of course use an array. Especially if you are planning to have hundreds of them.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks so much to both of you for these thoughtful and helpful responses. I'm trying out both approaches to see what fits best with the rest of the app - there are other things going on that are not shown in this simplified version that I posted here. Many thanks again.

    Stan great to see you again and thanks! Props and respect to see you're still helping people by sharing your expertise.

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