How do I, 2 text conditions

0 favourites
  • 4 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hi all!!

    I have 2 texts that move to a different position when the player collides with them. I want to have another "Correct" text go to a position when the previous texts move. So far I have when text1 goes to x=544 and when text2 goes to x=464<action is "correct" set position to x and y. However, the correct is moving when one text moves, not both. I tried to attach a picture but it wont let me.

    This is for my master class so any help would really be appreciated!!!

  • Hey A01214706,

    which I'll assume is pronounced AOLZLATOB! :)

    Okay, if I understand, you have 2 text objects Text1 and Text2.

    If the player touches Text1, it is moved horizontally to x=544.

    If the player touches Text2, it is moved horizontally to x=464.

    If Text1 and Text2 have both been moved, then TextCorrect (which says "Correct") should be moved to a given [x,y] position.

    There are a lot of ways to make that work, the one I'll explain isn't the most efficient, but it's easy to set up.

    The fast way:

    1. In the Layout View, select the Text1 object.

    2. In the properties panel, in the "Instance variables" section, click the blue "Instance variables" link.

    This will open the "Instance Variables" editor for the object.

    3. In the Instance Variables window, Click the plus "+" button at the top.

    This will pop up the "New Instance Variables" dialog.

    4. Change the Name field to "wasMoved".

    Later, we'll use the "wasMoved" variable to keep track of whether the text object has been moved yet.

    5. Click the "OK" button.

    6. Close the "Instance Variables" editor by clicking the "X" at its top right.

    7. Repeat the same process (steps 1-6) for the Text2 object, to give it a "wasMoved" variable.

    8. In the Event Sheet, find the event where the Text1 object gets moved.

    9. Under the action that moves Text1, add a new action.

    10. In the action browser, double click the Text1 object.

    11. In the "Instance variables" section, double click the "Set value" action.

    12. Make sure that "wasMoved" is selected in the "Instance variable" field.

    13. Change the value to 1, and click the "Done" button.

    We can later check to see if the value is 1, and if it is, we know the object was moved.

    14. Repeat the same process (steps 8-13) for the Text2 object, to create the action for its "wasMoved" variable. You'll need to find the event that moves the Text2 object.

    15. Create a new event with the following two conditions:

    Text1: Compare instance variable "wasMoved" = 1.

    Text2: Compare instance variable "wasMoved" = 1.

    (Note: To add a second condition, you can click in the event and press the "C" key on your keyboard.)

    16. Add the action to move the TextCorrect object to the desired location:

    Finally don't forget to disable your original event that moved the TextCorrect object.

    Done.

    It should look like this:

    Event:

    + Player touches Text1

    Text1: Move to new position.

    Text1: Set "wasMoved" to 1.

    Event:

    + Player touches Text2

    Text2: Move to new position.

    Text2: Set "wasMoved" to 1.

    Event:

    + Text1: Compare instance variable "wasMoved" = 1.

    + Text2: Compare instance variable "wasMoved" = 1.

    TextCorrect: Move to new position.

    A more efficient way

    There are more efficient ways to do this same task, but I didn't want to over-complicate things.

    With the solution described above, the game will be constantly checking to see if both "wasMoved" variables are currently 1.

    If you want to try making it more efficient, you can instead have the game only check when the move events for Text1 or Text2 occur.

    This way the game only checks when there's a chance we should move TextCorrect.

    Event:

    + Player touches Text1

    Text1: Move to new position.

    Text1: Set "wasMoved" to 1.

    ~ ~ Sub-Event: - (You can create sub-events by pressing "B" on your keyboard.)

    ~ ~ + Text1: Compare instance variable "wasMoved" = 1.

    ~ ~ + Text2: Compare instance variable "wasMoved" = 1.

    ~ ~ > TextCorrect: Move to new position.

    Event:

    + Player touches Text2

    Text2: Move to new position.

    Text2: Set "wasMoved" to 1.

    ~ ~ Sub-Event: - (You can create sub-events by pressing "B" on your keyboard.)

    ~ ~ + Text1: Compare instance variable "wasMoved" = 1.

    ~ ~ + Text2: Compare instance variable "wasMoved" = 1.

    ~ ~ > TextCorrect: Move to new position.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Fisholith,

    Thank you SOOO much!! I tried the second method you described and it worked perfectly!!! I was thinking something with having to do instance variables but I am very new to this. Thank you for taking the time to write such a detailed description!!

  • No problem A01214706, glad it helped out.

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