1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Function for a Live Tuner Panel

Discussion in 'Mod Creation Help' started by GeneN, May 25, 2017.

  1. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
    I would like to create a custom function and access it from a live tuner panel. I have created a Lua file and can load it by identifying it as a <LoadStates> item in the ltp file. It initializes variables that I use in the live tuner panel and seems to work as expected. However, when I add a function definition to the Lua file the live tuner panel does not work as expected.

    A pointer or two would be greatly appreciated!
     
  2. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
    Update: I changed the structure of the code in lua file referenced in <LoadStates> to 1) define variables, 2) define functions and then 3) call the function that initializes the variables. This structure makes the functions referenced in <LoadStates> accessible by code in the ltp file. ltp references:
    Code:
      <CompatibleStates>
        <string>InGame</string>
        <string>_TunerResourcePanel</string>
      </CompatibleStates>
      <LoadStates>
        <string>_TunerResourcePanel</string>
      </LoadStates>
    
    Referenced Lua code:
    Code:
    g_PanelHasFocus           = false
    g_SelectedPlayer          = -1
    efn_OnlyRevealedResources = true
    efn_OnlyRevealedPlots     = true
    efn_ResourceNames         = {}
    efn_ResourceDataByName    = {}
    efn_ResourcesToLocateList = {}
    efn_ResourcePinData       = {}
    
    -------------------------------------------------------------------------------
    
    function efn_IsResourceRevealed(resName, player)
    -- Function returns true iff the specified resource has been revealed to the specified player
       print("efn_ResourceRevealed entered")
       local idxTech, idxCivic, techRevealed, civicRevealed
       local resource = efn_ResourceDataByName[resName]
       idxTech  = resource.IndexPrereqTech
       idxCivic = resource.IndexPrereqCivic
       techRevealed  = (idxTech  == -1) or player:GetTechs():HasTech(idxTech)
       civicRevealed = (idxCivic == -1) or player:GetCulture():HasCivic(idxCivic)
       return techRevealed and civicRevealed
    end
    
    function efn_Initialize()
       print("_TunerResourcePanel loading")
       local resource, resourceName, prereqTech, idxPrereqTech, prereqCivic, idxPrereqCivic
       for resource in GameInfo.Resources() do
         resourceName = string.gsub(resource.ResourceType, "RESOURCE_", "")
         table.insert(efn_ResourceNames, resourceName)
         prereqTech = resource.PrereqTech
           idxPrereqTech = -1; if prereqTech then idxPrereqTech = GameInfo.Technologies[prereqTech].Index end
         prereqCivic = resource.PrereqCivic
           idxPrereqCivic = -1; if prereqCivic then idxPrereqCivic = GameInfo.Civics[prereqCivic].Index end
         efn_ResourceDataByName[resourceName] = {Index = resource.Index, IndexPrereqTech = idxPrereqTech, IndexPrereqCivic = idxPrereqCivic}
       end
       print("Initialized Resource Data Lists:")
       print("\tCount\t\tName\t\tIndex\tIndexReqTech\t\tIndexReqCivic")
       local idxRes, resourceData
       for idxRes, resourceName in ipairs(efn_ResourceNames) do
           resourceData =  efn_ResourceDataByName[resourceName]
           print("\t" .. idxRes .. "\t" .. resourceName .. "\t" .. resourceData.Index .. "\t" .. resourceData.IndexPrereqTech .. "\t" .. resourceData.IndexPrereqCivic)
       end
       print("**********************************")
    end
    
    efn_Initialize()
    
    The function: "efn_IsResourceRevealed(resName, player)" is available in the ltp code.
     

Share This Page