It is currently 18 Jul 2025, 21:36
   
Text Size

Help with error = attempt to index a nil value

Moderator: CCGHQ Admins

Help with error = attempt to index a nil value

Postby Luchian » 02 May 2014, 18:51

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. :?
Luchian
 
Posts: 20
Joined: 21 Mar 2014, 20:50
Has thanked: 10 times
Been thanked: 2 times

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

Postby MC Brodie » 02 May 2014, 19:03

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
-----------------------------------------------------------------------
Song of the Day: 46 and 2 (cover)
MC Brodie
 
Posts: 310
Joined: 01 Jun 2013, 00:10
Has thanked: 44 times
Been thanked: 34 times

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

Postby Luchian » 02 May 2014, 20:43

Thanks for your help. Sadly it didn't work and I'm still getting that error. :?
Luchian
 
Posts: 20
Joined: 21 Mar 2014, 20:50
Has thanked: 10 times
Been thanked: 2 times

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

Postby sumomole » 02 May 2014, 21:48

del LinkedDC, it's redundant.

EDIT: for Coordinated Barrage, you should use ZONE_BATTLEFIELD rather than ZONE_ANYWHERE, because it just count your permanents.
User avatar
sumomole
Programmer
 
Posts: 611
Joined: 07 Jun 2011, 08:34
Has thanked: 51 times
Been thanked: 234 times

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

Postby Luchian » 02 May 2014, 22:31

Just tested it and it worked. Thank you!
Luchian
 
Posts: 20
Joined: 21 Mar 2014, 20:50
Has thanked: 10 times
Been thanked: 2 times


Return to 2014

Who is online

Users browsing this forum: No registered users and 18 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 18 users online :: 0 registered, 0 hidden and 18 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 18 guests

Login Form