Starfinder Playlist
Page 2 of 2 First 12
  1. #11
    Getting farther down the rabbit hole... but man am I just so perplexed. If ANYONE here is a veteran Lua whiz, I could really use some big brain power. Moonwizard, you out there? *lights up the BatSignal*

    Here is a visual representation of what I am trying to do:
    codinglayout.jpg

    And here is the code so far (it is also attached in a zip file):

    Code:
    local aLiteralReplacements = {};
    local aLiteralReplacements2 = {};
    local aTableNameTable = {} 
    local aColumnTable = {}
    local StoredTableName = ""
    local incrementor = 0 --I might not use this
    
    
    function onButtonPress()  --This runs when you press "Generate Story" in the Story Template
    	local node = window.getDatabaseNode();
    	
        aLiteralReplacements2 = {}
    	
    	sText2 = performTableLookups2(DB.getValue(node, "text", ""));  -- parse the text in the Story Template, find tables, roll on them, and store the results in an array
        sText2 = performStoredReplacements2(sText2); -- retrieve Reference Link data from the array
    	
    	nodeTarget = DB.createChild("encounter"); -- make a new window
    	DB.setValue(nodeTarget, "text", "formattedtext", sText2); -- put all our new goodies into the new window
        
    	Interface.openWindow("encounter", nodeTarget); -- open the new window for the user to see
    
    end
    
    
    -- Look for table roll expressions
    function performTableLookups2(sOriginal)
    	-- store the original value in a variable. We will replace matches as we go and search for the next matching
    	-- expression.
    	local sOutput = sOriginal;
    	
    	
    	-- Resolve table expressions
    	local nMult = 1;
    	local aLookupResults = {};
    	for nStartTag, sTag, nEndTag in sOutput:gmatch("()[%{]([^%}]+)%}()") do
            local sMult = sTag:match("^(%d+)x$");
            StoredTableName = sTag; -- added this to save the table name up top and return into the function below
    		if sMult then
    			nMult = math.max(tonumber(sMult), 1);
    			table.insert(aLookupResults, { nStart = nStartTag, nEnd = nEndTag, vResult = "" });
    		else
    			local sTable = sTag;
    			local nCol = 0;
    			
    			local sColumn = sTable:match("|(%d+)$");
    			if sColumn then
    				sTable = sTable:sub(1, -(#sColumn + 2));
    				nCol = tonumber(sColumn) or 0;
    			end
    			local nodeTable = TableManager.findTable(sTable);
    
    			local aMultLookupResults = {};
    			local aMultLookupLinks = {};
    			for nCount = 1,nMult do
    				local sLocalReplace = "";
    				local aLocalLinks = {};
    				if nodeTable then
    					bContinue = true;
    					
    					local aDice, nMod = TableManager.getTableDice(nodeTable);
    					local nRollResults = StringManager.evalDice(aDice, nMod);
    					local aTableResults = TableManager.getResults(nodeTable, nRollResults, nCol);  
    					
    					local aOutputResults = {};
    					for _,v in ipairs(aTableResults) do
    						if (v.sClass or "") ~= "" then
    							if v.sClass == "table" then
    								local sTableName = DB.getValue(DB.getPath(v.sRecord, "name"), "");
                                    if sTableName ~= "" then
                                        globalTableName = sTableName
    									sTableName = "[" .. sTableName .. "]";
    									local sMultTag, nEndMultTag = v.sText:match("%[(%d+x)%]()");
    									if nEndMultTag then
    										v.sText = v.sText:sub(1, nEndMultTag - 1) .. sTableName .. " " .. v.sText:sub(nEndMultTag);
    									else
    										v.sText = sTableName .. " " .. v.sText;
    									end
    								end
    								table.insert(aOutputResults, v.sText);
    							else
    								table.insert(aLocalLinks, { sClass = v.sClass, sRecord = v.sRecord, sText = v.sText });
    							end
    						else
    							table.insert(aOutputResults, v.sText);
    						end
    					end
    					
                        sLocalReplace = table.concat(aOutputResults, " "); 
    
                        -- BELOW HERE is where I am hitting a mental roadblock... HOW do I get each column of the table results to go into their own array location,
                        --AND THEN how to I ensure I can accurately retrieve that data later?  I DON'T KNOW....
                        local sTableName = globalTableName;
                        incrementor = incrementor + 1;
                        table.insert(aTableNameTable, { incrementor = sTableName });
                        table.insert(aColumnTable, { StoredTableName = aOutputResults }); -- added storedtablename as the KEY, with the other as the value
                                            
                            
    				else
    					sLocalReplace = sTag;
    				end
    				
    				-- Recurse to address any new math/table lookups
    				sLocalReplace = performTableLookups2(sLocalReplace);
    				
    				table.insert(aMultLookupResults, sLocalReplace);
    				for _,vLink in ipairs(aLocalLinks) do
    					table.insert(aMultLookupLinks, vLink);
    				end
    			end
    
    			local sReplace = table.concat(aMultLookupResults, " ");
    			if aLiteralReplacements2[sTable] then
    				table.insert(aLiteralReplacements2[sTable], sReplace);
    			else
    				aLiteralReplacements2[sTable] = { sReplace };
    			end
    
    			for _,vLink in ipairs(aMultLookupLinks) do
    				sReplace = sReplace .. "||" .. vLink.sClass .. "|" .. vLink.sRecord .. "|" .. vLink.sText .. "||";
    			end
    			
    			table.insert(aLookupResults, { nStart = nStartTag, nEnd = nEndTag, vResult = sReplace });
    			nMult = 1;
    		end
    		
    	end
    	for i = #aLookupResults,1,-1 do
    		sOutput = sOutput:sub(1, aLookupResults[i].nStart - 1) .. aLookupResults[i].vResult .. sOutput:sub(aLookupResults[i].nEnd);
    	end
    	
    	return sOutput;
    end
    
    
    function performStoredReplacements2(sOriginal)  --AND this function is missing something VERY important,
        -- which I can't figure out how to accomplish.  How do I get the Reference Link to pull specific column
        -- data via the use of the pipe "|" symbol followed by the column number?  EX: on a reference link of
        -- #Table A|4# I want only the data from column 4 of the previously rolled {Table A}.  How do I do this!?
        local sOutput = sOriginal;
        local TableName = StoredTableName;
        local nCol = 0
    
        local isFGU = UtilityManager.isClientFGU();
        
        for incrementor,v in pairs(aTableNameTable) do
            local sLiteral = "%#" .. TableName:gsub("([%-%+%.%?%*%(%)%[%]%^%$%%])", "%%%1") .."%#";
            local sColumn = sLiteral:match("|(%d+)$");
            if sColumn then
                TableName = TableName:sub(1, -(#sColumn + 2));
                local sLiteral = "%#" .. TableName:gsub("([%-%+%.%?%*%(%)%[%]%^%$%%])", "%%%1") .."%#";
                nCol = tonumber(sColumn) or 0;
            else
                nCol = 0;
            end
            
            for nCol,o in pairs(aColumnTable) do
    
                sOutput = sOutput:gsub(sLiteral, table.concat(o, " "));	
            end
    
        end
    	return sOutput;
    end
    Attached Files Attached Files
    Last edited by JimSocks; October 12th, 2020 at 06:18.

  2. #12
    Now here's the long version of my plan, in case anyone does have the ability to help and would like more data:

    Within the software, we have a feature called Tables (where you can roll virtual dice and receive an outcome. These tables can have multiple columns forming their output.), and another feature called Story Templates (where you can write a story, and embed “callouts” to Tables.) When a “Generate Story” button is pressed within the Story Template, all the Table “callouts” you typed are replaced by the retrieved results from the Tables you were asking for. In practice, it would look like this in the Story Template before the button was pressed:

    • The merchant had [Eye Color] eyes, and [NPC Interesting Feature].


    Once the Generate Story button is pressed, a new record is created that replaces the Table callouts, it might look like this:

    • The merchant had blue eyes, and a pink scar on both palms.


    Furthermore, there is another layer to what is baked in out of the box, and these are called Reference Links. They let you recall something you have already retrieved from a given table, and would look like this at first:

    • The merchant had [Eye Color] eyes, and [NPC Interesting Feature]. His <Eye Color> eyes quickly searched the scene ahead.


    Once the Generate Story button is pressed, a new record is created that replaces the Table callouts, and ALSO retrieves data it already stored from the [Eye Color] Table Callout, in order to populate the <Eye Color> Reference Link with the same data. It might look like this:

    • The merchant had green eyes, and a nervous twitch. His green eyes quickly searched the scene ahead.


    I aim to provide a bit more functionality, in the form of a second type of Table Callout, and a second type of Reference Link. My callouts will look like {Table Callout} instead of [Table Callout], and my Reference Links will look like #Reference Link|Column Number# (where "Column Number" is a numerical digit) instead of <Reference Link>. This is intended to be additive, and not replace original functionality but augment it. (Though for prototype purposes, I have removed all original functionality from the code below. I'll add it back in when I get this working)

    When I make a Table callout using the new method, I want the output of the table's different columns to be placed into discrete positions within an array, so I can later retrieve them separately with the new Reference Link. (The original system doesn’t let you do this: any time you use a Reference Link, it verbal-diarrheas every single column result from the initial Table callout) Here's an example of how I want to cherry-pick the column results from Table callouts under my added system:

    Table A has 3 columns and 5 rows. When rolling for a result on Table A, no matter which of the 5 rows is rolled as the result, you will get output from all three columns of that row. So within the story template, let’s say we type:

    {Table A}

    #Table A|2#

    #Table A|3#

    The desired outcome would be that Table A’s output goes into an array, with each column occupying a different position. In the following two lines, we retrieve only what came from the second column of the original {Table A} callout, and on the third line we retrieve only what came from the third column.

    Conceptually, I know what I want to do, and I feel like I am close, but visualizing what I need to do next with my code is boggling me… Any suggestions would be greatly welcome

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