PDA

View Full Version : Dice Roll problem



Archlyte
April 7th, 2015, 16:46
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?

Trenloe
April 7th, 2015, 17:05
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).

Archlyte
April 7th, 2015, 17:15
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)

Trenloe
April 7th, 2015, 17:16
Please post the XML for the strikeranktotal control.

Archlyte
April 7th, 2015, 17:18
<NumberField name="strikeranktot"><anchored><left><parent>middleframe</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>

Archlyte
April 7th, 2015, 17:20
I am not able to identify how to put the code in a window. don't have a # choice

Trenloe
April 7th, 2015, 17:21
Have you tried using window.strikeranktot.getValue()?

Archlyte
April 7th, 2015, 17:24
No, let me try that

Archlyte
April 7th, 2015, 17:30
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

Archlyte
April 7th, 2015, 17:41
Do you get paid for this Trenloe? I hope you do :)

Trenloe
April 7th, 2015, 17:43
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
I'm not sure what you're trying to say here.

window.<control_name> is a way of getting access to the control named whatever you put in <control_name> within the current window environment. You can do it a number of different ways. Have the rollDice code in the <windowclass><script> section - which I think is where you have it at the moment, in which case you will need specific references to the controls which might need window.<control_name> to get to them.

If your strikeranktot control is in a different windowclass then you'll need additional window/control references to be able to reach it.

First step - try using window.strikeranktot.getValue() in your current rollDice function.

Trenloe
April 7th, 2015, 17:43
Do you get paid for this Trenloe? I hope you do :)
Nope.

Archlyte
April 7th, 2015, 18:54
Ok I can get it to work without errors with the following script:


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

it looks like this with me controlling a character named Brandorn:
9535

I want to add the Strink Rank Total to the dice roll. It finds the SRT fine for the desc, but every time I try to access it in order to add it to the die total it return s a nil value on global or it doesn't like the character such as when I put in the window.strikeranktot.getValue. I would also like a sting that says Initiative after the character's name. but when I tried to add it the thing kicked it back as no good. Thank you for all of your help, you are amazing.

Zeus
April 10th, 2015, 14:34
Ok I can get it to work without errors with the following script:


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

it looks like this with me controlling a character named Brandorn:
9535

I want to add the Strink Rank Total to the dice roll. It finds the SRT fine for the desc, but every time I try to access it in order to add it to the die total it return s a nil value on global or it doesn't like the character such as when I put in the window.strikeranktot.getValue. I would also like a sting that says Initiative after the character's name. but when I tried to add it the thing kicked it back as no good. Thank you for all of your help, you are amazing.

Which ruleset is this for? Is this based upon CoreRPG?

Make sure the numberfield tag for strikeranktot is <numberfield name = ... not <Numberfield name = ... as per your post above. Then add this version of rollDice to the script block attached to the window class that contains the strikeanktot numberfield:



function rollDice()
sStrikerAnkTot = strikeranktot.getValue();
sDesc = name.getValue() .. " (".. sStrikerAnkTot .. ")";
ChatManager.throwDice("dice",{"d10"},tonumber(sStrikerAnkTot),desc);
end

damned
April 12th, 2015, 08:44
Nope.

Repay him with warm fuzzies and use the Star to give him some reputation :)

Dakadin
April 12th, 2015, 17:50
Repay him with warm fuzzies and use the Star to give him some reputation :)

I'd be surprised if he doesn't fill up that reputation bar sometime soon to the point that he can't receive anymore. :p