0 Favourites

How do I alter the text object in a different layout?

  • I have a text object in my main layout (Let's call this A), and I have a second layout (B) that opens up from the main layout (A) via a button click. I want to alter the text object in (A) when I change settings on (B). How do I do this without databases? Is this possible?

  • Maybe store the text in a Global variable would be easiest option. That way, wherever you are you just need to set the text object's .text property to the Global variable, along with any other text you need.

  • I have a global variable for the text to set the Text Object's value. It still doesn't work.

    This is my set up:

    * Layout 1 & Layout 1 Event Sheet - two buttons; button 1 calls a function called "update" in the Function Event Sheet, button 2 goes to Layout 2.

    - a global variable initialised to 0.

    - a text object that is set to the global variable value.

    * Function Event Sheet - has a function called "update" which increments the global variable by 1.

    * Layout 2 & Layout 2 Event Sheet - has two buttons; button 1 calls a function called "update" in the Function Event Sheet, button 2 goes to Layout 1.

    Result:

    Layout 1 sets the text value to the global variable value correctly, but not Layout 2.

    A click of button 1 on Layout 1 updates the text object to a value of "1".

    Once we click to go to Layout 2 and press the button to update the global variable, then go back to layout 1, the text object has a value of "Text".

    A press of button 1 on Layout 1 updates the global variable to "2".

  • jbar6381

    Try doing:

    On start of layout -> Set text to global variable

    That way the text object will be updated each time the layout loads.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I have a text object in my main layout (Let's call this A), and I have a second layout (B) that opens up from the main layout (A) via a button click. I want to alter the text object in (A) when I change settings on (B). How do I do this without databases? Is this possible?

    It's not pretty but I was able to replicate this (I think) to the way you described. See the attached .capx

    It contains a global variable and is displayed on each layout. The call update button will increment it and the other button will swap between layouts.

    While variables can be global, events cannot (at least I think they can't) so both event sheets have a function called "update" that adds one to the global variable. They also have an "every tick" event to update the text on the screen.

    I suppose you could create an event sheet and just share it between layouts to eliminate the redundancy but that might not work in a full blown application.

    Hope that helps.

  • While variables can be global, events cannot (at least I think they can't) so both event sheets have a function called "update" that adds one to the global variable. They also have an "every tick" event to update the text on the screen

    Functions used in multiple layouts should be in a separate Event Sheet, you then just need to Include it in the layout's main Event Sheet.

    Also, updating the Text object every tick is overkill. It only needs to be changed in the Update function (if the object isn't there, it won't do anything) and on start of the layout.

  • Thanks OddConfection,

    That would make it easier. Create one event sheet for updating the global variable. The text update was simply to have the text object change which could be done in the "update" function, but it's just there for demo purposes.

    Thanks

  • OddConfection,

    That would make it easier. Create one event sheet for updating the global variable. The text update was simply to have the text object change which could be done in the "update" function, but it's just there for demo purposes.

    As per OddConfections suggestion I updated the sample.

    1. There's an event sheet call "Global Events" that's included the event sheet for each layout. This holds the global variable and the "update" function that adds 1 to the value and sets the text display to show the value.

    2. Each event sheet includes a System > On start of layout event that sets the text field to the value

    Thanks

  • Thank you very much OddConfection and bsimser. The key was to have the System > On start of layout repeat the assignment of the global variable text to the text object.

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