PDA

View Full Version : Protecting entries



DNH
November 30th, 2007, 15:03
I had thought I had read something about this somewhere on here before now, but I can't find it so here goes ...

My custom ruleset character sheet has a few entries which function as the indication of the modifier AND are grabbed to make dice rolls. To give one example, I have a weapons list which has an entry for weapon speed which is added to 1d10 to get the initiative (this is 2e, ok). So the player will grab at the "+5" or whatever, it becomes a d10 as he or she drags it and dropping it rolls 1d10+5. This is not the problem; this part all works fine.

What I would like to do is to be able to protect the field from inadvertent modification. I can quite easily see players inadvertently nudging the mousewheel up a notch or two and ending up with a higher initiative score than they should.

I do not want to make these fields "read only" as they will have to be altered at some point. I have already included the <noreset /> tag to prevent resetting to zero, but I would like to be able to prevent all editing but keying in of values. Is this possible? (It looks as though the opposite is possible, through use of <nokeyedit />.)

The only solution I can think of is to use the onValueChanged() function to throw up an alert message of sorts but a) I am not sure about how to do that (display an alert message box, I mean), and b) this is not particularly elegant.

Any thoughts?

DNH
November 30th, 2007, 15:51
A related problem to this (I think) is that another similar field has a fairly static modifier value in it. The code I have (from the d20 ruleset) provides a modifier widget but I need to be able to separate out the values. That is, I have it so that both the field value and the widget value are applied to the total when the roll is made (it's an attack roll btw) but I want to be able to adjust the widget independently of the field value. And I don't seem to be able to. The nearest I can get to it is to scrollwheel the whole thing up to the correct widget modifier value, then key in the field value back to what it was. All a bit Heath Robinson and not very satisfactory.

I suppose I could change the layout things around a bit and resolve the problem that way, but if there is any other way of doing this, I would appreciate the help.

Thanks.

Dachannien
November 30th, 2007, 17:28
If you register an onWheel() event function for the control and have it simply return true, this might prevent the wheel from updating the control.

joshuha
November 30th, 2007, 20:29
I thought there was a <noscroll /> tag that prevented the mouse from scrolling numberfields but I am not seeing it in the documentation. I would try it out anyways but I might just be going crazy.

DNH
December 5th, 2007, 10:13
A <noscroll /> tag makes sense and I was in fact surprised not to see it listed or used anywhere (it wouldn't be the first case of an undocumented feature). Anyway, I tried it and it doesn't work.

I have however resolved the problem with Dachannien's idea of a null onWheel() function. Thanks, Dachannnien.

eldrin81
December 14th, 2007, 22:33
I'm new to fantasy grounds and don't know much about any scripting yet, but this kind of functionality would be very useful. I've already inadvertently messed up several fields when inputting character stats from a physical character sheet and would appreciate some more detailed help in implementing this. Thanks:)

DNH
December 16th, 2007, 22:55
You can completely disable editing of fields with the <readonly /> tag. That might well be overkill for most parts of your character sheet, depending on what your ruleset does.

Keyboard editing only (ie leaving the scrollwheel and reset functions intact) can be hobbled with the <nokeyedit /> tag.

While I see how it can be useful to be able to zero numberfields at the click of a button, I would argue that this would be a problem for most of them. You can prevent this from happening with the <noreset /> tag.

What I consider the most important editing hobble involves the mouse scrollwheel ... and it is not directly implemented. Dachannien's solution is to add the following script block:



<script>
function onWheel()
return true;
end
</script>

This actually leaves the scrollwheel function intact BUT it doesn't actually DO anything.

I tend to include both this code snippet and <noreset />. This leaves my numberfields as protected, yet editable by keying in the required/desired value. Given that the numeric keypad is used for other things, you are most unlikely to type in any unwanted values.

Hope this helps.

eldrin81
December 17th, 2007, 23:11
Do I have to register this in every single control in every file for the character sheet or is there someway to make it global for all controls?

DNH
December 19th, 2007, 11:18
If you're sure you want to use it for every single control, then go ahead and implement it in the template for that control (eg linkednumber). Otherwise, yes, you would have to include these for each control you want to, er, control in this manner. OR you can always create a new template, implement these restrictions and use that. To be honest, I have been implementing these on a case-by-case basis so far and I haven't found things too onerous.