[SOLVED] Trying to create a custom behaviour

I’m trying to change my events in a behaviour.

As events, it works correctly; as a behaviour, my character doesn’t move.

I already tried following the wiki, and here’s where I’m stuck.

This is my screenshot:

My original events can be seen here: [SOLVED] Pause a custom event movement

The only voices that change are “Player” and “Water”, that become respectively “Object” and “Obstacles”.

“Sentence in Event Sheet” is: PARAM0 moves; PARAM1 is behaviour; PARAM2 animation; PARAM3 is an obstacle

My parameters:
gd2

gd3

There are no object groups.

You should use the “log in console” action to see what actually happens.

This is what the debugger displayed:

I meant this action:

You can use it anywhere you want to know if actions are run and with what values.

I’ve never used it. This is what I’ve done.

I put that action in every event, but only to “move up”:

The debug displayed an endless message with a constant growing number:

This happens even if I don’t push “up”.

Usually, you put a text that describes what happens and interesting values. This way you can follow what your program is doing.

I’ve corrected some of my errors. The message “executed” was made put the action in the scene instead of the Behavior.

Now I’ve renamed all of my 4 movements with “move up”, “move down” etc. messages:

Trying again the debugger doesn’t display any message:

Your messages are not logged. So, the actions are not run.

Do you call your function somewhere?

This is what I done for logging:
gd1

I really don’t know. Please, give me some example.

Sorry if I’m slow. Obviously, I’m trying to read the documentation to understand better what I’ve to do.

You said earlier

Is event in the scene and does it have any conditions?

Also, if you are making a behavior, it needs to be assigned to an object and there needs to be at least one object in the scene with the behavior.

1 Like

I’ve put the behaviour on my character:

The event isn’t in the scene. This is my scene:

Here there are my files: Test Grid Movement Behaviour

There were several things. First, the file you sent me the behavior wasn’t assigned to char. It turned out the behavior was assigned but it was hidden. For some reason the behavior and function were both set to private. I made them public.

image

image

There also wasn’t an obstacle object or an action to trigger the function. So, I added both. You need to have an action that triggers the function and supplies the name of the obstacle object.

It then worked except pressing right caused it to go up. It was reducing Y instead of increasing X.

The highlighted line needs to be x position plus 1.

Once those changes were made, it seemed to work. It doesn’t have animations, so I added one and tested just the one and it seems to work.

I’m a bi confused but I confused you maybe.

I made two scenes to compare my behaviour without closing and open another project.

The character in the Untitled scene is the one where I created the events, the one with the water.

In the scene2 there’s another character which I tried to create the behaviour and I attached it to the character Char. In the Untitled scene2 there’s no water.

The two scenes were made for comparison.

I’ll attach another file with only one scene if you don’t mind to take a look at it: Test Grid Movement Behaviour only one scene

I say sorry in advance if I’m making this post longer, I’m not in my best shape these days (illness). I sounds that I miss some piece of the topic :dizzy_face:

Which scene is causing the problem? As I said, there were minor issues with the scene with the behavior. The function in the behavior has to be called from the scene. The function needs to be visible to be able to be added. The one direction was changing y() instead of x().

I initially thought the behavior wasn’t attached but that was only because the behavior was set to private.

edit: I added a water object because the function needs an object to test against

I changed Y() to X()

The animation doesn’t change because there aren’t any assigned to char but otherwise after those 3 changes, it seems to work. Yes?
ScreenRecorderProject5_3

1 Like

I’ve noticed that this is my main error. I though that custom behaviours worked just like the regular ones, but now I know they must be called.

I’ve changed the water obstacle as a tiled sprite and added the water on my scene.

Everything works perfectly. Thank you so much. I’ll sign this post as solved.

1 Like

There doesn’t seem to be an easy way to control other objects from a behavior. Just like a function they’re independent or self-contained.

You can use functions within a behavior, it’s the use of other objects that needs an outside function call or the other objects also have a have a behavior.

Most behaviors/extensions seem to use a function when using additional objects. Except for the path finder or platform behaviors which use separate behaviors. I guess you could have 2 behaviors, one for the player and one for the obsticales. Or use the same behavior and the option to choose whether it’s a player or obsticales sort of like the physics havior has a static state. I don’t know how objects with behaviors communicate with each other. I’ll have to look into that. I know with Javascript, you can pick objects by their name using a string.

I’m not sure how the physics objects interact with other objects that have the physics behavior. Although , even it requires the other objects to have a behavior.

Anyway, I’m glad it’s working.

2 Likes