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?
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.
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?
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.
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:
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
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?
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 !
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.
You should learn to use the debugger
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)
If the effect works for half a second or not at all, maybe you have a conflict with another event.
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…
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.
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.
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.
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.