I stuck in the wild horse ,plz h

    -- 你怎么寻找最近的友好单位?
    -- 马=?
  horse = this.self:findNearest(this.findFriends())
    if horse then
        x1 = horse.pos.x - 7
        x2 = horse.pos.x + 7
        y = horse.pos.y
        if x1 >= 1 then
            self:moveXY(x1, y)
            -- 移动到马的y坐标,但使用x1作为x坐标。
            elseif x2 <= 79 then
            self:moveXY(x2, y)
            -- 移动到马的y坐标,但使用x2作为x坐标。
        local distance = self:distanceTo(horse)
        if distance <= 10 then
            -- 移到到红色的x来使马返回农场。
            self:moveXY(27, 54)
            -- 移回牧场开始寻找下一匹马。
            self:moveXY(43, 21)

this is my code.but it always break some mistake.

Uppercase or lowercase problem.Try this.

I have used this, why it show me this again…

thank you for your help~


I tried your 4 line: horse = this.self:findNearest(this.findFriends())
and it didn’t run.
I changed it to: horse = self.findNearest(self.findFriends())
and I managed the level.
Hope this helps!


It depends. @WatchAndLearn are you using Python?


yes (was allready wondering) Sorry my mistake!


Sorry ,I don’t use Python,I am just using LUA.


Still thanks for your words.

if you find some clues plz tell me then. :grin:

horse = self:findNearest(self:findFriends())

Lua uses self:methodName() to call methods, whereas it is just self.property to access non-method properties. It doesn’t use this, which is a JavaScript thing.

Also, you don’t put an end after the elseif x2 <= 79 then if-statement.


@WatchAndLearn Thank you for wanting to help, but please don’t post correct code. It makes it too easy for others and really takes away the whole point of the game.


OK WILL delete it.sorry .


Thanks very much, WatchAndLearn. Few people do that.