How do I create an organized engine?

Get help using Construct 2

Post » Sun Sep 27, 2015 8:25 pm

I see all sorts of tutorials here about how to do specific things for a game (like making inventories and such) but I do not see any on how to make a good framework/engine. Every time I attempt to make a game that is more than 200 events I end up getting pretty lost and everything seems to turn into pointless spaghetti code.

I realize that this requires practice but I really am unsure what the best way to make a larger than usual game would be.
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Sun Sep 27, 2015 8:47 pm

This is a pretty complex subject, and there's a lot of advice that could be given. Being a software engineer by trade, I can give a few tips. Abstraction is your friend, as is the separation of logical systems. Smart use of things like families and generalized functions aid the former, while the use of separate event sheets/groups are good for the latter. The key is to not let a single system get too complicated. If a system -- such as an inventory, for example -- begins to get too complicated, you should step back and see if it can be broken up into multiple connected systems instead of one monolithic one.

Remember: complex is better than complicated.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sun Sep 27, 2015 8:55 pm

as @linkman2004 said .. you need to keep your events as i like to call the method SAS ( simple and stupid)

that way youl find your way around the huge code ur engine that you build.

having small codes with comments on each one what it does and for what purpose will help you later on, when youl need to fix 1 small bug. comments sometimes are a bit to hard to read... and might confuse you... but with the help with search events.. and having he right comment placed above it.. youl find you way very fast.. and with little frustration.

i started splitting my code in multiple event_sheets lately.. because of the same reason.. i wold had 1 big event system and couldn't understand nothing after 2 days when i wold get back to it. either lack of comments.. either to many comments which tends to get frustrating to read ... so i just used small and many method.. and i know where to find what !


Edit: lol... sometimes i talk spaghetti English also ... so it confuses me more... like the above post i did... i guess im tired.., you got the idea now :) its going to take more time to keep it organized.. but we have to think that its for our own good, and also for the good health of people that works with us.
Using C2 its so addictive, to not care of the code inside, since its wrapping everything fast.. but when u have huge projects... that doesn't work that well.. and we need to organize things! :D have a rad night!
Last edited by gamecorpstudio on Sun Sep 27, 2015 10:06 pm, edited 1 time in total.
B
78
S
23
G
69
Posts: 1,354
Reputation: 44,027

Post » Sun Sep 27, 2015 9:11 pm

Thank you @gamecorpstudio and @linkman2004

I think my main problem was that I was using only one event sheet for my entire game and I would make each system too long without looking at what could make it simpler.

One specific thing I had trouble with was a crafting system I was trying to make. I used a long string of events just to make it so the player could create one item. Could this be simplified with the dictionary or some sort of table?
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Sun Sep 27, 2015 11:30 pm

Here is something I wrote some time ago for another post, Thought it might be useful for you as well when it comes to organizing large projects or just project in general that I as least find useful.

Here are some advise that might be useful.

1. Clean up
Objects that you don't need to be there from the start, by this I mean sprite objects that would be "Units", "Bullets" etc. you should destroy at the beginning of the game. This is simply to make sure that you don't have rogue objects in your program.

2. Precise functions
Make as small and precise functions as possible. Even though some of these functions might seem to simple for it to make much sense.

An example of why this is a good idea. Imagine you have a "Car" object and in you code you might change the speed to whatever you think is fine. like "Car.speed = 100". This would be fine until the point you decide that it could be fun to add something like, if the speed gets above a certain value the car should start loose control. If you add it in your code you would have to change/test for it every time you changed speed. But with a function you can simply add the test here and update it for the whole program at once. So using loads of functions is in my opinion one of the best ways to maintain an overview of your project, but they are very easy to replace, maintain and bug fix as you know what inputs and outputs they have.

3. Global constants
This can be very useful for reducing spelling errors, and to quickly change things in your game. Imagine in the above example, that you have several "Car" objects, which are categorized by a type, "Cheap car", "Normal car" and "Expensive car"
If you in your code manually add checks if ( Car.type = "Cheap car" ) and then do something, at some point you might figure out that the name "Cheap car" weren't that good an idea after all and something else would actually have been better, then instead of having to go through your whole code and replace "Cheap car", you can just update one global variable instant.

