Someone knows how to USE A FOR LOOP? Ah, dinosaur of old coding practices.
No, seriously. I am now honestly convinced that MARBLE MAN does not know how to use a for loop or even what that is. And no, this isn't some old mod that he made way back when he just started scripting, this is code STRAIGHT OUT of his 102nd mod. Recycled from his 49th, but at least I look over old code before flat-out copy pasting it. Clearly a waste of time, though, for one so busy as MARBLE THE GOD OF TRIVIAL MODS.
function RCCar_Cleanup(%i)
{
if(!isObject(RCBotGroup))
return;
if(RCBotGroup.getCount() > 0)
{
RCBotGroup.getObject(0).kill();
RCBotGroup.remove(RCBotGroup.getObject(0));
}
else
return;
if(%i>=24)
return schedule(16,0,RCCar_Cleanup);
return RCCar_Cleanup(%i++);
}
I could rewrite this code as a much cleaner function, as shown below.
function RCCar_Cleanup()
{
if(!isObject(RCBotGroup) || (%count = RCBotGroup.getCount()) == 0) return;
for(%i = %count - 1; %i >= 0; %i--)
{
(%bot = RCBotGroup.getObject(%i)).kill();
RCBotGroup.remove(%bot);
}
}
This function only calls RCBotGroup::getCount once, only calls RCBotGroup::getObject once per object, doesn't require a ton of unnecessary recursive function calls, and doesn't use any unnecessary schedules. In other words, it's THE PROPER WAY TO DO IT.
But you know what, the general public CAN'T be wrong. I must just not know how it's done. Who the forget needs efficient function calls and better looping of sets of objects?
I mean, it's not like we're using an engine where every optimization a mod makes counts, right?
Also, I was divided between putting this here or in Modification Discussion. In the end I decided this fit better since it's really a rant about a user.