PDA

View Full Version : Just a quick stringcontrol question...



Kioma
April 9th, 2012, 07:24
Is there any way of restricting a <stringcontrol> field to a single character?

I was hoping there'd be a <maxchar> control or something but as far as I can tell there's not.

Zeus
April 9th, 2012, 09:05
Not that I am aware of.

However there are a couple of things you could manually implement:

1) Limit the width of the string control so that it will only display a single character
2) Create an onLoseFocus() routine to handle the event that is fired when the User finishes editing the control via the keyboard and inside manipulate the string value so that it only equates to the first char.

e.g.

function onLoseFocus()
setValue(strsub(getValue(), 1, 1);
end

Brenn
April 9th, 2012, 11:15
or you could use the onChar event handler:


function onChar(keycode)
setValue(string.char(keycode));
end

Kioma
April 11th, 2012, 05:39
Mmm. Both good options but to be honest it's not a huge issue. It's just... not neat, the way I have it set up. Actually I need to find a totally different way of dealing with what I'm doing - I'm setting up a ten-box health level thingy - but ten narrow text boxes as suggested by the good Doctor will work for now. It's not worth wrangling the code for something I'm eventually going to replace.

Brenn
April 11th, 2012, 10:37
I'm not sure exactly what you are trying to do, but would the <radiogroup> be a better place to start?

Kioma
April 11th, 2012, 10:48
It's a health level chart similar to the one in, as an example, World of Darkness games. Ten boxes, each of which can be marked with a / or an X. So radio buttons won't do it, I'm afraid.

Valarian
April 11th, 2012, 19:07
The WoD ruleset handles it as an icon cycler.

Kioma
April 20th, 2012, 14:54
The WoD ruleset handles it as an icon cycler.

See, I've been looking about but I'm not much of a coder and thus not entirely clear on how icon cyclers would be implemented. Don't suppose there's a handy-dandy tutorial out there for adding icon cycling to rulesets?

Brenn
April 21st, 2012, 00:42
The best way is to do it is to download and play with the nWoD ruleset, see how it functions in FG, then go look at the xml/lua and see how they did it.

If you aren't using Notepad++ I would strongly recommend it, among many things it offers some powerful search features that help you navigate through an unfamiliar ruleset.

Biting down and learning some scripting will open many more doors in regards to FG rulesets. There is just only so much you can do in the xml. The xml is the skeleton, lua is the muscle.

Zeus
April 21st, 2012, 10:12
See, I've been looking about but I'm not much of a coder and thus not entirely clear on how icon cyclers would be implemented. Don't suppose there's a handy-dandy tutorial out there for adding icon cycling to rulesets?

Here you go. Lets start with defining a button icon cycler control. Using 4E's template.



<button_iconcycler name="button_damage">
<anchored>
... add standard anchoring
</anchored>
<parameters>
<icons>indicator_/_damage|indicator_X_damage</icons>
<values>0|1</values>
<tooltips>/|X</tooltips>
<defaulticon>indicator_/_damage</defaulticon>
<defaulttooltip>/</defaulttooltip>
</parameters>
</button_iconcycler>


Where

<icons> contains the names of each icon graphic (as registered in the ruleset somewhere under graphics.xml) separated by a | character.
<values> contains the string value you want represented for each icon state, again separated by a | character. In the example above clicking the button to select the X indicator would yield a value of 1 if we interrogated the control using its getStringValue() method.
<tooltips> contains a string based description of the control that is displayed whenever the mouse is hovered over for each icon state, again separated by a | character.
<defaulticon> contains the name of the icon graphic (as registered in the ruleset somewhere under graphics.xml) for its default state.
<defaulttooltip>contains string based description of the control that is displayed whenever the mouse is hovered over the control in its default state


Now for script methods. Once defined and depending upon any additional logic you need to add, generally you only need to know a couple of the methods, how to read the state and how to set it.

Lets start with reading state:

button_damage.getStringValue() -- will return 0 or 1 (from the <values> we set) depending upon its state
button_damage.getIndex() -- will return 0 for the off state, 1 for the first state we defined, 2 for the second, 3 for the third and so on


For setting state:

button_damage.setStringValue(1) -- will set the damage icon to its first state (/)
button_damage.setStringValue(2) -- will set the damage icon to its second state (X)
button_damage.setIndex(0) -- will set the damage icon to the off state
button_damage.setIndex(1) -- will set the damage icon to its first state (/)
button_damage.setIndex(2) -- will set the damage icon to its second state (X)