Use multiple global variables with the same name

Get help using Construct 2

Post » Thu Jan 30, 2014 9:43 pm

Hi!

I want to know if it is possible to use mulitple global variables with the same name in different event sheets.

I got a game with different levels.
Seperated in:
Level 1 = EventsheetLevel1
Level 2 = EventsheetLevel2
etc..

I want to use global variables in both event sheets with the same name but i can not make duplicates.

Can any one tell me how i am able to do this?

One way i can think of is including all global variables in one sheet, and in the different sheets set the global variables.

So it would be:
EventsheetLevel1
SET GLOBALVARIABLE1 1 = ....
EventsheetLevel2
SET GLOBALVARIABLE1 34 = ....

That way it is possible but the way to edit it is way more time taking than just normal global variables.

Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Thu Jan 30, 2014 9:52 pm

A global variable is global and as such can be used in your whole project. If you'd like the variable to have different values in different levels you will have to set these values in the event sheet.
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 30, 2014 9:55 pm

I do not know what you mean for sure.

What i got now is eventsheets like:
Eventsheetlvl1
Eventsheetlvl2

And on the layout i do it like:
if level = 1 include Eventsheetlvl1
if level = 2 include Eventsheetlvl2

Thats works great, but i can not use duplicates of global variables.
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Thu Jan 30, 2014 10:05 pm

There is no need for duplicates, for the variables are global.

On start of layout - set global variable
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 30, 2014 10:08 pm

Hi,

Yeah i was afraid so. I actually did that. The same way as including the sheets so i can use my sheets as level variables. Works perfect but global variables would be much easier to modify.

Well thanks! I continue using the method i used and you just told.

Thanks!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Thu Jan 30, 2014 10:20 pm

global variables are global.

If you'd rather use local variables, which are local, just create a group and put all events in the eventsheet as subevents of the group. that way you could create new variables with the same name on every event sheet.
Why you think that would be easier I have no idea, but it is possible.
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 30, 2014 10:29 pm

Make different variables, set them differently or use instance variables for specific things?
B
33
S
9
G
3
Posts: 493
Reputation: 4,042

Post » Fri Jan 31, 2014 2:18 am

Why not set the global variable back to 0 (or whatever you need) upon layout start?
B
73
S
10
G
6
Posts: 105
Reputation: 7,577

Post » Fri Jan 31, 2014 5:50 am

Just to recap, GLOBAL means it is used everywhere, it is not just tied to the Sheet where you declared it. If you want to have variables with the same name in each layout, you can do like I do and add an invisible sprite to each layout with instance variables and set them to different values in each layout. Then you can just use one event to talk to them in each layout since they have the same name in each one.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Fri Jan 31, 2014 6:44 am

@Buephaze

I think topicstarter would rather not use events to set the variable.
I guess he wants to see the global variable on the eventsheet, so he can insert/change the value there.
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

Next

Return to How do I....?

Who is online

Users browsing this forum: plinkie and 16 guests