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

Odd PopulateList Function Behavior

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

Tags:
  1. GeneN

    GeneN Chieftain

    Joined:
    Apr 11, 2017
    Messages:
    16
    Gender:
    Male
    I'm writing an LTP that identifies revealed resources and have encountered behavior that is very perplexing. The behavior occurs when parsing the code in a <PopulateList> element. Below is the code that results in the following message in the Lua Console:
    (Syntax Error: [string "return function()..."]:41: end expected (to close function at line 1) near '<eof>')

    If the single line containing "local temp3 = 0" is removed, there is no syntax error and the panel loads as expected.

    I am completely stumped. Any suggestions will be greatly appreciated.

    Code:
          <PopulateList>function()
              print("Test Resource Pin list")
              local resourcePinList = {}
              if efn_ResourcesToLocateList then
                print("Resource count: " .. #efn_ResourcesToLocateList)
                local resourceIndexesToLocate = {}
                local resourcePinData = {}
                local idxPlayer, Player, playerVis
                local idxLoc, resName, idxRes
                local temp1 = 1
                local temp2 = 1
                local temp3 = 0
                idxPlayer = Game.GetLocalPlayer()
                playerVis = PlayersVisibility[idxPlayer]
                player    = Players[idxPlayer]
                -- add efn_ResourcesToLocateList items to resourceIndexesToLocate consistent with efn_OnlyRevealedResources
                for idxLoc, resName in ipairs(efn_ResourcesToLocateList) do
                  if (not efn_OnlyRevealedResources) then
                    resourceIndexesToLocate[resName] = efn_ResourceDataByName[resName].Index
                  end
                end
                -- create a table of pin location data for plots containing resourcesToLocate consistent with efn_OnlyRevealedPlots.
                local idxPlot, plotRevealed, plot, resType
                for idxPlot = 0, Map.GetPlotCount() - 1 do
                  plotRevealed = "no"; if playerVis:IsRevealed(idxPlot) then plotRevealed = "yes" end
                  if (not efn_OnlyRevealedPlots) or (plotRevealed == "yes") then
                    plot = Map.GetPlotByIndex(idxPlot)
                    resType = plot:GetResourceType()
                    for resName, idxRes in pairs(resourceIndexesToLocate) do
                      if resType == idxRes then
                        local x = plot:GetX()
                        local y = plot:GetY()
                        table.insert(resourcePinData, {resName, idxPlot, x, y, plotRevealed})
                        table.insert(resourcePinList, resName .. ";" .. idxPlot .. ";" .. x .. ";" .. y .. ";" .. plotRevealed)
                        break
                      end
                    end
                  end
                end
              end 
              return resourcePinList
            end
          </PopulateList>
    
     

Share This Page