PDA

View Full Version : stated button, how to create, how it works?



grelgen
March 6th, 2016, 00:24
Ok, so here is my code so far:

in my root


<icon name="rnk_checkeon" file="graphics/icons/checkon.png"/>
<icon name="rnk_checkeof" file="graphics/icons/checkoff.png"/>

<template name="rnk_use_this">
<buttoncontrol>
<anchored height="12" width="12"/>
<state icon="rnk_checkof"/>
<state icon="rnk_checkon"/>
</buttoncontrol>
</template>
<template name="actions_use_this">
<rnk_use_this/>
</template>

yes i know I'm layering my templates for no reason...

and in my sheetdata


<actions_use_this name="ability_mod_use">
<anchored to="ability_name_frame">
<right offset="0"/>
<top offset="5"/>
</anchored>
</actions_use_this>



My problem so far is that this puts nothing on my window. no icon whatsoever. Is there a tutorial on stated buttons somewhere?

And my guess is that when i click on a stated button, it should auto cycle to the next state? and then getValue returns a number?

damned
March 6th, 2016, 00:57
Hey grelgen Im not sure what a stated button is. Your best bet is to look at the 3.5E/4E/5E rulesets and find an example of what you are trying to achieve and mimic that code.

grelgen
March 6th, 2016, 09:33
I got the example from the coreRPG tool set and it was just a bug or something... I started ripping it apart and after decoupling it from the window I was attaching it to it showed up. then I set all the offsets to 0, re-coupled and it just showed up.



<genericcontrol name="scripts">
<bounds>0,0,1,1</bounds>
<script>
function windowChanged()
end
</script>
</genericcontrol>

<button_checkbox name="ability_used1">
<anchored width="12" height="12" to="ability_name_frame1">
<right offset="0" />
<top offset="10" />
</anchored>
<script>
function onButtonPress()
if (window.ability_used1.getValue() == 1) then
window.ability_used2.setValue(0);
window.ability_used3.setValue(0);
end
end
function onValueChanged()
window.scripts.windowChanged();
end
</script>
<default>1</default>
</button_checkbox>

<button_checkbox name="ability_used2">
<anchored width="12" height="12" to="ability_name_frame2">
<right offset="0" />
<top offset="10" />
</anchored>
<script>
function onButtonPress()
if (window.ability_used2.getValue() == 1) then
window.ability_used1.setValue(0);
window.ability_used3.setValue(0);
end
end
function onValueChanged()
window.scripts.windowChanged();
end
</script>
<default>1</default>
</button_checkbox>

<button_checkbox name="ability_used3">
<anchored width="12" height="12" to="ability_name_frame3">
<right offset="0" />
<top offset="10" />
</anchored>
<script>
function onButtonPress()
if (window.ability_used3.getValue() == 1) then
window.ability_used1.setValue(0);
window.ability_used2.setValue(0);
end
end
function onValueChanged()
window.scripts.windowChanged();
end
</script>
<default>1</default>
</button_checkbox>


So the above code creates 3 mutually exclusive "check boxes" like a radio group in HTML. Each check resides at the right most edge of the generic control it's anchored to. The generic control at the beginning is something I'm doing to create a global function for the page since putting a script outside of <sheetdata> causes errors.

GrimmSpector
March 9th, 2016, 17:22
You can put a script in a window instance; in which case you can call the function of the script by "window.<functionname>". I use the onInit function in windows to instantiate drop down lists sets of values usually. There's really little limit to it.

It's becoming my preferred way of having controls affect each other. Here's my advice.

Setup a click event for each control to call a function like window.radioClick() or some such; and in the windows script put the same function in. I'd suggest you may want to call the function with some identifier as to the set, and an identifier for the control itself, you can pass it's name as an argument; then all your function needs to do is call it's child controls and change their image/state.

For example, let's say I want them to pick a race, and it's setup with "race1", "race2" and "race3" being my controls, and they're all from the set "race" (many other ways you could group and name things):



function radioClick(name, set)
function radioClick(name, set)
for i=1,3
window[set .. tostring[i]].setValue(0);
end
window[name].setValue(1);
end


I suggest making each control a template, with a set script resource, and in that script have your onValueChanged() function which will fire off when the window changes the value, and in that function you can change your image as appropriate, and call any other functions you want to call.

I've played a lot with controls calling other controls functions and learned (mostly from Moon), that the easiest way to do it is like this. If you're getting errors for a script after your /sheetdata tag, your indentation may be wrong, or you may have it in the wrong place, sample:



<root>
<windowclass name="somesheet">
<sheetdata>
'some data'
</sheetdata>
<script>
function onInit()
things to do
end
</script>
</windowclass>
<root>


I use this setup extensively. Make sure you don't have tags in weird places, not closed, etc.