Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Akumayo on Sun 12/02/2006 18:53:13

Title: Fatal Error genarated with while function (SOLVED)
Post by: Akumayo on Sun 12/02/2006 18:53:13
I have the following while function in a room's repeatedly_excecute script:

int characterone = 0;
int charactertwo = 1;
while (characterone <= 299) {
  if (character[characterone].IsCollidingWithChar(character[charactertwo])) {
    character[characterone].x = ((Random(13) + 1) * 20);
    character[characterone].y = ((Random(6) + 1) * 20);
  }
  if (charactertwo != 299) {
    charactertwo ++;
  }
  else {
    characterone ++;
    charactertwo = 1;
  }



It, in theory, should check to see if any characters in the whole game are colliding, and if they are, will move one two a randomized position.  The problem is that it generates the following fatal error:

Quote
---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0042E0B7 ; program pointer is +6, ACI version 2.71.894, gtags (1,2)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.

in Room 9 script (line 402)


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.
---------------------------
OK   
---------------------------

NOTE:  Room 9 script line 402 is the following line from the while function above:

  if (character[characterone].IsCollidingWithChar(character[charactertwo])) {


Thank you for any help you can offer.
Title: Re: Fatal Error genarated with while function
Post by: GarageGothic on Sun 12/02/2006 20:18:37
Do you actually have 299 characters? Otherwise, you could insert Game.CharacterCount instead of 299. Not sure if this is related to the problem.
Title: Re: Fatal Error genarated with while function
Post by: Akumayo on Sun 12/02/2006 20:41:44
I'm sure that would fix it, but searching the manual I can't find "Game.CharacterCount" or it's equivalent.  I know there's a way to return the number of characters, but I can't find it.
Title: Re: Fatal Error genarated with while function
Post by: Ashen on Sun 12/02/2006 20:51:14
GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0) should do it (I think Game.CharacterCount is only in the newest beta).
Title: Re: Fatal Error genarated with while function
Post by: Akumayo on Sun 12/02/2006 21:01:29
Well, the error is no longer being generated thanks to Ashen's help... but... CHAOS errupts on my screen!  Every character in the room constantly re-organizes it's position to a new random location!  It's madness!!!  What's wrong with my script that makes them think they're always touching?!


int characterone = 7;
int charactertwo = 8;
while (characterone <= GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0)) {
  if (character[characterone].IsCollidingWithChar(character[charactertwo]) == 1) {
    character[characterone].x = (Random(xboundb - xbounda) + xbounda);
    character[characterone].y = ((Random(ybound / 20) + 1) * 20);
  }
  if (charactertwo != GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0)) {
    charactertwo ++;
}
  else {
   characterone ++;
    charactertwo = 8;
}



My my, my head hurts just from looking at that madness.
Title: Re: Fatal Error genarated with while function
Post by: GarageGothic on Sun 12/02/2006 21:19:43
Sorry about that, yeah I just had to replace all my GetGameParameter functions, so I didn't even consider that not everyone around here is a beta whore. You will need to change it if you update to the next version when it's released though.

Edit: Also, and I'm not entirely sure of this. But character numbering starts at zero, so could it be that it has to be GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0) - 1? It doesn't sound like that's the problem in this case though.
Title: Re: Fatal Error genarated with while function
Post by: Ashen on Sun 12/02/2006 21:30:15
Now that I've actually READ the code... Is it possible you're comparing a character with itself (e.g. characterone is 8, and so is charactertwo)? In which case they'll ALWAYS be overlapping, and always thrown around the screen.
Try adding a characterone != charactertwo check to the IsCollidingWithChar condition, and/or a few Display(..) commands to check the values.
Title: Re: Fatal Error genarated with while function
Post by: Akumayo on Sun 12/02/2006 21:49:24
That was indeed the problem Ashen!  Thank you both for your help.  I appreciate it to a great degree!