Stop C2 checking global variables on new layout

Get help using Construct 2

Post » Tue Apr 29, 2014 4:22 pm

Everytime I go to another layout while having an event such as:

If GlobalVariable1 = 0)
>>Destroy the world

Every time the layout switches, it rechecks to see if this variable is 0 (and if it is, it destroys the world...again). Is there a way to avoid something like this?
B
44
S
12
G
1
Posts: 545
Reputation: 4,271

Post » Tue Apr 29, 2014 4:26 pm

Have all the layouts the same Event Sheet? Take a look to the layout properties. "Event Sheet". If so, check on what layout you are.
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Tue Apr 29, 2014 4:30 pm

on end of layout reset global variables
or
on end of layout set "globalvariable1"=1
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Post » Tue Apr 29, 2014 4:40 pm

@DAG Yes - all of my layouts are using a "Main" event sheet, and then subsequent event sheets for the specifics levels.
@Roccinio - the thing is, I don't want the global variable to change. It widely affects other events, and switching it to 1 when changing the layout will ultimately re-trigger the event anyway when switching it back to 0.
B
44
S
12
G
1
Posts: 545
Reputation: 4,271

Post » Tue Apr 29, 2014 4:54 pm

then you are doing it wrong,there is a reason they are called global,
try this.
create one event sheet for each level you have.
copy paste all events to all the event sheets you have.
Do not include one event sheet to another.
lets say you have 100 levels
set global variable "level" to 0
when you finish a level
on end of layout "level 1 "set "level:=1
on end of layout "level 2 "set "level:=2

on start of layout "level 2" "level"=1 destroy "level 1"
on start of layout "level"=3 "level"=2 destroy "level 2"
etc
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Post » Tue Apr 29, 2014 7:11 pm

@Roccinio - the reason I don't want to do that is if I want to change something that happens in all 100 of those levels, I would have to change the event 100 times...for each time I wanted to change it (sometimes I can't make up my mind!)
B
44
S
12
G
1
Posts: 545
Reputation: 4,271

Post » Wed Apr 30, 2014 4:42 am

You may want to rethink how you are approaching it if you don't want things to work they way they were designed to. I want my car to fly. But we don't make flying cars. But I want it to. You could possibly create another global variable that is either true or false, and add a condition that checks for it with your end of layout condition. So you say if end of layout and superVariable = 1, then blow up the world, that way you can set superVariable however you want in the layouts that should not blow up.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Wed Apr 30, 2014 7:03 am

@BluePhaze,

I'm sorry, but it seems incredibly silly to make something like a menu or interactive controls that will be used on every layout, and instead of using #Includes, copy/paste the events to 100+ event sheets.
B
44
S
12
G
1
Posts: 545
Reputation: 4,271

Post » Wed Apr 30, 2014 5:04 pm

If you want to get around global variables being global you are going to have to have something that is different on the ones that you don't want it happening on. That is just the way it is. If they are all the same with the same logic, you don't have a way to differentiate.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Wed Apr 30, 2014 5:09 pm

It's really not that hard. I have used an invisible object with an instance variable before. I drop and instance of it in each layout and set the instance variable accordingly. My events use it. Not hard. It's not unheard of to think that if you have 100 different layouts and you don't want to key off their names (which are unique and would work also) then you are going to have to make something different in each one. Your events in your "global" event sheet just needs to take that into account. Using the method I mentioned already doesn't really add much to the complexity or effort when building layouts. It is as simple as dropping an object (which you are already doing on each layout) in and setting a variable on it. Trying to do it after the fact may be a pain but that is just poor planning and not a deficiency in the way the tools work.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests