How get global var. from first to second layout

Get help using Construct 2

Post » Wed Nov 30, 2011 1:37 am

1. My player gets double jump on layer 1 and global variable it's =1
What to do to still have this variable on global var in next layer ?

2. Also whn I take double jump in first layer, go to layer 2 and back to layer 1 - double jump is there again. System should remember that i take this sprite.

thx
B
4
G
2
Posts: 48
Reputation: 1,328

Post » Wed Nov 30, 2011 2:35 am

1. A global variable means it's global to the whole project.
A global variable set in event sheet 1 will be available in a later executed event sheet 2.

2. If you load a layout, it will load with every default elements you've setted it for. Meaning if you have a "Double jump" sprite that stands in the layout, you might very well destroy it in the first execution of the layout. If you load again the layout, the sprite will be spawned again.

You have to take care of such "disapearing" objects in the event "Start of layout" (with the help of a global variable for example).
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Nov 30, 2011 11:55 am

ok, about point 2:
So if I back to layout 1 by tuching door - I should add event - delete double jump ?
But soetimes player couldn't find double jump in layer 1, so haven't got it yet. So I can't delete it.
B
4
G
2
Posts: 48
Reputation: 1,328

Post » Wed Nov 30, 2011 12:41 pm

That's where comes the use of a global variable.
Your global variable keeps the state of your PowerUp (the double jump, I guess it is a power up).

Check this capx.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Nov 30, 2011 1:15 pm

eh doesn't work for me.

event sheet 1
global var - doublejump = 0
When player found DoubleJump sprite = Add 1 to DoubleJump (global)
DoubleJump is visible - when System set DoubleJump = 1

And Layer 2 doesn't remember this. I can't double jump in layer 2 and when I back DoubleJump sprite is still there (but I taken it before)


B
4
G
2
Posts: 48
Reputation: 1,328

Post » Wed Nov 30, 2011 10:13 pm

I stil checking your capx, but it's works for you if you don't need to jump. Maybe I got this jump but it doesn't work. I can't jump.
I checked global (right corner) and now when I back to layout 1 - sprite is invisible.(so only that work)

It looks like this.


B
4
G
2
Posts: 48
Reputation: 1,328

Post » Wed Nov 30, 2011 10:53 pm

Using the same variable name for global and private instances is the best way to lose yourself.

You are overcomplicating things a great deal.
Check this other capx.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Thu Dec 01, 2011 12:13 am

I got it
Problem was that I added this:
Sprite2 is visible - Set doubleJump to 0

thanks fo capx
B
4
G
2
Posts: 48
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: h1k3, Unconnected and 0 guests