Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Bug in Backwoods Forest: Leave it to Cleaver

Hi, I was playing with my wife and I realized that this code was wrong. We are using an enemy variable inside the function, but this variable doesn’t exist in the function scope, should be target. But it worked. Then it’s a bug.

The map is in Backwoods Forest world, and the map is Leave it to Cleaver

Thanks,

Jordi.

Howdy and welcome to the forum folks!

Jordi, are you not passing the variable ‘enemy’ to the function via line 15 “cleaveWhenClose(enemy)”? The function is written to accept a single variable, which happens to be named ‘target’ in this case…the odd name might be confusing, but this practice allows calling this function from other lines of code, or even other functions, where a specific name may not necessarily apply. This is especially handy if you have a cause to reuse this function code in a new level (program).