[Solved] Help with functions please


I need some help with functions. I’m trying to convert as many of my external events into functions/behaviors as possible as the list is getting quite long.

I’m having trouble with some of my power-up items, specifically timed ones (shields and boost crystals). They are working when I use them in external events, but not in functions. It’s probably an issue of using the wrong types of parameters or not including ones that I should.

So how to convert them into a properly functioning function? :crazy_face:

I have tried using number type parameters to call the scene variable - I entered “Variable(jump)” into the action and also tried making them as both conditions and actions. I’ve tried using timer and platform behavior expressions, etc. to no avail. I’m missing something and I don’t know what…

The following images are working code from the external events.

This one had to be in two parts.
The top of the second is a continuation from the first, it’s not actually in my code twice :wink:

I would post the function code, but it’s pretty much the same so…

Can anyone tell me exactly what parameters and/or expressions I need?

Please and thank you :slight_smile:

1 Like

Is a ‘dummy project’ needed?

I haven’t used functions so far, but I think you can export these separately?

You’re saying the problem is with timed items, so if you haven’t done that yet, you should try to use the timer feature inside a basic function, to make sure you handle that properly.
Can you be more specific about what is happening/not working?

Thank you for your reply.

I can indeed export them separately. But I’d still have to create a dummy project so you could compare how it works in the external event sheets Vs. a function.

I have timers in other functions already (for example, enemies shooting blood) and they seem to be working fine, but for some reason, I didn’t have to add the timers to parameters. The only parameters it has are for the objects themselves. Doing the same thing on power-up items isn’t working, unfortunately.

As for specifics on what isn’t working, it’s just that these particular items aren’t doing what they’re intended to do. Pink and green crystals modify platform behavior properties to temporarily increase max speed or jump speed/gravity, respectively. That’s not happening.

The shields are not blocking damage from blood drops, but they seem to work properly on contact with the broken heart (aka “injure”) enemy.

Okay, here’s a project ZIP for testing. It includes a testing scene, external event sheet called “powers”, and a behavior/function called “Boosters”. I’m only including the code from my crystals, but no actual assets.

I left out the shields because they were in another function and there are no enemies to test with.

I’m having difficulties solving your issue, I wonder if it’s related to that:
(Changing the platformer behaviour settings from within the function) :thinking:
After some tweaking, the animation change works fine, the timer works fine…
Not sure if it’s a bug, it’s my first time playing with functions.
Let’s wait for a function guru. :sweat_smile:

1 Like

Thank you for having a look anyway :slight_smile:

Problem solved. The platformer behaviour needs to be added as a parameter below the player parameter. I had to redo the platformer settings events because the actions weren’t applied, for some reason.
Here’s for you:

1 Like

So strange, I tried that before asking for help and it still didn’t work for me - maybe I had them in the wrong order or something. Thank you so much! :star2:

Unfortunately, the [Solved] label was applied a bit prematurely.

I changed my function according to the screen capture provided, with some slight adjustments for item name, sound effect, and animation settings - but it still isn’t working. My player object isn’t even colliding with the crystal now :frowning:

How was it added to the scene’s event sheet? I’ll be using an external sheet to call the functions, but the events should be the same anyway. Are there any other parameters under “boosty” that I need to include?

Ah… As I said, some changes didn’t work until I recreated the events, did you do that?
Either that or you made an error in your adjustments…
No other parameters under boosty.

Edit: the system says you are not accepting private messages, here’s the json:https://send.firefox.com/download/4435490732489ce7/#x0a9i5Awbc_lYhetzHhucg

Yes, I did and as for the adjustments, all I added was:

  • The sound effect that it usually has
  • Score points

Both of the above should be upon collision.

  • The item name can’t be boosty - it’s cute, but there are two different boost items and I need to be able to tell them apart. I’ve triple checked that the renames are spelled correctly.

The boost effect works for maybe half a second, but definitely not 8 seconds.

Thank you for the JSON

