SamSieder
2017-03-25T19:52:16Z
hey so this is my first AI and I'm having trouble with my function to select attack targets never being called

" deck.AttackTarget = WattAttackTarget" is in startup but the function is not getting called, ever. I've checked that it's spelled the same and everything.

Does anyone know what could be happening?



I would love to attach the deck and ai but am not sure how so if anyone could offer up that help too that would be cool

thanks
SamSieder
2017-03-25T19:54:16Z
um never mind about that last part
neftalimich
2017-03-26T00:41:08Z
There is no problem. [:confu:]

It works properly.

EDIT: Mostly of your monsters attack directly, this function is not called when this happens

UserPostedImage
SamSieder
2017-03-26T03:01:11Z
Huh, it must be something wrong with my files then. I know about the direct attack thing.

Thanks though, I'll post a new version without that chat everytime it's called then.
neftalimich
2017-03-26T04:54:29Z
Originally Posted by: SamSieder 

Huh, it must be something wrong with my files then. I know about the direct attack thing.

Thanks though, I'll post a new version without that chat everytime it's called then.



Post the file, I could check them again.

Maybe, you have a corrupt file.

You may use the command print (ygopro_vs_ai_debug.exe) or AI.chat in file: YGOPro 1.033.D\ai\mod\SelectBattleCommand.lua

for debug purpose.


  local d = DeckCheck()
  if d and d.AttackTarget then
    result = d.AttackTarget(cards,attacker)
  end
SamSieder
2017-03-26T12:08:53Z
i'll definitely do that.

I ran into this problem with my init function as well. I think what was happening was that once the function returned a nil to let the default function take over, it never called my function again. your screenshot appears to be of the AI's first attack so I'm curious if the function was called again after a direct attack went through.

also the new uploaded file returns the available monster as an attack target instead of nil now if it didn't have one before, so here's hoping that keeps the default from taking over completely
neftalimich
2017-03-26T16:19:32Z
Originally Posted by: SamSieder 

i'll definitely do that.

I ran into this problem with my init function as well. I think what was happening was that once the function returned a nil to let the default function take over, it never called my function again. your screenshot appears to be of the AI's first attack so I'm curious if the function was called again after a direct attack went through.

also the new uploaded file returns the available monster as an attack target instead of nil now if it didn't have one before, so here's hoping that keeps the default from taking over completely



Your problem is in another step, this usually happens, If returns an **incorrect value** (EDIT) value by a error/bug, it will no longer go through the rest of the code.
SamSieder
2017-03-26T17:39:49Z
That's what I was afraid of.

I think I misunderstood how returning nil worked. I was having my function return nil if i thought the defaults could handle every other case. I didn't realize it would mean the function would never be called again. I'll need to rework that.

Can't thank you enough for the help.

It bugs me to leave an unfinished project up though so i think i'll take it down for now until i get it working
neftalimich
2017-03-27T20:49:25Z
Originally Posted by: SamSieder 

That's what I was afraid of.

I think I misunderstood how returning nil worked. I was having my function return nil if i thought the defaults could handle every other case. I didn't realize it would mean the function would never be called again. I'll need to rework that.

Can't thank you enough for the help.

It bugs me to leave an unfinished project up though so i think i'll take it down for now until i get it working



In init function you can return nil values.

Sorry, I meant, when the code makes a crash or returns an incorrect value, the rest of code will not work.

For example, When you must return an array of 6 values, but you return an array of 5 values, or you return a nil array, or you have sitanxis error, etc.

You must always return a correct value.
SamSieder
2017-03-27T21:00:03Z
That makes sense but that usually throws an error message in the chat, right?

Also just to make sure i understand, if a targeting function returns nil, will the defaults take over?
neftalimich
2017-03-27T23:41:39Z
Originally Posted by: SamSieder 

That makes sense but that usually throws an error message in the chat, right?

Also just to make sure i understand, if a targeting function returns nil, will the defaults take over?




nop, mostly chat does not show the errors.


Sorry english is not my native language, Sometimes it is difficult for me to say what I want.

An Example that how it works.

Percy Source:


--- OnSelectCard ---
--
-- Called when AI has to select a card. Like effect target or attack target.
-- Note: "Always check if your return value has the correct amount of targets as specified by minTargets, maxTargets"
-- Example card(s): Caius the Shadow Monarch, Chaos Sorcerer, Elemental HERO The Shining
-- 
-- Parameters:
-- cards = table of cards to select
-- minTargets = how many you must select min
-- maxTargets = how many you can select max
-- triggeringID = (deprecated) id of the card that is responsible for the card selection. This parameter is deprecated. Please use triggeringCard instead.
-- triggeringCard = card object of the card that is responsible for the card selection. If card is unknown, triggerCard will be false
--
-- Return: 
-- result = table containing target indices
function OnSelectCard(cards, minTargets, maxTargets, triggeringID, triggeringCard)
	local result = {}
	
	print("OnSelectCard",minTargets,maxTargets)
	if triggeringCard ~= false then
		print("OnSelectCard triggered by: " .. triggeringCard.id)
	else
		print("triggeringCard is unknown!")
	end
	
	-- Example implementation: always choose the mimimum amount of targets and select the index of the first available targets
	for i=1,minTargets do
		result[i]=i
	end
	
	return result
end


Snarkie Base (ai/mod/SelectCard.lua):

Steps (This structure applies to almost all functions: Card, Battle, Chain, etc.)

1. Some priority stuffs.
2. Check if your function (WattCard for example) returns a value. if d and d.Card then
3. else returns generic results.
4. else returns random minimum amount of values.


function OnSelectCard(cards, minTargets, maxTargets, triggeringID,triggeringCard)
  local result = {}
  
  ... --hidden "1. PRIORITY STUFFS"

  local d = DeckCheck() -- "2.THIS WILL FIND YOUR OWN SCRIPT."
  if d and d.Card then
    result = d.Card(cards,minTargets,maxTargets,triggeringID,triggeringCard)
  end
  
  ... -- "hidden 3. Generic functions"
  
  -- "4. always choose the mimimum amount of targets and select random targets"
  local targets = {}
  for i,c in pairs(cards) do
    targets[i]=c
    c.index=i
  end
  for i=1,minTargets do
    local r=math.random(1,#targets)
    local c=targets[r]
    table.remove(targets,r)
    result[i]=c.index
  end
  return result
end


EDIT: So, if your own script fails the application will do incorrect things, like omit the cost of activation, omit cost materials, etc etc..
Snarky
2017-04-27T09:24:43Z
Great to see more people working on the AI, while I was gone. I hope, this is working out, did you solve the problem?

Also thanks neftalimich for keeping an eye on the forums for me <3
sieders1
2017-07-21T03:30:46Z
Yes, everything with this one (barring a one troublesome misplay which i'll pretend is just the ai intentionally bluffing) this deck appears to more or less do its thing. It isn't mind-blowingly powerful, but my friends and I have fun with it. anyway I just posted the (mostly) finished files and I have a fun slifer deck for the ai in the works.

by the way thanks to both of you guys for the help. i owe you a coke or something
"All things in moderation" has to include moderation as well, right?
Users browsing this topic