microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
473 stars 200 forks source link

Python code editor saying code that works in blocks is an error. #6413

Open Randompythoncoder13 opened 1 month ago

Randompythoncoder13 commented 1 month ago

I'm making a game and use both python and blocks. I made a function in blocks that when called with a sprite it will loop through all the enemies and find the closest one with a custom distance function. Once it finishes looping it will have the sprite follow the closest enemy. When I switched into python it says that there is an error in the function and that "types not compatible: number and Sprite". At first, I just ignored it but when trying to switch back to blocks it says that it is incompatible, and I must undo all my changes to enter blocks mode. After I do that and reenter python the same error is still there.

This is my python code causing the error: def Distance(entity1: Sprite, entity2: Sprite): return Math.round(Math.sqrt(abs(entity1.x - entity2.x) 2 + abs(entity1.x - entity2.x) 2)) def Tick(entity: Sprite): global target_dis, target target_dis = 200 target = 0 for targets in sprites.all_of_kind(SpriteKind.enemy): if Distance(entity, targets) < target_dis: target_dis += Distance(entity, targets) target += targets if target != 0: entity.follow(target)

The exact line it dislikes is entity.follow(target) (specifically target which I hover over and get: "types not compatible: number and Sprite").

It functions as it should in blocks mode but I believe the way the python interpreter is setup sees this as a bug and thinks it won't translate back to blocks.

OS: Windows 11 Using the app from Microsoft Store. MakeCode Version: 8.5.63 Arcade Version: 1.12.51