4. Use several event sheets
Don't be afraid of using event sheets even though you might not add a lot to them. It will really help you maintain an overview of your game.

5. Split events and functions
Unless you are 100% sure that an event sheet should only be used one place, its always a good idea to split events and functions, even though they work on the same object. So an event sheet called "Car events" and "Car functions" would be a good idea. You can always move functions later on, but think it good practice to just get used to splitting them. The reason for splitting them is that Functions wont execute without being called, so if you suddenly figure out that the functions in a event sheet could be useful in another, but have mixed a lot of events into it. You will have to move all the functions to a new event sheet to avoid unwanted problems of events suddenly executing when they shouldn't.

6. Requirements and returns
When making functions I find it very useful to add comments above them with requirements, and potential return values. This will make it very easy later on as you move along and might forget what a function actual does when you return to it.

An example could be like this:
Image

7. Bug sheet
Make an empty event sheet, that you just use for comments. You don't include it in your program. But the purpose is that as you test your game and might be testing something, suddenly notice that something else is not working as intended. Then instead of fixing it straight away, you just in your "Bug event sheet" add a comment explaining what you noticed. And if possible the cause for it. Then you can always fix it later and you wont forget about it.

8. Quick reference function sheet.
This can be a bit time consuming but very useful. The idea is again to add an event sheet that you don't include in your program. But you simply add function calls to it, with the required amount of parameters.

Image

This can speed things up quite a bit as you can just copy/paste function calls from this sheet to wherever you need them, and just update the parameters, and you don't have to remember the name or how you spelled the function name etc.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Sep 29, 2015 3:08 am

Thank you @nimos100 this is very helpful.
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Tue Sep 29, 2015 10:34 am

Hi guys, first time poster here.
A couple of questions on this topic:

- The manual states that event sheet includes are a kind of automatic copy-paste. Am I right thinking that the included sheets are evaluated first and the "host" sheet follows?

- Lets say I have 2 different sheets: One to handle sound&music and another to handle visual FX. Is it a bad practice checking for the same event on both sheets but triggering different actions? e.g.

EVENT SHEET 1 (Sound&Music)
Player collides with Enemy --> Play sound "GotHit"

EVENT SHEET 2 (Visual FX)
Player collides with Enemy --> Player Spawn object "Explosion"
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Tue Sep 29, 2015 11:16 am

immortalx wrote:Hi guys, first time poster here.
A couple of questions on this topic:

- The manual states that event sheet includes are a kind of automatic copy-paste. Am I right thinking that the included sheets are evaluated first and the "host" sheet follows?

- Lets say I have 2 different sheets: One to handle sound&music and another to handle visual FX. Is it a bad practice checking for the same event on both sheets but triggering different actions? e.g.

EVENT SHEET 1 (Sound&Music)
Player collides with Enemy --> Play sound "GotHit"

EVENT SHEET 2 (Visual FX)
Player collides with Enemy --> Player Spawn object "Explosion"


It doesn't realy matter. The event sheet is read top to bottom with included sheets as if they were pasted in at the points you included them. I say doesn't matter because it is read top to bottom every tick, and that is multiple times a second so it makes very little difference. It is purely benificial for you to structure your code by breaking it up (which is recommended)

But you would include a sheet called player collides with enemy into your main sheet.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Tue Sep 29, 2015 6:38 pm

@DUTOIT thank you very much!

Excuse my poor English (not a native speaker), but I'm not sure I understand the second part of your answer.
I should have said that if I have a main sheet with 2 additional sheets included, can each of the latter 2 sheets have the same event in them? (and of course each one trigger a different action)
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Tue Sep 29, 2015 7:43 pm

Yes you can, but that is bad programming. It is best to group things together in such a way as you can come back to it 1 year from now and now where to find it.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Next

Return to How do I....?

Who is online

Users browsing this forum: Iquerno, Team EternaL and 38 guests