FG Spreadshirt Swag

Thread: onValueChange()

  1. #1
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,621

    onValueChange()

    onValueChange()

    ... this stumps me, is there a way to make it look at another value to update THIS field whenever that one updates?

    aka...

    <numberfield name="field1>
    ....
    </numberfield>

    <numberfield name="field2>
    ....
    <script>
    onValueChange(field1)
    .....
    .....
    end
    </script>
    </numberfield>
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  2. #2
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,621
    The biggest problem here I think is caused by me using a windowlist...
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  3. #3
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,621
    Code:
    <numberfield name="mstat">
        <bounds rect="300,9,35,20" />
        <description text="Dexterity" />
        <script>
       
        function onInit()
         source = window.windowlist.window.getDatabaseNode().getChild("dexterity")
         window.getDatabaseNode().getChild("mstat").setValue(source) 
         source.onUpdate = onValueChanged
         onValueChanged()
        end
    
        function onValueChanged()
        
           local a,b,c,d,e;
           
           a = window.windowlist.window.getDatabaseNode().getChild("dexterity").getvalue();
           window.getDatabaseNode().getChild("mstat").setValue(a) 
           
           a = window.getDatabaseNode().getChild("abonus").getValue() 
           b = window.getDatabaseNode().getChild("skill").getValue() 
           c = window.getDatabaseNode().getChild("mstat").getValue() 
           d = a+b+c;
           window.getDatabaseNode().getChild("Attack").setValue(d) 
           
         return true;  
        end
         </script>
       </numberfield>
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  4. #4
    Sorry can you explain a bit better what you are trying to do?

    OnValueChanged is a function that happens when the control (self-referential) changes a value. You seem to be trying to set an update handler to fire off that local event but that doesn't really make sense.

    If you are trying to look at another value that when the other value changes it does something then you almost have it. You just need to make your own function instead of using the built in onValueChanged. Call it sourceUpdate or something like that.

  5. #5
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,621
    I just wish to link two fields...
    One is inside a windowlist and should always be equal to the other one. (And if it changes it also needs to do the regular OnUpdate thing to update other values within the windowlist instance. )

    IE :

    The windowlist is the weapon-entry for the character-sheet. You can cram in as many weapons as you wish. But all melee weapons have a bonus equal with the Dexterity of the wielder.

    I just want to be able to pull the bonus so it is nicely visible on the charsheet.

    Pulling it when I doubleclick the attack is easy, I just call it with

    window.windowlist.window.getDatabaseNode().getChil d("dexterity").getValue();

    ... but I'd much rather have it all update in a nice clean manner.
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  6. #6
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    One way to do this is using the onInit event for your weapon windowclass:

    Code:
    in weapon windowclass:
    
    local dexnode = nil;
    
    function onInit()
      dexnode = windowlist.window.getDatabaseNode().getChild("dexterity");
      if dexnode then
        dexnode.onUpdate = recalc;
        recalc();
      end
    end
    
    function recalc()
      if dexnode then
        mstat.setValue(dexnode.getValue());
      end
    end
    Is that the sort of thing?

    Stuart
    Last edited by Foen; May 21st, 2008 at 16:45.

  7. #7
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    Linking it in to your code, mstat could be redefined as a numbercontrol instead of a numberfield, and the mstat script block becomes:

    Code:
    in mstat script block;
    
      function onValueChanged()
        local a,b,c;
        a = window.getDatabaseNode().getChild("abonus").getValue();
        b = window.getDatabaseNode().getChild("skill").getValue();
        c = getValue();
        window.getDatabaseNode().getChild("Attack").setValue(a+b+c);
        return true;  
      end
    Stuart

  8. #8
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,621
    THAT did the trick.
    Perfect solution.
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

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
  •  
DICE PACKS BUNDLE

Log in

Log in