I'm stuck, coding error..

Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
edited August 2012 in Modding
I have decimated NS2 to get my mod proving grounds running only what it needs. Unfortunately I am generating many code errors, purely because of my haphazard hacking of the code base.

Any way I have one code error that has me completely stumped. I think it may be one of those odd ones where the error is someplace else, but is only caught here. Anyway, here is the error:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script Error #1: lua/GUIAlienBuyMenu.lua:403: attempt to index field '?' (a nil value)
    Call stack:
    #1: _InitializeMouseOverInfo lua/GUIAlienBuyMenu.lua:403
        self = GUIAlienBuyMenu{}
    #2: Initialize lua/GUIAlienBuyMenu.lua:119
        self = GUIAlienBuyMenu{}
    #3: SharedCreate lua/GUIManager.lua:76
        scriptName = "GUIAlienBuyMenu"
        result = {1="GUIAlienBuyMenu"}
        creationFunction = {kEvolveButtonTextSize=21.462890625,_Updat{lots of details here}
        newScript = GUIAlienBuyMenu{}
    #4: CreateGUIScript lua/GUIManager.lua:85
        self = GUIManager{}
        scriptName = "GUIAlienBuyMenu"
    #5: Buy lua/Alien_Client.lua:435
        self = Entity{{lots of details here}
    #6: HandleButtons lua/Player.lua:2469
        self = Entity{{lots of details here}
        buyButtonPressed = true
    #7: HandleButtons lua/Alien.lua:409
        self = Entity{{lots of details here}
    #8: lua/Player.lua:1583
        self = Entity{lots of details here}
    #9: [C]:-1<!--c2--></div><!--ec2-->

Here is the line in the function in question. The rest of the function is irrelevant in this particular case:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->    self.mouseOverInfo:SetText(string.upper(GUIAlienBuyMenu.kAlienTypes[AlienBuy_GetCurrentAlien()].Name))<!--c2--></div><!--ec2-->

Now I have edited kAlienTypes from:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->GUIAlienBuyMenu.kAlienTypes = { { Name = Locale.ResolveString("FADE"), Width = GUIScale(188), Height = GUIScale(220), XPos = 4, Index = 1 },
                                { Name = Locale.ResolveString("GORGE"), Width = GUIScale(200), Height = GUIScale(167), XPos = 2, Index = 2 },
                                { Name = Locale.ResolveString("LERK"), Width = GUIScale(284), Height = GUIScale(253), XPos = 3, Index = 3 },
                                { Name = Locale.ResolveString("ONOS"), Width = GUIScale(304), Height = GUIScale(326), XPos = 5, Index = 4 },
                                { Name = Locale.ResolveString("SKULK"), Width = GUIScale(240), Height = GUIScale(170), XPos = 1, Index = 5 } }<!--c2--></div><!--ec2-->

-to-

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->GUIAlienBuyMenu.kAlienTypes = { { Name = Locale.ResolveString("FADE"), Width = GUIScale(188), Height = GUIScale(220), XPos = 4, Index = 1 },
                                { Name = Locale.ResolveString("GORGE"), Width = GUIScale(200), Height = GUIScale(167), XPos = 2, Index = 2 },
                                { Name = Locale.ResolveString("LERK"), Width = GUIScale(284), Height = GUIScale(253), XPos = 3, Index = 3 },
                                { Name = Locale.ResolveString("SKULK"), Width = GUIScale(240), Height = GUIScale(170), XPos = 1, Index = 5 } }<!--c2--></div><!--ec2-->

I also tried skulk with an index of 4, but still the same error.

I have removed Onos completely from the code, and I don't want to have to re-instate him just because this sill function is trying to keep him in!!

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->AlienBuy_GetCurrentAlien()<!--c2--></div><!--ec2-->

Has an assert and a printout if it does not have the techId of the current alien, so the error is not in that part of the line either.

This variable is called many times throughout the code, so either doesn't cause problems there, or more likely, first shows up when initializing here. Any advice? Or even a general direction to look in, this one has me baffled :)

Comments

  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    edited August 2012
    Try:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if GUIAlienBuyMenu.kAlienTypes[AlienBuy_GetCurrentAlien()] then
       self.mouseOverInfo:SetText(string.upper(GUIAlienBuyMenu.kAlienTypes[AlienBuy_GetCurrentAlien()].Name))
    end<!--c2--></div><!--ec2-->
  • DoublehexDoublehex Join Date: 2012-06-23 Member: 153607Members
    Found the problem. Skulk id is 5 and it was trying to access outside the bounds of the table.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Double hex was close, the actual problem was that there was an Onos still loose in the code!! In AlienBuy_Client i had left the kTechId.Onos in the list, which is why it wasn't working even when I changed it to 4, kTechId.Onos was the ? fieldref :P
  • DoublehexDoublehex Join Date: 2012-06-23 Member: 153607Members
    edited August 2012
    Oh, I guess you didn't really read the messages I sent you. I told you that was the problem lol
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    OK so here's another first for me...

    Here's the output log..

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Server  : 0.033115 : CreateEntityForTeam(nil): Couldn't kTechDataMapName for entity.
    Script Error #1: lua/NS2Utility_Server.lua:66: assertion failed!
        Call stack:
        #1: assert [C]:-1
        #2: lua/NS2Utility_Server.lua:66
            techId = nil
            position = Vector{y=-26.009599685669,x=39.014400482178,z=-35.763198852539}
            teamNumber = 4
            player = nil
            newEnt = nil
            mapName = nil
        #3:  (tail call):-1
        #4: SpawnCommandStructure lua/PlayingTeam.lua:482
            techPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=5,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
            teamNumber = 4
        #5: SpawnInitialStructures lua/PlayingTeam.lua:500
            self = Forts1Team{}
            techPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=5,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
        #6: SpawnInitialStructures lua/Forts1Team.lua:303
            self = Forts1Team{}
            techPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=5,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
        #7: ResetTeam lua/PlayingTeam.lua:136
            self = Forts1Team{}
            initialTechPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=5,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
        #8: ResetGame lua/GCFGamerules.lua:494
            self = Entity{}
            techPoints = {}
            team1TechPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=5,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
            team2TechPoint = Entity{locationId=1,occupiedTeam=0,modelIndex=2,showObjective=false,locationEntI
    d=6,gameEffectsFlags=0,sighted=false,physicsType=4,attachedId=-1,physicsGroupFilterMask=0,smashScouted=false,collisionRep=0,animationGraphIndex
    =1,smashed=false,physicsGroup=13,techId=28}
        #9: lua/GCFGamerules.lua:857
            self = Entity{}
            timePassed = 0.033115386962891<!--c2--></div><!--ec2-->

    Now all the relevant data is passed to the function, but then the error -

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->#3:  (tail call):-1<!--c2--></div><!--ec2-->

    Any idea what this means? It wipes the techId which is being passed (techId=28 in this case), and then throws up an error. Any idea what I'm missing..
  • xmtxmt Join Date: 2012-08-22 Member: 156218Members
    I don't know why it's showing up as (tail call), but from looking at the code it appears to be a call to function TechPoint:SpawnCommandStructure(teamNumber) in TechPoint_Server.lua:39.

    That sets techId as local techId = ConditionalValue(alienTeam, kTechId.Hive, kTechId.CommandStation) which is probably where your nil is coming from.

    Then it calls function CreateEntityForTeam(techId, position, teamNumber, player) in NS2Utility_Server.lua:43 which is #2 in your error.

    Did you remove the code for Hives or Commandstations?
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited August 2012
    Sorry, I forgot to post that edited function :P

    Here it is:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function TechPoint:SpawnCommandStructure(teamNumber)
        
        if GetGamerules() == "gc_gamerules" then
            local alienTeam = (GetGamerules():GetTeam(teamNumber):GetTeamType() == kAlienTeamType)
            local techId = ConditionalValue(alienTeam, kTechId.Hive, kTechId.CommandStation)
        elseif GetGamerules() == "gcf_gamerules" then
            local fort1Team = (GetGamerules():GetTeam(teamNumber):GetTeamType() == kFort1TeamType)
            local techId = ConditionalValue(fort1Team, kTechId.Hive, kTechId.Hive)
        end
        
        return CreateEntityForTeam(techId, Vector(self:GetOrigin()), teamNumber)
        
    end<!--c2--></div><!--ec2-->

    The problem seems to be the if statements. I just tested gc, and got the same error. How do I sort this one out?

    I have deleted kTechId.CommandStation, from the tech data files, but note I also have done that in the last release of GorgeCraft and it works fine, as there is only 1 team in that line.

    I have reverted the code back, and it works in normal Gorgecraft mode with the default line.
    This tells me the <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if GetGamerules() == "text"<!--c2--></div><!--ec2--> is not working.
  • xmtxmt Join Date: 2012-08-22 Member: 156218Members
    This might be a stupid question but why are you comparing the result of GetGamerules() with a string? I don't know how equality works in lua, but GetGamerules() seems to return an object/table.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited August 2012
    gc_gamerules is the mapname for the class entity GCGamerules.

    Maybe the code should be something like<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if GetGamerules.kMapName == "gc_gamerules" then<!--c2--></div><!--ec2-->
    or
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if kMapName.GetGamerules() == "gc_gamerules" then<!--c2--></div><!--ec2-->

    EDIT-----

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if GetGamerules().kMapName == "gc_gamerules" then<!--c2--></div><!--ec2-->

    fixed it :)
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Thanks for your help xmt.

    I was too tired to re-post last night :)

    Lua seems to be very tolerant. For example I have a working string where I call

    gameRules = GetCamerules()

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if gameRules == "gc_gamerules" then<!--c2--></div><!--ec2-->

    This seems to show that it is tolerant, although it also shows the first line of data happens to be the kMapName. I have updated this string to make it more resilient should that ever change in the future :)
Sign In or Register to comment.