YGOPRO Forum

Welcome Guest! To enable all features please try to register or login.
Options
Go to last post Go to first unread
sieders1  
#1 Posted : Monday, September 11, 2017 12:22:42 PM(UTC)
sieders1

Rank: Newbie

Joined: 7/20/2017(UTC)
Posts: 18

Thanks: 2 times
Was thanked: 3 time(s) in 2 post(s)
I've been trying to code a new deck but all of the targeting functions are getting an error message in the ai editor window saying Warning: invalid card selecter (card id).

I didn't have this problem with this before but now it's constantly a problem. I was under the impression that these functions returned the index of the card you wanted in the table "cards" of cards it can possibly target?

here's one of the targeting functions that gets called

function sanganCard(cards)
--finds the first maiden possible, if no maiden then the ideal timelord
for i = 1,#cards do
if cards[i].id == maiden then --maiden is the id of Time Maiden
return i
end
end
--at this point no maidens so...
local ideal = idealTimelord(cards) --idealTimelord() returns the id of the best timelord right now
for i = 1,#cards do
if cards[i].id == ideal then
return i
end
end
return 1
end

Edited by user Monday, September 11, 2017 12:25:09 PM(UTC)  | Reason: Not specified

"All things in moderation" has to include moderation as well, right?
Snarky  
#2 Posted : Tuesday, September 12, 2017 12:42:33 PM(UTC)
Snarky

Rank: Advanced Member

Joined: 7/6/2013(UTC)
Posts: 2,192
Germany

Thanks: 10 times
Was thanked: 460 time(s) in 339 post(s)
The function itself looks like it should be working to me. How do you call it in your script?

Try to simplify it as much as possible, until it works, then add more and more of the function with some debug messages sprinkled in to track down the problem.

For example try, if just returning 1 does even work. No? Then the problem is probably how you even call the function in the first place. If it works, add another step. Rinse repeat.
sieders1  
#3 Posted : Wednesday, September 20, 2017 12:35:43 AM(UTC)
sieders1

Rank: Newbie

Joined: 7/20/2017(UTC)
Posts: 18

Thanks: 2 times
Was thanked: 3 time(s) in 2 post(s)
In my startup function I have this line which overrides the default targetting function with my own:

"deck.Card = TimelordsCard"

Here is the TimelordsCard function:

function TimelordsCard(cards, minTargets, maxTargets, triggeringID,triggeringCard)
if type(triggeringCard) == "boolean" then
return nil
end
if targFunctions[triggeringCard.id] ~= nil then
return targFunctions[triggeringCard.id](cards)
else
return 1
end
end
----targFunctions is a table full of the individual target functions for each card that needs one.
--this code IS calling the correct target function for the proper card that is returning an error.

all of the values the functions return are valid indices (<= #cards) so I must be using the function incorrectly right?

I've tried having this function always return 1 so i must be using it incorrectly. Do you have any ideas when/where the AI would call this?

Edited by user Wednesday, September 20, 2017 12:36:36 AM(UTC)  | Reason: Not specified

"All things in moderation" has to include moderation as well, right?
Snarky  
#4 Posted : Wednesday, September 20, 2017 10:46:09 AM(UTC)
Snarky

Rank: Advanced Member

Joined: 7/6/2013(UTC)
Posts: 2,192
Germany

Thanks: 10 times
Was thanked: 460 time(s) in 339 post(s)
Ah, you are returning the number directly. That is probably the issue, as the return expected by the OnSelectCard functions is a list of numbers instead of a number. Try changing it like this:

Code:

function sanganCard(cards)
--finds the first maiden possible, if no maiden then the ideal timelord
  for i = 1,#cards do
    if cards[i].id == maiden then --maiden is the id of Time Maiden
      return {i}
    end
  end
   --at this point no maidens so...
  local ideal = idealTimelord(cards) --idealTimelord() returns the id of the best timelord right now
    for i = 1,#cards do
      if cards[i].id == ideal then
        return {i}
      end
    end
  return {1}
end


I can change the handling of targeting functions on my end to allow for number returns as well, if they are within the given parameters. Probably makes sense, but won't work until the next version.

Also, at first glance, there could be a problem, if the triggeringCard is nil. triggeringCard is only valid within a chain, but the function can be called for some selections without a chain.

You are checking, if the type of triggeringCard is a boolean, which it would be, if it would always return false in case it doesn't exist. However I am pretty sure, it would just be nil instead, in which case this check fails, as nil does not have the type of boolean (I think?).

I'd change the check to something like this:

Code:

if triggeringCard and targFunctions[triggeringCard.id] then 
  return targFunctions[triggeringCard.id](cards)
else
...


Just using the triggeringCard as the condition causes it to return false, if it is false or nil, and true for any other case.

Generally, the function should be called anytime the AI needs to select cards for card effects, some summons and a couple other niche cases. There are exceptions, for example if the AI has to select cards that sum up to something, like a ritual summon requiring x amount of combined levels, these are partly handled by other functions

You can use debug messages (or AI.Chat, if you prefer) to make sure, the functions get called properly, and to display helpful information:

Code:

function TimelordsCard(cards,min,max,id,c)
  print("TimelordsCard is called")
  print("triggeringCard:")
  print(c)
  ...

Edited by user Wednesday, September 20, 2017 10:53:24 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error