GetGamerules() problem...

Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
edited September 2012 in Modding
Ok, here is the function for GetGamerules() as defined in Gamerules_Global.lua

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function GetGamerules()

    if Server then
        return globalGamerules
    end
    
    return nil
    
end<!--c2--></div><!--ec2-->

This tells me, if the code is being run server-side, calling GetGamerules() should return the variable globalGamerules.

I know this to be working correctly, because in Server.lua I have the following statement:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local gameRules = GetGamerules()
if gameRules == 'gc_gamerules' then
    kMapEntityLoadPriorities[GCGamerules.kMapName] = 1
elseif gameRules == 'gcf_gamerules' then
    kMapEntityLoadPriorities[GCFGamerules.kMapName] = 1
end<!--c2--></div><!--ec2-->

This picks up the relevant entity and loads it at priority. If gameRules was empty, nothing would load...

However....

When I run this in Gorge_Server.lua like this:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local gameRules = GetGamerules()

function Gorge:InitWeapons()

    Alien.InitWeapons(self)
    
    if gameRules == 'gc_gamerules' then

        self:GiveItem(SpitSpray.kMapName)
        self:GiveItem(DropStructureAbility.kMapName)
        self:GiveItem(DropStructureAbility2.kMapName)
        self:GiveItem(DropStructureAbility3.kMapName)

    elseif gameRules == 'gcf_gamerules' then
        self:GiveItem(SpitSpray.kMapName)
        self:GiveItem(BileBomb.kMapName)
        self:GiveItem(DropStructureAbility.kMapName)
    
    end
    self:SetActiveWeapon(SpitSpray.kMapName)
end<!--c2--></div><!--ec2-->

I don't get given any weapons, and only an error about being unable to SetActiveWeapon to SpitSpray.

Gorge_Server is only called on the server, so I can't understand why this is not working...

What is not working, or what am I not understanding? Any help, greatly appreciated....

Comments

  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited September 2012
    HAHAHA

    Ignore the whole thing :( gameRules is always nil on the server.lua, it just loads the relevant map entity anyway.

    That's why it doesn't work in Gorge_Server.lua :(

    I do however need a way to work out what the currently running game mode is.

    Any ideas?
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited September 2012
    OK, I fixed it...

    For those who are having this kind of problem in the future...

    I added a function to the shared section of my gamerules files called GetMapName() which returns the mapname.

    I just called GetGamerules():GetMapName() and now it works.

    EDIT---------------

    OK I lied...

    I don't know what happened on the earlier test, but this is not working. Gives me an error saying attempt to index a nil value.

    This is ridiculous. This convention is used all over the game, so why won't it work here...
Sign In or Register to comment.