DICE PACKS BUNDLE
  1. #1

    Problems getting events to work with an element of a windowlist

    I'm trying to add a feature to ruleset which allows the user to toggle the state of a skill by double-clicking the name of the skill. I think I know how to code what I want to do, but I can't get the skill labels to respond to any events, so I can't even really get to square 1.

    The skills are all items on a windowlist, so there is a windowclass that defines the entry for a skill on this list. In the windowclass are all of the values for the skill. Basically they are the label, which is the name of the skill, the rating value, and the pool value. The label is a stringfield, and I am trying to attach a script block to that which includes an onDoubleClick function. Here's my windowclass, below. I'll try to trim out parts that seem irrelevant for brevity's sake.
    Code:
        <windowclass name="char_skill">
            <script file="campaign/scripts/char_skill.lua" />
            <sheetdata>
                <genericcontrol name="rightanchor">
                    <anchored width="0" height="0">
                        <top />
                        <right />
                    </anchored>
                    <invisible />
                </genericcontrol>
                <button_idelete name="idelete">
                    <anchored width="15" height="12">
                        <top offset="4" />
                        <right parent="rightanchor" anchor="left" relation="relative" offset="-2" />
                    </anchored>
                </button_idelete>
                <genericcontrol name="idelete_spacer">
                    <anchored width="15" height="12">
                        <top offset="4" />
                        <right parent="rightanchor" anchor="left" relation="relative" offset="-2" />
                    </anchored>
                    <disabled />
                    <invisible />
                </genericcontrol>
    
    
                <numberfield name="pool">
                                                 trimmed   ...    
                           </numberfield>            
                
                <number_charskillfield name="rating">
                                                              ...
                </number_charskillfield>
    
    
                <stringfield name="label">
                    <anchored height="15">
                        <top offset="2" />
                        <left offset="1" />
                        <right parent="rightanchor" anchor="left" relation="relative" offset="-2" />
                    </anchored>
                    <font>sheetlabelsmallbold</font>
                    <tabtarget next="rating" />
                                    <script>
                                          function onDoubleClick(x,y)                                <!-- HERE is the event I'm trying to get working -->
                                               Debug.chat('BAM!');
                                          end
                                     </script>
                </stringfield>
    
    
            </sheetdata>
                
        </windowclass>
    What's happening is I can put the event in and get no errors, but double-clicking on the label stringfield does nothing. onClick is the same way. It works on item items in this windowclass, but not on the label stringfield.

    Does this make any sense? Am I leaving out important info? Does this sound recognizable as a common gotcha or anything? Any ideas what I need to be looking at would be appreciated!

  2. #2
    Usually, this happens when another control is layered on top of the control you're trying to capture the event for.

    It can be layered on top of the label in the char_skill windowclass (which doesn't seem to be the case from what you posted, but you may have left out other controls listed after label or that were moved forward in Z-order using windowcontrol.bringToFront.

    Or it could be layered on top of the windowlist containing the char_skill; or any layer above that.

    Regards,
    JPG

  3. #3
    Hrm, I did leave off one control listed afterward, and that is the sub-label item which a few skills use. (I'm basing this on the skills entries from the Call of Cthulhu ruleset, which also features the sub-labeling). I didn't think that was relevant since only a few skills use the sub-label, but maybe I am wrong about that.


    Would it be a bad idea to just use the bringToFront that you mentioned on my label control, to potentially fix the problem or at least test to see if this is an issue with Z-overlap?


    I'll see what I can figure out. Thank you for the pointer!!


    Scott

  4. #4
    Okay, I think I got to the bottom of this! In the CoC ruleset, there are two kinds of skills: The default ones, and user-created ("custom") skills. The attached lua file uses setEnabled(false) for the default skills, which makes it so that the user can't edit the text in the label field. As it happens, that also prevents me from getting events off the control!

    I changed this script to use setReadOnly(true) instead. It SEEMS to work, but I'm a little concerned that I'm jacking something up and that it was coded the way it was for a good reason. Have I made a sensible fix, or have I trifled with powers I ought not have?

    Anyway, just thought I would ask, and mention what the problem turned out to be for any future forum-searchers.

    Thanks!

  5. #5
    That's exactly what I would do. The control was set to disabled to prevent people from changing the names on the default skills on accident, since they are recreated if they are missing.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in