Thread: Dice Roll problem
-
April 7th, 2015, 16:46 #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?
-
April 7th, 2015, 17:05 #2
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!
-
April 7th, 2015, 17:15 #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)
-
April 7th, 2015, 17:16 #4
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!
-
April 7th, 2015, 17:18 #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.
-
April 7th, 2015, 17:20 #6
I am not able to identify how to put the code in a window. don't have a # choice
-
April 7th, 2015, 17:21 #7
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!
-
April 7th, 2015, 17:24 #8
-
April 7th, 2015, 17:30 #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
-
April 7th, 2015, 17:41 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks