How to make going to previous layout?

Get help using Construct 2

Post » Mon Apr 04, 2016 8:34 pm

Hello,
I'm making a text based game where inventory is in "Inventory" layout.
When players are reading, they press Inventory button and then game opens Inventory layout. Then I need game to remember that layout where player was when he was pressing Inventory button and open it.
For example player is in Layout #3 and then he goes to Inventory layout and then when he presses back button, he gets into Layout #3.
How to make it?
B
6
Posts: 20
Reputation: 266

Post » Mon Apr 04, 2016 8:54 pm

You can set a global variable when you push the button inventory.

Or you can make the inventory on top_layer in each level. With a call function you only need the code once.

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Tue Apr 05, 2016 2:06 am

What I did (Inventory is on same layout, but I did this for a save and load menu) is:

1) Make a global variable, I called mine last_layout. The variable can either be a number, or text. In my case it's text.

2) When the player starts the level, make an On Start of Layout and in it make a Set global variable last_layout equal to LayoutName

There you go! Now all you need to do is:

3) Have a trigger on the inventory screen so that when a player pressed or clicks it, it does Go to: Layout by name (or number if you used a number) last_layout.
B
28
S
5
G
5
Posts: 98
Reputation: 4,794

Post » Sat Oct 29, 2016 10:44 am

I can not do, there is an example that I could download?
B
10
S
5
Posts: 2
Reputation: 869

Post » Sat Oct 29, 2016 7:05 pm

Put this CAPX together real quick. It's just a simple project with 4 layouts (3 regular layouts and an Inventory layout). The 3 regular layouts share a single event sheet - note: you don't NEED to do this, as they can still have their own sheets and work. Inventory layout has its own inventory sheet.

"On Start of Layout", as suggested by Equinox80, the layout name is stored in a global variable called Last_Layout. I've made it a text variable, and one easy way to do it would be to simply use the system expression "LayoutName" to automatically set the variable to the name of the current layout.

In the Inventory Sheet, when the Back button is pressed, I simply use "Go to layout (by name)" and type in the "Last_Layout" variable.

Remembering Last Layout CAPX

Hope this is what you're looking for!
B
9
S
2
G
1
Posts: 19
Reputation: 660

Post » Sun Oct 30, 2016 8:24 am

thanks !
B
10
S
5
Posts: 2
Reputation: 869


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 14 guests