PF2E Playlist
Page 1 of 2 12 Last
  1. #1

    Gambit of Ord extension

    Hey all, I've been hacking away at my first extension and could use all the help/advice I can get.

    Basically, I'd like to automate Matt Mercer's Gambit of Ord rules and use them to simulate a night of gambling. Our current 5E D&D party has a goblin rogue (me) who likes to invite people to play cards whenever we're in a tavern. So far, we've tried playing with roughly the same rules at GoO, with all the other PCs taking the part of suckers -- erm, NPC players -- in the game. Since I wanted to make sure supporting my rogue's gambling addiction was still fun for other players, and most of them are unlikely to play the goblin for money.

    Doing this manually, however, was just a bit too much of a hassle to imagine doing it regularly. So, being someone who knows how to code well enough to be dangerous, I decided to tackle my first FG extension. I found a simple extension, broke it, and started hacking things back together until it started to look like something I wanted.

    It wasn't long before I ran into some questions that could surely be answered quicker through the forum than through my wading through endless .lua files until I find something similar to what I want to do.

    After a few hours of hacking I had a window with a few buttons and a few number fields. Right now, the buttons perform a secret d8 roll and that's it. What I would like is to have each button roll a different die (d8, d6, and d4), and populate the number field for that roll when it does so. There's also another field for the total of all dice rolled so far. All the buttons call the same action manager script, though, and I haven't yet figured out how to pass a parameter from the xml that calls the script.

    I also haven't yet figured out how to populate the number field with the result of that roll. So those would be the first two problems to solve.

    These are, I'm sure, only the first and easiest obstacles to overcome - for instance, I have no idea yet how I can manage each player having his own version of the window, rather than everyone seeing the same window which is what happens now, nor have I started to think about how to handle betting, raising, etc. But, baby steps.

    Any comments/help/advice would be appreciated. Yes, I know that my windowclass is ugly as hell and surely the least efficient way imaginable to lay out the window elements, so any comments on how to do that better would be nice as well.

    Also, I'm using the GoO rules, but I've used "Talis" as the game name in the extension as that's the card game played in our FR campaign.

    Thanks,
    bripod
    Attached Files Attached Files

  2. #2
    sturtus's Avatar
    Join Date
    Feb 2010
    Location
    New Jersey, NYC
    Posts
    198
    I'm helping.

  3. #3
    So I solved one of the issues I mentioned, getting the three different button_roll elements in talisWindow.xml, which each call utility_talis_roll.lua, to roll different dice based on the button_roll/@name. I found self.getName() would return the @name of the button_roll calling utility_talis_roll.lua, so I could set a variable to pass along for use by rRoll.aDie. What I couldn't figure out was why that worked in utility_talis_roll.lua but not in manager_talis_roll.lua, which contained the actual rolling functions.

    (As an aside, I set up two lua scripts for this instead of putting it all in utility_talis_roll.lua because that was the way the extension I started with did things, but what is the reasoning behind this separation?)

    I also realized that the windowinstance I was creating was not bound to a database node, so I bound it to a node named TalisWindow, which I assume will make it easier/possible to manipulate the values of the child nodes that will contain the results of the die rolls. Now I have a node in the db, but I haven't yet figured out how to access/change those values - every function I try that seems like it might work results in "attempt to call field XX (a nil value)".

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    28,541
    I'm not sure if you're making statements or asking for help - as there's no detailed information that might allow us to help.

    For the database, look at these topics:

    http://www.fantasygrounds.com/wiki/i...ets_-_Database - Some high level info on the FG database.
    http://www.fantasygrounds.com/wiki/i...ts_-_Scripting - Scripting info.
    http://www.fantasygrounds.com/refdoc/DB.xcp - The DB API - used to access nodes within the database using LUA.
    http://www.fantasygrounds.com/refdoc/databasenode.xcp - The databasenode API - used to do LUA scripting against database nodes.

    You can also get the databasenode object from controls/windows that are anchored on a field in the database:

    http://www.fantasygrounds.com/refdoc...asecontrol.xcp - a database control (stringfield, numberfield, windowlist, formattedtextfield, windowreferencefield).
    http://www.fantasygrounds.com/refdoc...etDatabaseNode (the node related to the window instance).
    Last edited by Trenloe; May 24th, 2018 at 16:01.

    FG Con 16 FG Online RPG Convention - Friday April 16th Sunday 18th, 2021.
    FG Con 17: October 15th 17th, 2021.

    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
    sturtus's Avatar
    Join Date
    Feb 2010
    Location
    New Jersey, NYC
    Posts
    198
    He is just sharing his experience and seeing if anybody that is into Critical Role and has insight on extensions wants to follow along or contribute. That feedback is super helpful. After Mem Day I intend to collaborate on it through UI dev, splitting backend from front end. As we devs do.

  6. #6
    Ha, yes, I guess I was pretty vague about what kind of feedback I was looking for. The links you posted are perfect, thanks. Mostly as sturtus said, I'm just sharing what I'm doing and seeing if anyone has helpful advice/best practices etc. to share. I often find that trying to articulate the problems I'm having helps me find the solution.

    As I get more familiar with lua and the api, I expect I'll have some specific questions. For example, like this one (actual question follows verbose explanation):

    I've got this button_roll, which is an instance of the button_roll template from CoreRPG, in talisWindow.xml (I've simplified the xml here to remove multiple sets of label/button/number, as they currently all work the same):
    Code:
    <root>
    	<windowclass name="talisWindow">
    		<frame>partysheet</frame>
    		<placement>
    			<size width="500" height="600"/>
    		</placement>
    		<noresize/>
    		<minimize>minimized_npc</minimize>
    		<nodelete/>
    		<sheetdata>
    			<windowtitlebar name="title">
    				<resource>talis_window_title</resource>
    			</windowtitlebar>
    			<anchor_title_charsheet name="contentanchor"/>
    			<label_charframetop name="card1_section">
    				<anchored height="25">
    					<top parent="contentanchor" anchor="top" relation="relative" offset="75"/>
    					<left offset="50"/>
    					<right offset="-50"/>
    				</anchored>
    				<bounds>55,110,-335,20</bounds>
    				<static>First Card - d8</static>
    			</label_charframetop>
    			<button_roll name="button_roll_d8">
    				<anchored to="card1_section" position="insidetopleft" offset="25,35" width="25" height="25"/>
    				<script  name="TalisRoll" file="utility/scripts/utility_talis_roll.lua"/>
    			</button_roll>
    			<numberfield name="talisCard1">
    				<anchored to="button_roll_d8" position="insidetopleft" offset="35,0" width="25" height="25"/>
    				<frame name="fieldlight" offset="7,5,7,5"/>
    				<hideonvalue>0</hideonvalue>
    			</numberfield>
    			<close_charsheethelper/>
    		</sheetdata>
    	</windowclass>
    </root>
    I'm sure this is a terrible way to set up the windowclass, but I'm just hacking bits together and trying to figure out what works at this point. And this creates the window that I want, bound to the db node "Talis_Window":
    Code:
    Interface.openWindow("talisWindow","Talis_Window");
    The idea is that the window contains a button which kicks off the script to roll a die, and a numberfield which should contain the result of that roll.

    In the script called by button_roll_d8, utility_talis_roll.lua, I can see the database node: window.getDatabaseNode().getChildren() returns all the nodes I expect: { s'talisCard1' = databasenode = {Talis_Window.talisCard1} }. However, when I try the same thing in manager_action_talis.lua, which contains the functions that actually perform the roll (and is included from extension.xml), I get the window/nil value error.

    I swear there was a forum post I saw earlier that seems to address this issue (why can't I access the window object from within a script) but I can't find it anymore. Pretty sure it's because the manager_action_talis.lua script has no idea what window it's being called from. But eventually I want to be able to write the result of the roll to that database node, and I expect that I'll be doing this in manager_action_talis.lua.

    SOOOO, long story short, I guess my question is, where is that post that explained this issue? And, as a follow-on question, what is wrong with my windowclass setup, in general? I mean, it's working, but I'm sure there's a better way that it should be set up than this, as I just took an existing example from another extension and hacked at it until it looked the way I want.

    Thanks for reading all the way to the end.

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    28,541
    Quote Originally Posted by [email protected] View Post
    However, when I try the same thing in manager_action_talis.lua, which contains the functions that actually perform the roll (and is included from extension.xml), I get the window/nil value error.

    I swear there was a forum post I saw earlier that seems to address this issue (why can't I access the window object from within a script) but I can't find it anymore. Pretty sure it's because the manager_action_talis.lua script has no idea what window it's being called from. But eventually I want to be able to write the result of the roll to that database node, and I expect that I'll be doing this in manager_action_talis.lua.
    I'm guessing manager_action_talis.lua is a Global <script> and is not attached to a GUI control somewhere?

    If so, then window won't return anything (as you're seeings) as a global script does not know which window you're referring to.

    It's best to store the databasenode in the rRoll data record - then you can access it after the roll completes in manager_action_talis.lua by accessing the databasenode from the rRoll record.

    A good example of this is the table roll in CoreRPG. In campaign\scripts\table_main.lua the databasenode of the table is stored in rTableRoll.nodeTable which is the roll record used in the performRoll action. rTableRoll.nodeTable = getDatabaseNode(); is used - this is actually <windowsintance>.getDatabaseNode() - <windowsintance> is implied as table_main.lua is tied directly to a GUI window. http://www.fantasygrounds.com/refdoc...etDatabaseNode

    In the tableroll handler, scripts\manager_table.lua, the databasenode passed into the roll record, rTableRoll.nodeTable, is used a few times to give access to the original table database record.

    FG Con 16 FG Online RPG Convention - Friday April 16th Sunday 18th, 2021.
    FG Con 17: October 15th 17th, 2021.

    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
    Quote Originally Posted by Trenloe View Post
    I'm guessing manager_action_talis.lua is a Global <script> and is not attached to a GUI control somewhere?
    Yep, exactly right, manager_talis_roll.lua is a Global.

    A good example of this is the table roll in CoreRPG. In campaign\scripts\table_main.lua the databasenode of the table is stored in rTableRoll.nodeTable which is the roll record used in the performRoll action. rTableRoll.nodeTable = getDatabaseNode(); is used - this is actually <windowsintance>.getDatabaseNode() - <windowsintance> is implied as table_main.lua is tied directly to a GUI window. http://www.fantasygrounds.com/refdoc...etDatabaseNode
    THANK YOU, this is exactly the sort of thing I was looking for. For some reason my brain doesn't process documentation very well until I've actually seen something in action a few times. I will dig into this example.

  9. #9
    That example was super helpful, by the way. I've now got the right databasenode being passed along in the rRoll record, and everything is working as intended so far.

    Well, everything I've coded, that is. I've still got a lot of work to do, but this solved the current problem. More questions will surely follow as I get further along.

    Thanks again!

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    28,541
    Quote Originally Posted by [email protected] View Post
    That example was super helpful, by the way. I've now got the right databasenode being passed along in the rRoll record, and everything is working as intended so far.
    Cool!

    FG Con 16 FG Online RPG Convention - Friday April 16th Sunday 18th, 2021.
    FG Con 17: October 15th 17th, 2021.

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in