[LUA] lua-code not working after update

Discussion in 'Civ5 - Creation & Customization' started by martijnaikema, Dec 17, 2010.

  1. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    I am having a lot of trouble with my lua-file since the update. This code crashes in FireTuner. I am sure it worked before the update:

    Spoiler :

    for index,mPlayer in pairs(Players) do
    if (mPlayer:IsMinorCiv() or mPlayer:IsBarbarian()) then
    else
    print (mPlayer:GetCivilizationAdjectiveKey())
    end -- if mPlayer
    end -- for index


    It looks like that with the code not only the active players (AI or human) are loaded. Cause when I run a game with 8 players and 16 citystates, this code:
    Spoiler :

    for index,mPlayer in pairs(Players) do
    if (mPlayer:IsMinorCiv() or mPlayer:IsBarbarian()) then
    else
    print (mPlayer:GetID())
    end -- if mPlayer
    end -- for index


    returns in FireTuner:
    Spoiler :

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    0


    So it returns 47 values in stead of 8. Does anyone know how to fix this?
     
  2. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    You need an IsAlive() check in there. You should also check for null entries. So something like:

    Spoiler :

    for index,mPlayer in pairs( Players ) do
    if( mPlayer ~= nil and mPlayer:IsAlive() ) then
    if (mPlayer:IsMinorCiv() or mPlayer:IsBarbarian()) then
    else


    and so on.
     

Share This Page