PDA

View Full Version : Check boxes flicker.



statik37
August 2nd, 2020, 19:53
Hello everyone I have a bit of a quandry. I looked in other Rulesets, and I could not find a solution to this.

I have a list of stats on the PC sheet that each have a check box next to them. What I am trying to do is set it up so that only one box can be checked at a time. The code looks like this.



<basicnumber name="stat1" source="stat1.value">
<anchored to="stats" position="below" offset="0,3"/>
<frame mergerule="replace" name="fielddark" offset="4,4,4,4" />
<font>sheetnumber_lg</font>
<nodrag />
<nodrop />
<default>1</default>
<min>1</min>
<max>5</max>
</basicnumber>

<buttonfield name="stat1selector" source="stat1.button">
<anchored to="stats" position="right" offset="3,0" width="10" height="10" />
<state icon="button_checkoff10_wht" />
<state icon="button_checkon10_grn" />
<script>
function onInit()
Node = window.getDatabaseNode();
if DB.getValue(Node, 'statname') == "stat1" then
onValueChanged();
end
end

function onValueChanged()
window.stat2selector.setValue(0);
window.stat3selector.setValue(0);
window.stat4selector.setValue(0);
window.stat5selector.setValue(0);
window.stat6selector.setValue(0);
window.stat1selector.setValue(1);
statLibrary.statSelect(window, "stat1.value", "stat1")
end
</script>
</buttonfield>


Initially instead of using buttonfield I was just using buttoncontrol. The problem with that is the stat was not updating on the GM view, and the GM wants to be able to see what is selected by the players. So, I changed it to buttonfield, and now, the GM can see the changes live, the problem is, when the player selects a second stat, the buttons start flickering. I'm pretty sure it's because both the GM and Player are triggering the onValueChanged function. When the player is in their sheet and the GM does not also have it open, it works fine. The second the GM opens the sheet to see what they are selecting, it's starts to freak out.

How can I fix this? I was thinking OOBMessaging might be the answer, but as seeing the value is being saved in the players DB node, I didn't think that would be the answer. I also thought of putting in either an if !isHost or isLocal command, but I also want the GM to be able to change those selections as well, and I assume this would prevent that from happening.

Any advice would be greatly appreciated.

damned
August 2nd, 2020, 22:58
What about calculating onGainFocus or onLoseFocus - one of those might work.

LordEntrails
August 2nd, 2020, 23:05
I'm assuming their are no radiobuttons available in FG?

statik37
August 3rd, 2020, 01:12
What about calculating onGainFocus or onLoseFocus - one of those might work.

Unfortunately buttoncontrol does not have either of those. But now that I do look again, maybe I should be doing onBottonPress instead of onValueChange.


I'm assuming their are no radiobuttons available in FG?

I think I tried radiobuttons in the passed and I didn't like it for some reason, but I can look into it again.

damned
August 3rd, 2020, 01:15
Use onClickRelease then - its generally a better UI experience.