How do I use functions?

0 favourites
  • 7 posts
From the Asset Store
Template for dungeon/maze generation, using wave function collapse
  • Hello,

    I have a event sheet with all my functions. One of these is a function, which set a random color of sprite.

    The function will be call two times... "On start of layout" and here:

    The problem is the second call. The color will be black, everytime. What am I doing wrong?

  • Try adding "Wait 0" between "Create object fx_echo" and "Function call"

    You need to wait 1 tick for object to be created.

    Another (better) solution would be to pass fx_echo.UID to the function as a parameter.

    Inside the function use "fx_echo Pick by Unique ID"

    This will allow to pick a newly created instance of the fx_echo object before it actually added to the layout.

  • Wossi

    I think it's because the color settings for SetColor range between 0-100, not 0-255. I've made the same mistake myself!

  • mekonbekon That too, probably. But if you set values >100 to all three parameters, the sprite should become white, not black.

    So the problem is that the function can't access an instance that has just been created.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dop2000 , well at least Wossi won't need to ask why the sprite now only turns white!

  • Another (better) solution would be to pass fx_echo.UID to the function as a parameter.

    Inside the function use "fx_echo Pick by Unique ID"

    This will allow to pick a newly created instance of the fx_echo object before it actually added to the layout.

    Ah, this is great! Thank you very much!

    mekonbekon: Yep, I know! But the values 100+ give me a better color effect.

  • On a related topic, the color system for this effect goes from 0% to 100%, which means 50 is 127, 100 is 255 and so it goes. If you prefer you can use 0-255 values by adjusting then inside the function (value / 255 * 100).

    Here's an example:

    https://www.dropbox.com/s/edx7g4dswda8b ... .capx?dl=1

    Hope this helps. Cheers!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)