GDevelopApp / GDevelop-extensions

Repository of behaviors, actions, conditions and expressions to be used in GDevelop for creating games
https://gdevelop.io
MIT License
131 stars 52 forks source link

FlashLayer: Make a layer visible for a specified duration of time #76

Closed tristanbob closed 3 years ago

tristanbob commented 3 years ago

<<NEED HELP, SEE NOTE>>

Describe the extension

Make a layer visible for a specified duration of time Useful to make a temporary effect (flash on hit, flickering lights, lightning flash, show text like Batman and Robin "Bam!", etc) It is recommended to select a layer on the top, and that is hidden by default.

Input Parameters: Layer: The layer to be made visible (default="") Duration: The amount of time to show the layer before it is hidden (default=0.25) TimeScale: The global time scale value while the layer is being shown (can be used to slow/freeze time) (default=1)

Checklist

Extension file

FlashLayer-0.0.1.json.zip

Note

This extension is complete, but it has a critical flaw. The layer is displayed properly, but the "hide layer" action doesn't work. Can someone double-check the code and see why this happens?

tristanbob commented 3 years ago

Minor update, but the problem still exists. I think I know what is happening, though. It seems that no matter what string I use for Layer, it ignores it and always uses the default layer. To test this, I made all layers hidden. When I initiate the flash, the "" (base layer) becomes visible for the duration of the flash, and then is hidden. So the logic works great.

The problem is that "Hide Layer" and "Show Layer" are not reading my string properly.

Any ideas? Is this a bug in GDevelop?

Video demonstrating problem: 95EDMoSvwZ.zip

FlashLayer-0.0.2.json.zip

arthuro555 commented 3 years ago

I think the issue are those quotes: image Variable names don't have quotes, so you're reading from a separate "__FlashLayer_Layer" variable instead of the __FlashLayer_Layer variable

tristanbob commented 3 years ago

Thanks to @arthuro555, I was able to make this extension work correctly. Changes include:

FlashLayer-0.1.0.json.zip

4ian commented 3 years ago

Thanks! Do you think we should use a scene variable? To avoid conflicts in case you change to another scene while having a "flash" in progress?

tristanbob commented 3 years ago

My understanding is that you must use globals to for a lifecycle function to see them.

You raise a good question; if the scene changes and the lifecycle function tries to hide a non-existing layer, what happens?

On Tue, Dec 22, 2020 at 8:43 AM Florian Rival notifications@github.com wrote:

Thanks! Do you think we should use a scene variable? To avoid conflicts in case you change to another scene while having a "flash" in progress?

tristanbob commented 3 years ago

I just tested this, and if the layer does not exist, then it appears to fail silently. Therefore, I don't think we need to worry if a scene changes and the flashed layer does not exist.

Did my comment about the need to use a global variable make sense?

4ian commented 3 years ago

While it's true that for a lifecycle function like "onFirstSceneLoaded" (and even here, you still have a scene that is running), for other lifecycle you have a scene that is being run (hence the names: onSceneBlabla), so you can totally use scene variables without problem :)

This can allow to start a layer flash on a scene, then pause it, running another scene on top of it, make a layer flash, then go back to the previous one and continue without issues (with global variable, the flash of the second scene would erase the global variable used by the first scene that was paused).

So I think scene variables should both work and be safer?

tristanbob commented 3 years ago

Dangit, I spent all this time thinking I had to use global variables.

I think it was because the help text on lifecycle functions says "only global objects can be used", and I assumed this also meant only global variables.

I will work on converting this to scene variables (and all future extensions).

tristanbob commented 3 years ago

Changes:

FlashLayer-0.2.0.json.zip

tristanbob commented 3 years ago

I was thinking, should I update this to offer the ability to keep flashing? This would make it more similar and consist with the existing flash/blink object extension.

4ian commented 3 years ago

That's a good question, how would you offer this possibility to the user? I guess it would make sense to have it, right now it's more a "flash in the sense fade" layer extension :)

tristanbob commented 3 years ago

I don't think I will make this extension flash multiple times (at least for now). Would you accept it as is?

BTW, I'm not sure what you meant by "flash in the sense fade". This extension briefly shows a hidden layer and then hides it again. There is no fading involved.

4ian commented 3 years ago

Sounds good then!

4ian commented 3 years ago

It's up :)