Results 1 to 2 of 2

Thread: How to print out the result return by GetAttackTarget() ?

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    123

    How to print out the result return by GetAttackTarget() ?

    code I have tried, all under Think() function:

    Code:
    	local target =  npcBot:GetAttackTarget();
    	if (target ~= nil) then
    		print('target = '..target);
    	end
    from error message I know target is a table, so I tried to print it as table:

    Code:
    local target =  npcBot:GetAttackTarget();
    	if (target ~= nil and #target > 0) then
    		print('target1 = '..target[1]);
    	end
    Bot is attacking some creep and no result is printed out, while no error message.

    And:

    Code:
    local target =  npcBot:GetAttackTarget();
    	if (target ~= nil) then
    		for unit_k, unit in pairs(target) do
    			print('target = '..unit);
    		end
    	end
    error message: target is a usedata
    Last edited by lunarbreez; 02-14-2017 at 02:41 PM.

  2. #2
    Basic Member
    Join Date
    Jun 2013
    Posts
    274
    It's actually technically not a Table. It's returning the handle to the target.

    So you need to use unit-scoped functions on it, like:

    Code:
    local target =  npcBot:GetAttackTarget();
    if (target ~= nil) then
    	print('target = '..target:GetUnitName());
    end
    Last edited by Cornbane; 02-14-2017 at 02:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •