Fatal Error genarated with while function (SOLVED)

Started by Akumayo, Sun 12/02/2006 18:53:13

Previous topic - Next topic

Akumayo

I have the following while function in a room's repeatedly_excecute script:
Code: ags

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:
Code: ags

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


Thank you for any help you can offer.
"Power is not a means - it is an end."

GarageGothic

Do you actually have 299 characters? Otherwise, you could insert Game.CharacterCount instead of 299. Not sure if this is related to the problem.

Akumayo

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.
"Power is not a means - it is an end."

Ashen

GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0) should do it (I think Game.CharacterCount is only in the newest beta).
I know what you're thinking ... Don't think that.

Akumayo

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?!

Code: ags

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.
"Power is not a means - it is an end."

GarageGothic

#5
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.

Ashen

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.
I know what you're thinking ... Don't think that.

Akumayo

That was indeed the problem Ashen!  Thank you both for your help.  I appreciate it to a great degree!
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk