How do I select a word and set other text to match it?

0 favourites
  • 7 posts
From the Asset Store
A complete set of Graphic, User Interface element to build 2D mobile game or PC game.
  • Hello friends,

    I've been struggling to figure out how to achieve this simple functionality. I thought it would be using tokenat, but nothing I have tried has worked. Any help is appreciated.

    The actual use case is this. On the right side a random shape/color combination is automatically loaded. Then the user must ID the shape and its color by choosing a shape and color name from the left. I can do everything else, but this above part has me stuck. These are just normal text boxes with pre-set text.

  • First thing that comes to mind would be to use separate instances of the text object for each word, instead of one text object with all the words. That should should make it simple.

  • I can do that, but If it is possible to do what I've eluded to in the first pic, I would really like to learn how. It's a technique that I could use in a wide variety of ways.

  • Unless you would use a monospace font (means each letter has the same width) it would be difficult to determine which letter or word the player clicks, as construct only has a collider for the whole text object.

    with a monospace font you could check the position of the cursor compared to the text object and use tokenat.

    But imo it would be easiest to use seperate instances per word like oosyrag said.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, I see the difficulty now. It's quick work in this case to make them separate, just wondering if a more automated approach could be worked out. It would make it much easier to make a variety of content that uses this mechanic.

  • You could still automate the creation of the separate text objects.

    Using a text object or dictonary etc that has the whole text and then have a loop that creates a text-box per word from it.

  • To automate it, you would use tokenat on the source text. Repeat source text token count times, and create and position each word (add the comma back when appropriate) based on loopindex or the number of characters in the previous word. Sprite fonts would be easier to handle in regards to positioning.

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