Page 1 of 1

Help with error = attempt to index a nil value

PostPosted: 02 May 2014, 18:51
by Luchian
I'm having a time of it trying to work out why I keep getting the error :
[lua] [string "COORDINATED_BARRAGE_153151_TITLE (RESOLUTION_TIME_ACTION)~0x000005ea"]:2: attempt to index a nil value
on the following card I made for Coordinated Barrage.
I used Sumomole's Adaptive Automaton and code for the base and the card seems to work just fine. I keep getting this error when I quit though and I keep trying to fix it but I think I have been looking at code too long the past few weeks and I have no idea what to do to get rid of the error.
Here is the code :
Code: Select all
  <SPELL_ABILITY>
<SFX text="TARGET_PIERCE_PLAY" />
      <TARGET tag="CARD_QUERY_CHOOSE_CREATURE_DEAL_DAMAGE" definition="0" compartment="0" count="1" />
      <TARGET_DEFINITION id="0">
    local filter = ClearFilter()
    filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
    local subFilter = filter:AddSubFilter_Or()
       subFilter:Add(FE_IS_ATTACKING, true)
       subFilter:Add(FE_IS_BLOCKING, true)
    </TARGET_DEFINITION>
      <RESOLUTION_TIME_ACTION>
    local zone = ZONE_ANYWHERE
    local player = EffectController()
    S_CountCreatureTypes(zone, player)
    </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION repeating="1">
    local player = EffectController()
     return S_ChooseCreatureType(player)
    </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
    LinkedDC():Set_Int(0, S_ChosenCreatureType())
    </RESOLUTION_TIME_ACTION>
      <RESOLUTION_TIME_ACTION>
    local target_creature = EffectDC():Get_Targets(0):Get_CardPtr(0)
    if ( target_creature ~= nil ) then
    local filter = ClearFilter()
    filter:Add( FE_SUBTYPE, OP_IS, S_ChosenCreatureType() )
    filter:Add( FE_CONTROLLER, OP_IS, EffectController() )
    local damage = filter:Count()
       EffectSourceLKI():DealDamageTo( damage, target_creature )
    end
    </RESOLUTION_TIME_ACTION>
      <AI_SIMPLIFIED_TARGETING compartment="0" hint="HINT_ENEMY_ONLY" />
  </SPELL_ABILITY>
Please help. I am a nil value. :?

Re: Help with error = attempt to index a nil value

PostPosted: 02 May 2014, 19:03
by MC Brodie
From the error message I'm guessing it's the line that says:

Code: Select all
local target_creature = EffectDC():Get_Targets(0):Get_CardPtr(0)
Try changing it to:

Code: Select all
local target_creature = EffectDC():Get_Targets(0) and EffectDC():Get_Targets(0):Get_CardPtr(0)
See this post:
viewtopic.php?f=63&t=11418&start=75#p145343

Re: Help with error = attempt to index a nil value

PostPosted: 02 May 2014, 20:43
by Luchian
Thanks for your help. Sadly it didn't work and I'm still getting that error. :?

Re: Help with error = attempt to index a nil value

PostPosted: 02 May 2014, 21:48
by sumomole
del LinkedDC, it's redundant.

EDIT: for Coordinated Barrage, you should use ZONE_BATTLEFIELD rather than ZONE_ANYWHERE, because it just count your permanents.

Re: Help with error = attempt to index a nil value

PostPosted: 02 May 2014, 22:31
by Luchian
Just tested it and it worked. Thank you!