Tips for creating re-usable code/events

0 favourites
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • I tend to start new projects on a whim. More than I should. I'm sure I'm not alone.

    It is frustrating to have spent a significant amount of time on perfecting a feature, something basic like controls or camera movement, then have to recreate it from scratch if you want the same thing in a new project.

    I wish instead of receiving the error message when trying to paste events where an object is missing it would give you the option of replacing that object. The only foolproof way I can think of is to make a block of code made up of only functions and variables so you can paste all at once and fill in the results of the final functions.

    Would a real life example help?

    Take a second to look at this project and click/touch the screen to view the on screen controls.

    http://bit.ly/Ninja0619

    What would be the simplest way to get those on-screen controls into a new or another existing project?

    Even if I added the control sprites it still wouldn't paste over because it would say the player, sword, shuriken, etc are not present in that project. (not that I want the sword or shuriken in a new project).

    If I setup the controls in a project by themselves is there a way to include a whole project? Then the event sheet could be used by 'include' and the sprites set to global so they would appear on every layout.

    Same with the Zelda-like camera pan. The events are driven by the location of the player so wouldn't paste. Removing the events involving the player object/sprite would remove most of the work.

    Please don't interpret this as 'being lazy'. Attempting to practice DRY.

    Any serious game probably deserves completely customized events, but one of the reasons I enjoy Construct, say over Unity, for certain things is being able to think up and idea and quickly get something up and going to see how it looks. I don't want to sit there and re-event basic movement, animations, camera, etc for the nth time all on a whim.

  • The only real way to do this is to re-create your objects in the new game with the same names, then rename everything afterwards to suit.

    The other option is to have a more "generic" name for stuff - so instead of "sword" have "weapon" - but again you'd still have to recreate the objects in another game... but at least you may get away with not renaming everything again afterwards.

    Ultimately it comes down to C2 really lacking the feature to efficiently copy and paste event sheets between projects. It's a big improvement over CC's abilities to do the same thing, but hopefully in C3 there will be full support for this type of thing - as well as collaboration abilities. It's frustrating working on a project with multiple people, and only one person can work on it at a time.

    ~Sol

  • The only real way to do this is to re-create your objects in the new game with the same names, then rename everything afterwards to suit.

    The other option is to have a more "generic" name for stuff - so instead of "sword" have "weapon" - but again you'd still have to recreate the objects in another game... but at least you may get away with not renaming everything again afterwards.

    Ultimately it comes down to C2 really lacking the feature to efficiently copy and paste event sheets between projects. It's a big improvement over CC's abilities to do the same thing, but hopefully in C3 there will be full support for this type of thing - as well as collaboration abilities. It's frustrating working on a project with multiple people, and only one person can work on it at a time.

    ~Sol

    If so it sounds like the best option is to duplicate the capx and delete out everything I don't want to keep. Thanks

  • I re-use a lot of my events in different projects and it is a huge timesaver. It really just comes down to planning to do this and always using the same naming conventions. Like Sol said, generic names work best as they're easy to remember and will be relevantly named between projects. Once you start to consciously plan to reuse events and name objects accordingly it becomes pretty painless.

  • The best option is to use familys & local variables. Keep the instance variables, behaviours & effects on the family.

    This way, if you have a bunch of events that you want to re-use, al you have to do is create the familys in the target sheet. Can add any object (with any propertys) to those families.

  • The best option is to use familys & local variables. Keep the instance variables, behaviours & effects on the family.

    This way, if you have a bunch of events that you want to re-use, al you have to do is create the familys in the target sheet. Can add any object (with any propertys) to those families.

    Is this in reference to doing so between two separate projects? That is what the question is targeting.

  • I re-use a lot of my events in different projects and it is a huge timesaver. It really just comes down to planning to do this and always using the same naming conventions. Like Sol said, generic names work best as they're easy to remember and will be relevantly named between projects. Once you start to consciously plan to reuse events and name objects accordingly it becomes pretty painless.

    So it will let you paste events over if there is an object named exactly the same that has the same instance variables and behaviors?

  • Yes, ofcours.

  • Construct2 does not allow you to copy and paste events from different Capx projects. It may sound time consuming, but including the function object, and having a separate events sheet only for common functions has worked for me.

    You won't be able to copy+paste the event sheet, but at least it is easier to duplicate your functions.

  • Construct2 does not allow you to copy and paste events from different Capx projects.

    Are you SURE about that? Pretty sure you can, as long as the same objects exist with the same names... I know because I've done it, lots of times.

    ~Sol

  • Yes, ofcours.

    Okay, I think I misunderstood at first.

    So basically you are suggesting instead of re-creating objects to re-create the families. Have all the events target families thus less to reproduce.

    Construct2 does not allow you to copy and paste events from different Capx projects. It may sound time consuming, but including the function object, and having a separate events sheet only for common functions has worked for me.

    You won't be able to copy+paste the event sheet, but at least it is easier to duplicate your functions.

    I think I'm on the same page with you here. It will let you copy and paste functions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My bad Sol. Never done it with same objects and same names.

  • A tactic I've been trying lately is making stuff in separate projects with the intent to push them into the main project once it is working how I want it. The advantage with this is that, because it is in another project I can focus on minimizing the implementation of it to a point where it is easy to transfer to another project.

  • Construct2 does not allow you to copy and paste events from different Capx projects. It may sound time consuming, but including the function object, and having a separate events sheet only for common functions has worked for me.

    You won't be able to copy+paste the event sheet, but at least it is easier to duplicate your functions.

    Sure it's possible, as long as the object and and behaviors are the same (if used)

  • My bad Sol. Never done it with same objects and same names.

    All good mate. It definitely works but yes, you MUST have all of the exact same objects, object names, behaviours, global variables, instance variables etc (if they are referenced in any of the events you're copying over anyway). There does seem to be issues however with events not applying the correct actions when it comes to some behaviours though - the actions will often change to something arbitrary.

    I think the best way to really re-use code is to make some sort of template file that you can use to start building your new projects from... so think along the lines of a "platformer template" or an "infinite runner template" etc, where you load that up and savre it as a new project file, but it gives you some basic building blocks to work from.

    ~Sol

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