GDevelop-examples icon indicating copy to clipboard operation
GDevelop-examples copied to clipboard

New example: Events Functions Patterns

Open arthuro555 opened this issue 3 years ago • 10 comments

Describe the example

This example shows how to use a few popular programming patterns via events functions for helping to develop a game. The patterns that are shown in this example:

  • [X] Encapsulating multiple conditions into one (in this example for input management)
  • [X] Encapsulating events into a custom behavior (reusing input management as an example)
  • [X] Service Locator pattern (in this example for switching between an AI and a User input for player 2)
  • [X] Object-oriented programming (3 example scenes for showing using it generally, how to do inheritance and how to do composition)
  • [X] State pattern (Making a platformer FSM with an events based behavior)

Checklist

  • [X] My game has a proper name in the game properties.
  • [X] My game package name behind with com.example..
  • [X] My game has all events unfolded.
  • [X] I've added myself as the author in the game properties.
  • [X] I've included a file called "README.md" with a description in proper English, explaining what this example is doing.
  • [X] I confirm that this game and all of its resources can be integrated into this GitHub repository, distributed and MIT licensed.
  • [X] I've cleaned unused resources.

Game folder

FunctionsPatterns.zip

arthuro555 avatar Oct 02 '21 13:10 arthuro555

I did a quick look at the project (I will do a proper review this weekend)

  • There are some empty extension. I don't know if it's because of the dunder __ in the name and the functions are not visible. It would be better if they are left open for the user or remove if it's the first case

  • In the properties update, I changed the package name to start with com.gdexample so that the examples can be differentiated from projects made with gdevelop with the package name updated. ANd also to make the packgame name unique. It would be great if this is followed from now on :)

  • There are two usused Holly_standing and Holly-hurt image

:)

Midhil457 avatar Oct 07 '21 15:10 Midhil457

Hi, adding to my first review

  • Some topics shown in this example have their wiki pages, (FSM, behavior, functions) so you could add a link to the page if anyones needs a step by step guide

I have added my few suggestions in here: FunctionsPatterns2.zip

Midhil457 avatar Oct 10 '21 07:10 Midhil457

There are two usused Holly_standing and Holly-hurt image

Whoops I thought I'd deleted all unused assets 😬

In the properties update, I changed the package name to start with com.gdexample so that the examples can be differentiated from projects made with gdevelop with the package name updated. ANd also to make the packgame name unique. It would be great if this is followed from now on :)

Is it a new best practice? Sorry i did not know about it.

There are some empty extension. I don't know if it's because of the dunder __ in the name and the functions are not visible. It would be better if they are left open for the user or remove if it's the first case

I thought their naming, emptyness, lack of icon and placement made it fairly obvious that they are distinguishing extensions from the extension library from extensions that were made for the examples sake (as it shows how you can use events based extensions for your game specific logic too). I'd keep them personally.

Some topics shown in this example have their wiki pages

Good idea, I would not do so for FSM though as iirc the wiki page is a tutorial about making those with external events and would confuse the user's since this is about making stuff with events based extensions.

arthuro555 avatar Oct 10 '21 09:10 arthuro555

About the "Service Locator" example, the main idea of these patterns aiming to reduce coupling is to use common interfaces. The example breaks this by communicating directly to one implementation using scene variables. An action "Move among _OtherPlayer_" could be added in MultiplayerService to have something that looks like an interface. An AI will probably need a state at some point so behaviors would be a better fit. The MultiplayerService behavior would have the same interface as "AI" behavior and "Player" behavior. It will delegate to one of them according to a state. And here is a State pattern (approximately).

About the OOP examples, why not using objects and behaviors?

D8H avatar Oct 10 '21 12:10 D8H

The example breaks this by communicating directly to one implementation using scene variables.

I agree that this is suboptimal and it frustrated me when I ended up doing that. I did think of adding an action on the services for that but don't quite remember why i decided not to. I'll look into it again.

An AI will probably need a state at some point so behaviors would be a better fit.

This is more about showing the pattern than it is about showing the optimal way to code an AI/Human second player. Doing it with behaviors would kind of lose its purpose as it would be more of a State pattern (as you said). Originally i was making an example that makes more sense (a generic networking service that can switch between a P2P Provider and an MQTT provider), but I realized midway that it was way too complex and that since all I want to do is explain the patterns in this example, this input switching would be easier to understand.

About the OOP examples, why not using objects and behaviors?

I could ask the opposite question; Why would I use objects and behaviors for those? I am assuming you mean using an object instance as an instance of a class defined by a behavior attached to the object. In GDevelop, objects are only visual elements, with the exception of the text entry that many said shouldn't have been made an object in hindsight. It just doesn't make sense to me to use a GDevelop object in that context since it is strictly representing data, not any elements to display.

arthuro555 avatar Oct 10 '21 19:10 arthuro555

Is this submission still being worked on? If not, this will be closed :)

Midhil457 avatar Dec 11 '21 09:12 Midhil457

I wasn't, thanks for the ping. I'm on it.

arthuro555 avatar Dec 12 '21 19:12 arthuro555

There, I addressed the reviews comments that I agreed with: FunctionsPatterns.zip

arthuro555 avatar Dec 14 '21 23:12 arthuro555

Sorry for the late review :sweat_smile:

  • In the Scene OOP: Inheritence under the Spawning of new enemies group, there is an event that is disabled that I think it's needed
  • Is the flexbox extension used anywhere? The project's resolution doesn't change, so I don't see a point in having it anyways
  • Unfold all the events

I can approve this after these changes are made. If anyone wants to do a review after me, feel free to do so :)

Midhil457 avatar Dec 20 '21 13:12 Midhil457

Is the flexbox extension used anywhere? The project's resolution doesn't change, so I don't see a point in having it anyways

I have not checked yet what the usage is but fyi the flex box extension is not for adapting to changes in resolution, it is for positioning objects that may be of different sizes in a way that keeps them all in the bounds of another object.

arthuro555 avatar Dec 20 '21 14:12 arthuro555