Tips for creating re-usable code/events

Get help using Construct 2

Post » Sat Jul 02, 2016 3:07 am

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.
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jul 02, 2016 3:49 am

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Sat Jul 02, 2016 6:33 am

SoldjahBoy wrote: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
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jul 02, 2016 9:17 am

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.
B
64
S
25
G
4
Posts: 204
Reputation: 6,993

Post » Sat Jul 02, 2016 11:37 am

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jul 02, 2016 2:33 pm

99Instances2Go wrote: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.
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jul 02, 2016 2:34 pm

signaljacker wrote: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?
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jul 02, 2016 2:48 pm

Yes, ofcours.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jul 02, 2016 2:54 pm

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.
B
28
S
10
G
10
Posts: 97
Reputation: 6,584

Post » Sat Jul 02, 2016 3:08 pm

makotto wrote: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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Next

Return to How do I....?

Who is online

Users browsing this forum: evillair, Exabot [Bot], LunchboxGames, NumberOne, rekjl and 16 guests