Expected type for color_block's SetOpacity

Hey everyone. I’m setting up a simple fade-to-black UI transition using a color_block that I’m fading from 10% up to 100%.

I’m having an issue passing the correct type to the SetOpacity method. If I send a static float, everything works well. Example:

However, as soon as I try to pass a float variable I get the following error message:

Full code below:

        var OpacityValue : float = 0.1

            set OpacityValue = OpacityValue + 0.1

            if (OpacityValue >= 1.0):

Appreciate the help!

Hi @zoakibo , you’re getting that error because the function is not expecting a regular float. It’s expecting a float between certain values. This is defined as a different type in Verse. If you right-click the SetOpacity() function and click Go To Definition in VS Code, you can see the type itself.

To fix your issue, instead of declaring OpacityValue as a float, declare it like this:

var OpacityValue : type{_X: float where 0.0 <= _X, _X <= 1.0} = 0.1

Brilliant, big thanks @capen_r. Lots to learn with Verse - but that is a brilliant way of setting up data limitations.

As a follow-up if you have the time, @capen_r: what would be the correct way to increment OpacityValue in a loop with 0.1 for each step of the loop? Struggling to get the syntax to work as any operation I do naturally says I am not using the correct type.

What I’m after is the correct version of set OpacityValue = OpacityValue + 0.1 given that OpacityValue now is set up correctly as per your recommendation: OpacityValue : type{_X: float where 0.0 <= _X, _X <= 1.0} = 0.1

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.