Where are all the function gurus?

I’ve seen something about behaviors.

As @Gruk have showed before in screen the behavior is marked like not attached to Object. It’s because in Parameters when we choose behavior type it’s wrote Behavior (for the previous object)
(for the previous object) is very important, it’s the previous object above in parameters.
You need att this platform character behavior if you want change the physic property like gravity, speed … on your player Object

In the event function, you call player as object, but it’s not player, you need call Object, because in parameters the param#0 is Object it’s your player

And about variable fields in functions , you do :
Variable player.Variable(jump) of Object is = 0

Its not correct, you need to do :
Variable jump of Object is = 0

About timers in function :
All is ok here, but if you wish manage something on a object, i prefer use timer of object, but it’s ok here, just don’t add more player, otherwise both players will act on the same timer. In this case, therefore, prefer to use object timers

When you change parameters you need to back in your event here is call the function for set again the values. It’s important !

Try to apply this change and tell me after :wink:

Thanks Bouh, and again to Gruk for your time and efforts.

Sorry, I should have given some updated screenshots for what I currently have in the jump boost function. Aside from the score, sound event, and name of the boost object - I followed how Gruk had it set up in his screenshots and the JSON exactly.

The only parameter I changed was the name of the boost item as again, I have two different ones. I know to update the parameter values in the action where the function is called when these are changed. :wink: :+1:

My function events

My parameters:

PARAM0 - Object (player)
PARAM1 - Behavior
PARAM2 - Behavior for previous object (Platformer character)
PARAM3 - greencrystal (objects > sprite)

The values of the action in my event sheet:


When I test it, the boost works intermittently, for less than a second. This time it didn’t at all.


When I disable the function event and use what I have in my external event sheet (as posted previously), it works like this, which is what I’d like to see from the function.


You should learn to use the debugger :wink:
You need look the variable “jump” of Object and the value of “JumpTime”
Because from what you’re saying. the actions binded with this two conditions are not enable.

On wiki > Interface > Game Debugger and Profiler
(On the debugger you need click on the button refresh manually for refresh the value in debugger)

I’m familiar with how the debugger works, at least in terms of the most basic tasks like opening it, starting the profiler and refreshing/viewing the inspectors to find variables, thank you. :wink:

The value of JumpTime isn’t listed at all, in either case, unless I’ve missed it.

The value of “jump” is 1 when I use my external sheet, but it’s 0 with the function.

If the effect works for half a second or not at all, maybe you have a conflict with another event. :thinking:
We know the collision works because the crystal disappears on your gif, so the issue would be specific to your player/platformer behaviour.
All I can say is that I had to rewrite the behaviour-related events or that part wouldn’t work… :man_shrugging:
Did you try my json on its own and confirmed that it works?

Regarding the value of ‘jump’, be careful, it’s a scene variable in one case, and an object variable in the other case.

Could be a conflict, I don’t know as it doesn’t seem to be an issue outside of using a function. :thinking:

Oh yeah, the collision part is obviously working. Forgot to mention that I fixed it and if I recall correctly after a couple of days, it was simply that I needed to replace “player” with “Object” in my function events. :roll_eyes: :woman_facepalming:

It does work in your JSON, although the boost objects weren’t meant to do the same exact thing; that’s why they had separate functions. Confused me a bit is all, no big whoop.

Indeed, I’m mindful of the scene and object variables. I actually just added the “jump” variable to my player object thinking that was the issue, but nope. I didn’t have it on the object already since I haven’t been using the function outside of testing.

I don’t understand what I’m doing so much differently. My events are basically the same as is in your JSON and I have several other functions with variables and timers that work. I guess I’ll have to experiment more and figure it out like I did with those. If/when I finally do, I’ll share my solution.

Thanks again both.

Me too, it’s like when you edit parameters function you need rewrite the event, here i was forced to rewrite or re-bind the object in properties of your events.
I don’t know if it’s just me or something not refresh in GD, I can’t reproduce the problem.