Page 2 of 2 FirstFirst 1 2
Results 11 to 14 of 14

Thread: BUG: GetTower(..,..) Will return nil if tower has fallen

  1. #11
    Basic Member
    Join Date
    May 2014
    Yep my bad. I've tried using IsAlive() and it still works. What is the difference between using "for building_k, building in pairs(tablebuildings) do" and "for _, building in pairs(tablebuildings) do"? Can it affect the handle?

  2. #12
    Basic Member
    Join Date
    Mar 2012
    No. The syntax is for key,pair in pairs(key_pair_value) do ... end.
    Sometimes you only need the key, sometimes you only need the pair and sometimes you need both. using for _, value is just a way of saying you only need the value, but not the key. This is because you can't do for , value in pairs() since it's a syntax error. Using _ is a simple way of using an allowed character to "not" use the key Of course you can still use _ in the code itself, it's just a cosmetic thing for coders to tell other coders that the key isn't needed.

    For readability you should only write what you use. If, in pair, you only need the key, then using for key,value in pairs() is just overkill.

    Think of it as best practice.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  3. #13
    Valve Developer
    Join Date
    Sep 2011
    I'm not seeing a crash with this as my main bot think code, when destroying the first top tower:

    function Think()
    	local tower = GetTower(GetOpposingTeam( ), TOWER_TOP_1);	
    	if (tower ~= nil and tower:IsAlive() ) then
    		print ("tower alive" )

  4. #14
    Basic Member
    Join Date
    Dec 2016
    when we check tower ~= nil, no crash happen and that's right. but if we only use IsAlive() function, crash happens. just for notice. thanks Chris

Posting Permissions

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