Update after GUI Button Click

Hello Everyone,

In the PG below, the “Most Value” button will create a line that should always point to the sphere with the highest value. Value is assigned randomly at first, but clicking on a sphere will increase its value by 1. However, if you increase a sphere’s value to give it the new highest value, the line will not link to the new sphere.

As the code is written now, I know the line will only switch when the button is pressed. I’ve tried many variations of true/false statements and new variables with no success. If you remove the button from the equation, the line will update automatically.

To summarize: The line should only appear when the button is clicked, and then move to a new sphere if that sphere’s value becomes the new highest value.


Thanks in advance for any help or recommendations! :smiley: :+1:

This would work : https://www.babylonjs-playground.com/#4UUDKU#9

But you should probably do the max compute directly on click.

1 Like

Thanks @sebavan! This PG was made just to work on the issue you solved. In my actual project, I have hundreds of meshes moving around, and their values are constantly changing. When the button is clicked, the line will link to the mesh with the highest value at that particular time. However, if another mesh gets a higher value after that, the line will not automatically switch. The code you provided will fix that, so thanks again! :smiley: :+1: