Code Structure

0 favourites
  • 4 posts
From the Asset Store
Two levels with two sistem Wave. with Source-code (.c3p) + HTML5 Exported.
  • 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!

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    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 :)

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)