lives and scores

Get help using Construct 2

Post » Thu Dec 08, 2011 9:43 pm

@Yann

Mina's problem is that after playing through the level, it shows the Start page again, but on Pressing Enter to start, the text boxes are missing.

It can be quickly fixed by setting the text boxes 'Global Property' to 'No', although the values will no longer display on the Start page after completing the level, which I'm not sure is how Mina wants it.zenox982011-12-08 21:47:48
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Fri Dec 09, 2011 7:36 am

Oh! well it's not really a problem is it?

You just have to duplicate the object and change its text with event as you still have the value in the global variables.

minaPlatform.capx
Last edited by Yann on Sun Sep 14, 2014 10:50 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 09, 2011 10:01 am

@Yann.

You're correct in that it is easy to fix, but I wanted to know WHY the text objects and sprite didn't appear.

After adding some debug code, it seems that on start of Layout 1, these global objects are on Layer 3, but after level is completed, they move to Layer 0 (because there is no layer 3 on the subsequent layout), which means that when you press Enter to start again, these objects are still on Layer 0 so don't show.

It seems logical, but I would have thought it would have reset the layer back to 3 on this layout, which it doesn't. You can always specifically set these objects to the correct layer on Start of Layout using 'move to layer' but it's still seems wrong to me.

Personally, I just think the use of global objects is ambiguous, and not readily understandable to the layman. Users are probably expecting these global objects to appear on all layouts, which without extra coding, they won't.

Sorry for the waffling, people :/
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Fri Dec 09, 2011 10:12 am

How it was used in Mina's capx is not a proper use of global object. Global object shouldn't even be used for Graphical representation.
The only things that should be global are data you want to keep through layouts (score/lives/position/etc)

I used to use Global object in cc to avoid updating sprites in each layout each time I change things.
But now Sprite instance even if not global share the same Object Definition in the Object library (Texture, variables, behavior, etc). So if you want to change animation or instance variable definition for the whole project, you can change on the instance and it will be changed for all layout even if it's not global.

I can't really figure out why making graphical element global.Yann2011-12-09 10:13:12
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 09, 2011 10:14 am

@Yann

Exactly my point!

It's all about user expectation - what does the user expect to happen.

As you have said, why are objects allowed to be global? One for @Ashley, I feel.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Fri Dec 09, 2011 10:22 am

zenox > it's an ergonomy problem then. But I don't think the "global" option should be disable. For one reason: it could be used effectively we just never encounter a case where it was.

The more option the better, even if confusion can arise. People will ask, and learn some concept through design mistake.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 09, 2011 3:51 pm

Thank u zenox98 & Yann for ur help.
I set both text boxes to non global and it works fine in my game, but I'm not really figured out why they are missing while they are global. May be it's just as zenox98 said after restart the game they transfer to layer one.

@ zenox98 "Personally, I just think the use of global objects is ambiguous, and not readily understandable to the layman. Users are probably expecting these global objects to appear on all layouts, which without extra coding, they won't." That is exactly what i thought first "before this post"

@Yann "How it was used in Mina's capx is not a proper use of global object. Global object shouldn't even be used for Graphical representation." So how can i post the lives and scores in a game without using graphical representation and why it has the ability to be global if i can't use it?
B
303
S
6
G
5
Posts: 163
Reputation: 12,152

Post » Fri Dec 09, 2011 6:37 pm

The ability to be global exist 'cause it's possible. That is to say, you can have persistance of object through layout.

But for graphical object (I mean by that object that draw something on the layout (sprite, text, tiledbackground)), I don't think it's necessary and it leads to problems as the one we just encountered that is "where do you put global object when you don't have the same layer structure in different layout?"

For score and live representation, you just need something that would display it in each layout. What you want to be global (that is to say travel through layout) is data. It's just the number you don't want to be reset.
The graphical stuff... there's no reseting, it's juste your sprite and text boxes you use to display your game.

So for lives and score, just use global variables to keep them
and in each layout
[code]system: every tick
     -> TextScore: set Text to score
     -> TextLife: set Text to lives[/code]
TextScore and TextLife are Text object but they doen't need to be global, it's the variable that need to be, the data.
And as I said in a post long time ago, there's generally not that much global stuff in a game.
Unless you want a big stat layout with number of kill, number of death, precision of shoting, etc
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 09, 2011 9:16 pm

Extract from the manual article about instances:
[quote]By default, all instances are destroyed when the layout ends (e.g. when going to the next layout). If Global is Yes, none of the instances of this object type will be destroyed when switching layouts.[/quote]

Consider this example
The object Text is set to global.
I have an instance of Text in layout 1.

Layout 1 automaticly switches to layout 2 after 2 seconds.
Result => the button instance of layout2 appears, the text instance of layout 1 stays on screen.

Clicking the button allow to make a new instance of the Text object.

Now if you turn global to no on the Text object, observe:

On layout switching, the Text instance from layout 1 disappears (gets destroyed).
Still you can create a new instance of Text on layout 2. The object Text itself is "global"/reachable from the whole project.

The sprite in layout 2 is global.
Clicking it leads to layout 3.

The button2 in layout3 just takes back to layout 1.

You can see with global set to yes, from now on, the Text instances and the sprite appear in every layouts.


Global only apply to instances, not to the object itself. Every objects are "global" to the project by default.

In mina's capx, I think the trouble comes from the layer.
In the "startup of layout" of Event sheet 1 (event 64), you have to "move to layer 3" for text_lives, sprite2 and text_score.

Make an experience, make sprite4 in layout1 invisible (it is the background, btw mina, you should rather use a tiledbackground object than a sprite there, you could then use a smaller texture (base png) that will repeat itself automaticly and make the project and then download of the game in the end smaller, so better).

You can see, the instances of text_lives, etc... are on layer 0 (they stay in place when you move to the right).
In fact, each time you execute the layout 1 again, the sprite4 of background gets drawed over the global instances that traveled through the different layouts, keeping their properties.
@zenox98: It makes sense that they don't get moved back automaticly to the layer3. In fact in the case of non global instances, they would be moved/spawned back. The instance is set for this specific layout.
But since you're using global instances, that are non limited to a specific layout, it's your responsability to move/handle them.
The layout sort of "ignores" them.

I must admit I was confused with this too. Reading the manual and testing in C2 helped.Kyatric2011-12-09 21:21:05
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: 6,999
Reputation: 57,793

Previous

Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt, Matthew de and 4 guests