More Robust safePath code - not working (Python)


#1

I was trying my hand at creating a re-usable function and am getting rather annoyed at the error message “Assigning to r value”. What am I doing wrong, please?

self.SafePath(fx, fy) = function:
    tarA = Vector(fx, fy)
    vecA = Vector.subtract(tarA, self.pos)
    # This creates a 90° rotated, 0.5 m long vector realtive to vec.
    normV = Vector.multiply(Vector.normalize(Vector.rotate(vecA, 1.5708)), 0.5)
    targetL = [tarA,   Vector.add(tarA, normV),   Vector.subtract(tarA, normV)]
    startL  = [self.pos, Vector.add(self.pos, normV), Vector.subtract(self.pos, normV)]
    isFree = True
    for s in startL:
        for t in targetL:
            isFree = isFree and self.isPathClear(s, t)
    return isFree

[And a big thank you to J_F_B_M (i.e. Joachim Brehmer), without whom I would not have gotten even this far.]


#2

For Python, just try this function definition:

def safePath(fx, fy):

For JavaScript, it would be:

this.safePath = function(fx, fy) {

So I think the two have gotten a bit mixed on your first line there.


#3

Much thanks …I think the description of the “function” inside the CodeCombat needs to be changed to reflect that self.functionName(param) = function: does not work to create a new method or function with respect to self. :smile: The things you learn…


#4

Oops, you’re right! Fixed now, thanks.


#5

I love especially that I never actually checked if my code is syntactically correct. It just came with the flow. If I would use all the snippets I produce for the forum in CodeCombat I might even have solved all levels by now.