Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Why do debug tell me I use a null value


def GetCloser(maTarget):
    if maTarget and hero.distanceTo(maTarget)>10:
        midX = (hero.pos.x + maTarget.pos.x)/2
        midY = (hero.pos.y + maTarget.pos.y)/2
    elif maTarget :

so debug tells me that hero.moveXY(maTarget.pos.x,maTarget.pos.y) uses null parameter instead of x=integer and y=integer. I thought that the elif would be false so that part of the code would not be executed.


Do you have boots with the moveXY? It could be an equipment problem


yep i have those boots. and the code runs for a while.


Then what happens? :thought_balloon:


As far as I understand coding : if maTarget.pos.x is null, it’s because maTarget is also null. So I do not get why anything after the elif would ever be executed. So I should be wrong somewhere and therefore ask if someone knows about it.


What is ma Target. You have to define what ma Target is


It’s called from this part of code and only this

cible = hero.findNearestEnemy()
if cible:

so here it is an enemy, but it could also be an item. btw this is python


So you are trying to go to the enemy.pos if so then put cible instead of ma Target


when you call : # call to the function/method)
maTarget = anyEnemy
maTarget = anyItem

or there wouldn’t be any benefits to define functions/methods


Which level are you doing?


stonehold siege? not sure about the name in English (last one in the forest). but the question is not especially about that level.


oh ok but you don’t really need that you can just command all of your troops to defend you


and attack the enemies then you can easily win with any hero


Is this question about multyplayer levels?


not especially. but could be used to optimze your movements on the map and avoid moving to dead enemies.
(only if the code was running as intended :’( )


Sometimes maTarget exists when you call GetCloser(maTarget) function, but dies or gets invisible on the 2d or 3d line of function, so hero stucks. Depends on loops and other code, of course. But it made me agrrhh! many times)


I suppose you are trying to do recursion and the general idea is

def GetCloser(maTarget):
    if maTarget and maTarget > 3:
        mid = maTarget/2
        return GetCloser(mid)
    else :
        return True


I’m also eager to know how this algorithm can be implemented with moveXY and move


yup. the idea is :

  • maTarget is any object with position so pos.x and pos.y. lets call it enemy
    if the distance between hero and enemy is too much (10 here) and enemy still exist , I do half the travel. then call GetCloser() again
    if the distance is ok (<10) and enemi still exist go to enemi.


I understand your intentions and already tested the code. If this is some kind of recursion? Did you click on the link?


yup, I clicked. and yes it is recursion as far as a function call itself (if I remember well what recursion is :wink: )