Computed property default value

I’ve made canvas class that is trying to look like ledbar.
There’s one thing I can’t figure out. I have computed property ‘LedCount’ that defaults to 10. But still it’s 0 when I launch program. I had to add line:

if LedCount = 0 Then LedCount = 10

…to render-method to make it work. Can’t understand.
You can look the code in:

I copied/pasted your mLedCount and LedCount variables into a blank projects to see if they worked fine, and they did.

Looks like maybe you’re accessing the LedCount before the window has a chance to fully initiate the items and properly assign the default value.

When the items are being created it looks like they are first assigned a value of zero (you can see this happen if you put a breakpoint in the LedCount.set). This causes a render to happen which is where the problem occurs.

After the window loads, it will then properly assign the default values and the other values from the window’s open event. You might want to either (a) make sure that LedCount.set doesn’t call render if the assigned value is zero or (b) prevent any rendering until the items have fully loaded.

Your computed property setter is getting called when the window is initialized
Put a break point in CLed.LedCount.Set & you’ll see a stack that looks like
Nothing more

IF you right click on your class Cled and select “inspector Behaviour” check the check box next to that property
This will expose the property in the inspector so you can set it ion the layout itself.
Now you can set the default value when the window initializes each instance.

see case 29383 <>

I have made very subtle alterations to your set up so you do NOT need to have that line in Render (although you probably should check for 0 as the initial value otherwise the code fails in a different spot)

Wow! So I can make my own properties to inspector GUI. That’s too cool :slight_smile:
And there is also default sizes when you drag it to window, been looking for those, thanks a lot!
Now I only have to check that it’s not chaged to 0.