Challenge 3: Configurable Monkeys
Remember that one magic number in attack with: monkey
? The number 128 means nothing special - it's just a range value.
Well, it would be more useful if that range were intrinsic to the individual monkey. That way, you could have monkeys with different range values. And that way, you could have upgradeable units.
Your challenge is to implement this change. Make attack with: monkey
read a range value from the monkey, instead of using a magic number.
To do this, you will need to know about instance properties and keys.
Instance properties are properties that are set on individual objects, rather than on everything with that script. You can access instance properties by right-clicking on the object and selecting "instance properties". Initially you won't see anything, because there are no public properties.
To make a property public, go into the script. Click the burger menu and access the script properties. Here, you can check "Public" beside any property you want to see in instance properties. You can also set a default value.
When the object is created, its instance properties are already set. This means you can immediately use them.
Keys are pieces of data that are available to other objects. Use the Key section in the Events tab to add and read key blocks.
You should add a key called "range" to the When created
block of the monkey script, and set that key to an instance property. This will allow you to set range per monkey, and read it off in the attack with: monkey
script.
Good hunting!
Mastering this challenge indicates an excellent understanding of the radius and communicating information around a program.