Here’s a quick short-cut to wrap up some boiler plate code you may write when trying to access elements of arrays. While we can’t chain accessors syntactically, we still can work around the issue in a fairly readable way still. A method I use is adding a function
arr(_array, _index) that simply returns the value in
Let’s say we’re resolving collision and we have an array of bullets that successfully hit their target, the player. We loop through
_bullets_hit, where each element is an
EBullet Array Object class. one member of
Damage, representing simply how much damage the target receives.
We want to call a hypothetical
This really just a short cut for writing:
Just incase you’re unfamiliar with
gml_pragma, I’m using it here with
forceinline since the
arr function is quite simple, and if we’re getting a ton of utilty out of it, compiling it inline will save us some cycles… we’re basically teling the compiler to paste the code wherever we call
arr, rather than call the function.