How do I transport my character through layouts?

Get help using Construct 2

Post » Thu Jan 21, 2016 11:20 pm

Hi ppl,

I have a character (sprite) which is my player. When player walks into some "doors" he should be transported to the next layout (level) and be able to back to previous one layout (level).

Sounds trivial, but... this character (sprite) has several instance values like healthPoints etc. No matter what I try I can't get the instance variables to persist.

What I have tried:

1. Add persist behaviour to the object - It doesn't work, but that's understandable cause Persist behaviour remembers the state of the object instance for the particular layout.

2. Set "playersLayer" to global and player object to global - in result object is automatically (no need to add it manually) created on the layout with the initial state of the instance variables. Well I thought "global" moves the instance to the next layout so I would expect to keep the instance variables unchanged... but not

3. Allright so I've tried to set layer and character object to global AND add a persist behaviour hoping maybe this will keep the instanca variables set up... but again failure.

I think I am missing something right? Do I really need to save those values somewhere in a dictionary or so and then load it after layout switch or there is a smart way to move The Player in one piece all over the layouts?
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Thu Jan 21, 2016 11:43 pm

I always thought using global on the player-object should keep the instance variables intact..
Are you sure you are not resetting them through events?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jan 21, 2016 11:54 pm

Yes I'm sure. I've checked that like ten times. Darn that should be trivial and I stuck with it for a pretty long time now huh.
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804

Post » Fri Jan 22, 2016 12:01 am

Awwkay... I got it. My Character is in container with another sprite (his gun), and that gun sprite was not global, that's why I had such a wierd situation.

I made gun sprite global as well, and it works fine now... duh!
ImageImageImage
B
28
S
16
G
82
Posts: 1,030
Reputation: 45,804


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 16 guests