FG Spreadshirt Swag
  1. #1

    Comm.throwDice Question

    Hi Guys,

    Can't seem to work this one out:

    If I have a command Comm.throwDice() in a script, how do I access the die results within that script?

    Cheers
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    The process is asynchronous in order to allow all of the dice to roll and land before looking at the result.

    The process is described in the header of manager_actions.lua:
    Code:
    --  ACTION FLOW
    --
    --	1. INITIATE ACTION (DRAG OR DOUBLE-CLICK)
    --	2. DETERMINE TARGETS (DROP OR TARGETING SUBSYSTEM)
    --	3. APPLY MODIFIERS
    --	4. PERFORM ROLLS (IF ANY)
    --	5. RESOLVE ACTION
    
    -- ROLL
    --		.sType
    --		.sDesc
    --		.aDice
    --		.nMod
    --		(Any other fields added as string -> string map, if possible)
    I've been through this very process with damned recently. Take a look at the 3.5e manager_action_ability.lua file - this is for making ability rolls (Strength, Dexterity, etc.). There are a few steps you need to do:
    1. Decide on an action type to use for your rolls - this needs to be a valid action type for the ruleset defined in the "actions" table at the top of the manager_gamesystem.lua file in 3.5e.
    2. Write 2 event handlers for the Modifier Handler and the Result Handler, then register these with the event handlers registerModHandler and registerResultHandler in the onInit() function of your action script file - see this at the top of manager_action_ability.lua for an example and the 2 event handlers in the same file: modRoll and onRoll.
    3. If you need to calculate any other modifiers beyond that incorporated into the modifier box, work these out and apply them in the modifier event handler modRoll. For the 3.5e ability roll the mod handler adds the ability bonus, affects from conditions, negative levels, etc..
    4. Then in the onRoll event you get access to the result of the roll and can do what you want with it.

    Two things to remember:
    1. You have to do this all attached to an rRoll.sType action type which has to be a valid action defined in manager_gamesystem.lua in your layered ruleset.
    2. The standard to pass info from the place where the Comm.throwDice method occurred is to enclose it in square brackets in the rRoll.sDesc description string and then parse this out in the modifier or result event handlers. The example 3.5e ability roll adds [ABILITY] then the ability name so that this can be extracted in the modifier handler and the related ability modifier calculated and added to the roll modifier. This method can also be used to pass target number info to calculate success/failure in the result handler and lots of other info - a complex 3.5e roll can have lots of data in separate square brackets for effects, conditions, etc..
    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
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,678
    Blog Entries
    1
    Quote Originally Posted by Trenloe View Post
    I've been through this very process with damned recently.
    I bet he picks it up way faster than me...

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Quote Originally Posted by damned View Post
    I bet he picks it up way faster than me...
    I really hope so.
    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
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,678
    Blog Entries
    1
    Quote Originally Posted by Trenloe View Post
    I really hope so.
    Me too...

  6. #6
    OK, so what do the arrays rSource and rTarget contain?

    Ie:
    Code:
    onRoll(rSource, rTarget, rRoll)
    Actually, more importantly, why isn't the following code working:

    Code:
    function onRoll(rSource, rTarget, rRoll)
    	print(rRoll.aDice[1].result);
    	window.nDie.setValue(rRoll.aDice[1].result);
    end
    I'm getting an "attempt to index global 'window' (a nil value)" error, but the print function is working fine, so I know the onRoll() is being called correctly.

    BTW onRoll() is defined in a "Manager" script and is being called by a Button's onButtonPress().

    Thanks
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Quote Originally Posted by dulux-oz View Post
    OK, so what do the arrays rSource and rTarget contain?

    Ie:
    Code:
    onRoll(rSource, rTarget, rRoll)
    Look in manager_actor.lua for info in the header on the data structure - and more info can be gleaned by looking in the rest of that script. This is essentially the source of the roll - and the data is essentially the same for sTarget which will usually only be present for a drag/drop event as there is a target (where the roll was dropped).

    Quote Originally Posted by dulux-oz View Post
    I'm getting an "attempt to index global 'window' (a nil value)" error, but the print function is working fine, so I know the onRoll() is being called correctly.
    The error tells you the reason - "window" is nil, it doesn't exist. As I mentioned above the dice roll event handlers are asynchronous - once the Comm.throwDice() function is used there is no longer any connection to the GUI window where the roll was initiated. The modifier handler and result handler are events that are triggered without a window to reference.

    Quote Originally Posted by dulux-oz View Post
    BTW onRoll() is defined in a "Manager" script and is being called by a Button's onButtonPress().
    onRoll is an event - it is the result handler of a roll - the very last step in the process listed in post #2: 5 - Resolve Action. You should not be calling it from pressing a button in the GUI. Use the button in the GUI to kick off the Comm.throwDice() operation - making sure to set the action type (rRoll.sType) to a valid action type. You should be using the performRoll function from a global script to initiate the roll. Refer to manager_action_ability.lua in the 3.5e ruleset. The roll is kicked off from code in a control that calls ActionAbility.performRoll - look at the <template name="number_charabilitybonus"> template in template_char.xml for the code that kicks off ActionAbility.performRoll:

    Code:
    function action(draginfo)
    	local rActor = ActorManager.getActor("pc", window.getDatabaseNode());
    	ActionAbility.performRoll(draginfo, rActor, self.target[1]);
    
    	return true;
    end
    
    function onDragStart(button, x, y, draginfo)
    	return action(draginfo);
    end
    	
    function onDoubleClick(x,y)
    	return action();
    end
    The action(draginfo) function sets up the actor data and then performs the roll with ActionAbility.performRoll. Draginfo will be available if the roll is started via a drag - the onDragStart function, or there will be no draginfo if the roll was initiated by a double click - onDoubleClick.
    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!

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