olistic / warriorjs

🏰 An exciting game of programming and Artificial Intelligence
https://warriorjs.com
MIT License
9.41k stars 488 forks source link

Can't access functions from a Unit object #256

Closed akhercha closed 3 years ago

akhercha commented 3 years ago

Environment

On the https://warriorjs.com/ website : I was trying your game and I was faced with a problem that I can't solve. I think it's not from my code but if it is (or anything else that I missed...), sorry for the inconvenience!

Steps to reproduce

Tick, Tick... Boom! campaign, level 2, test the following code. The specific lines that do not work are in the getClosestEnemyDirection function:

const blockAtDirection = warrior.feel(direction);
const unitAtBlock = blockAtDirection.getUnit();
warrior.think(unitAtBlock);
// warrior.think(unitAtBlock.isBound());
...

Expected Behavior

Here, when I remove the comments tag from the line

warrior.think(unitAtBlock.isBound());

I should see the returned value from the isBound method but I got an error saying that unitAtBlock is undefined (while just below - see Actual Behavior section - we can see that this object exists and contains functions.).

The same thing happens when I try this :

warrior.think(warrior.feel(direction).getUnit().isBound());

Actual Behavior

image

unitAtBlock Unit object is suddenly undefined and I can't access its functions.