DICE PACKS BUNDLE
Page 1 of 2 12 Last
  1. #1

    Dice Roll problem

    I'm trying to get a dice roll to add a value from a NumberField on the character sheet to a d10 dice roll triggered by a button on the character sheet. The value I want as a modifier to the roll is called strikeranktot and comes from a NumberField down further in the same windowclass as the roll script. This is the script. Right now it returns an error saying i'm going for a global value. Anyone see the problem?


    function rollDice()
    local desc = name.getValue().." ("..strikeranktot.getValue()..")"; local dice,modifier = name.getValue()..(..strikeranktotal.getValue()..);
    ChatManager.throwDice("dice",{"d10"},modifier,desc );
    end


    P.S. how do I post code in a little box like the other wizards here?

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    What is the exact error message you're getting?

    Where is this script being executed?

    You might try using window.strikeranktot.getValue()

    window is mentioned in the Script Block Scope section here: https://www.fantasygrounds.com/modguide/scripting.xcp

    Use the "Go Advanced" button when posting in the forums to show more options (including the code # button).
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    ok thanks Trenloe. I attached the rollDice function to the windowclass block, and the roller happens down below as a buttoncontrol.

    windowclass part

    function rollDice()
    local desc = name.getValue().." ("..strikeranktot.getValue()..")"; local dice,modifier = name.getValue()..(..strikeranktotal.getValue()..);
    ChatManager.throwDice("dice",{"d10"},modifier,desc );
    end


    buttoncontrol part:

    function onButtonPress()
    window.rollDice({"d10"});
    return true;
    end



    gets this:
    Script Error: [string "charsheet_main"]:1: attempt to index global 'strikeranktotal' (a nil value)
    Script Error: [string "charsheet_main"]:1: attempt to index global 'strikeranktotal' (a nil value)

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    Please post the XML for the strikeranktotal control.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    <NumberField name="strikeranktot"><anchored><left><parent>middl eframe</parent><anchor>left</anchor><offset>204,20</offset></left><top><parent>middleframe</parent><anchor>top</anchor><offset>42</offset></top><size><width>20</width><height>20</height></size></anchored><font>chatfont</font><frame><name>modifier</name><offset>5,4,5,4</offset></frame><!----><script>function recalc()
    local srbase = window.getDatabaseNode().
    getChild("strikerank").getValue();
    local sradj = window.getDatabaseNode().
    getChild("strikerankadj").getValue();
    setValue(math.floor((srbase-sradj)));
    end
    function onInit()
    local srbasenode = window.getDatabaseNode().
    getChild("strikerank");
    local sradjnode = window.getDatabaseNode().
    getChild("strikerankadj");
    if dexnode and intnode then
    srbasenode.onUpdate = recalc;
    sradjnode.onUpdate = recalc;
    end
    recalc();
    end</script></NumberField>
    Last edited by Archlyte; April 7th, 2015 at 17:21.

  6. #6
    I am not able to identify how to put the code in a window. don't have a # choice

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    Have you tried using window.strikeranktot.getValue()?
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  8. #8

  9. #9
    I read that section, but I don't know if it works like this or not:

    Have the buttoncontrol scrip call to window.strikeranktot. then define that up in the windowclass so instead of rollDice it is looking to window.strikeranktot.getValue

  10. #10
    Do you get paid for this Trenloe? I hope you do

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
  •  
STAR TREK 2d20

Log in

Log in