He was pointing me in the correct direction by showing me what to do and where I went wrong. I needed help, and he gave it. Yeah, we know Port's does it more efficiently, but Bluetooth was showing me how to do it the way that I did it originally.
Even if you consider the fact that the code gives
incorrect results...
It's still a really bad way to do it.
Think about it. Even if it were to give correct results.
You're looping through a group, using .getCount() to check if you counted them all, setting subcount to the loop count.
You don't need to loop till the loop count is the brick count when you already have a function that gives the count right in the loop function, that you're calling every single time you're resetting the subcount.
If you're going to do a manual count, and not use the method Port posted, here you go.
%total = 0; //Set the count to 0 for whatever reason. Probably not necessary.
%groupcount = MainBrickGroup.getCount(); //Get the count once. Inefficient to call this function each check.
for(%i = 0; %i < %groupcount; %i++) //Loop through all the brick groups.
%total+=MainBrickGroup.getObject(%i).getCount(); //Add the number of objects in each brick group.
echo(%total); //loving done.