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

Get help using Construct 2

Post » Mon Jul 14, 2014 11:08 am

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?
B
9
S
2
Posts: 18
Reputation: 619

Post » Mon Jul 14, 2014 12:07 pm

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.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,548
Reputation: 60,440

Post » Tue Jul 15, 2014 3:07 pm

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".
B
9
S
2
Posts: 18
Reputation: 619

Post » Tue Jul 15, 2014 3:28 pm

@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.
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 475
Reputation: 7,015

Post » Tue Jul 15, 2014 3:40 pm

jbar6381 wrote: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.
You do not have the required permissions to view the files attached to this post.
B
17
S
5
G
2
Posts: 39
Reputation: 1,846

Post » Tue Jul 15, 2014 3:52 pm

bsimser wrote: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.
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 475
Reputation: 7,015

Post » Tue Jul 15, 2014 4:19 pm

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
B
17
S
5
G
2
Posts: 39
Reputation: 1,846

Post » Tue Jul 15, 2014 4:20 pm

@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
You do not have the required permissions to view the files attached to this post.
B
17
S
5
G
2
Posts: 39
Reputation: 1,846

Post » Tue Jul 15, 2014 9:23 pm

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. :D
B
9
S
2
Posts: 18
Reputation: 619


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests