Re: help with a strange runtime in bgt

Well, that code doesn't seem to be enough, I guess there is actually a loop ment to run around this code, so without that one we cannot help you. If its a for loop, manually removing entries from an array will end you up accessing higher indices which don't exist anymore and skipping earlier ones, but thats just me guessing what might be wrong here.
I'll try to explain my thoughts to you. Lets just say your array has 10 entries right now, and thus you run a for loop from 0 to 9. Now, while i is 0, your code kicks in. Your first if is correct, thus the sound plays and the variable with index 0 is removed from your array, its now 9 items large, ranging from index 0 to 8, but your loop will still run from 0 to 9. Now, your loop continues and will check your 1'st entry. Note that that already skipped one entry, entry 0, the former entry 1, because you deleted the 0th entry, thus making entry 1 become entry 0. Even if your if-clauses now will always not be true, as soon as i becomes 9, you'll encounter a runtime error, because an item with i = 9 doesn't exist anymore within your array, because the largest one is now 8.
TL;DR: Loops reducing the array's size are usually done by using do-while-loops incrementing the index manually, something like:

int[] arr={0,1,2,3,4,5,6,7,8,9,10};
i = 0;
do
{
  if(arr[i] == 0)
  {
    arr.remove_at(i);
    continue;
  }
  i++;
}
while(i < arr.length());

Best Regards.
Hijacker



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : audiogame via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ironcross32 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : rory-games via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector

Reply via email to