Code Structure

Get help using Construct 2

Post » Fri Feb 01, 2013 6:10 am

Hi guys and gals,

So I've programs previously so I'm familiar with functions, I like the way I can group up code and call it when I need to so I'm not cluttering up my screen. When I code in construct 2 I'm not sure how divide up my code.

So I started putting all my "A start of layout" at the top, but then I found I had a lot of them so I started dividing the code into entities like sprite1, sprite2, etc.

So how should I do it? I was thinking of using separate even sheets for each entity and another for the layout. So I;d have all the code effecting each entity under there own event sheet and the all my "start of layout" and generic stuff in my layout event sheet.

Dose it make sense, is there a better way to organize your code?

Thanks!
B
15
S
1
G
3
Posts: 47
Reputation: 1,912

Post » Fri Feb 01, 2013 6:49 am

@ShabbyCat - if you have a whole bunch of "on start of layout" events and actions for each sprite you can stick them in the same "on start of layout event".

eg.
on start of layout
        > sprite1 destroy
        > sprite2 set opacity 50
        > sprite3 set x to 50
- system compare varible1 - is greater than 1 (sub-event)
        > sprite2 set sprite2.angle to 90

is this what you mean?
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Fri Feb 01, 2013 6:54 am

[QUOTE=ShabbyCat] Hi guys and gals,

So I've programs previously so I'm familiar with functions, I like the way I can group up code and call it when I need to so I'm not cluttering up my screen. When I code in construct 2 I'm not sure how divide up my code.

[/QUOTE]

Personally I prefer using lots of Groups to group things nicely. For example I have group called "Interface" that holds everything related to interface in it. "Controls" hold everything related to player controls. "Enemy Logic" could be stuff the enemies do and so forth.

Lot of the time I find functions unnecessary, although they can be nice way of dividing your code into high level events that are executed in the functions.

Combination of these works best for me: Grouping simple events (simplified via functions if necessary) into logical groups. So you have the 'high level' logic neatly as one single list, and all the dirt and detailed functionality in the functions or related events.

These are just my personal preferences, hope you find some help in there :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Fri Feb 01, 2013 8:10 am

I love to keep things organised, and with my current project closing in on 400 events (at this rate it'll push 1000 when completed), I have to.

For starters, I've put global variables into their own event sheet. I've also put all reusable game logic into its own sheet called Main Mechanisms. Then, every level/screen/etc has its own sheet, which is a very trim, very neat little thing that I can use to change level parameters quickly.

I use groups extensively - probably have about 40 at the moment. And sub-groups too. Basically, whenever an event looks like it's going to be larger than the height of my screen, I put it in a group, together with anything that would logically go with it. All my initialisation stuff is in its own place, so are my settings for mobile, my controls, AI, world events, etc.

Getting organised early and staying that way is good practice.
B
56
S
15
G
10
Posts: 910
Reputation: 11,972


Return to How do I....?

Who is online

Users browsing this forum: Megavolt and 0 guests