Bug? Characters detected in rooms they aren't in.

Started by Kinoko, Wed 01/09/2004 04:39:00

Previous topic - Next topic

Kinoko

I've just noticed that some characters are being detected in rooms they don't exist in. This will happen in any room, even a newly created one.

I have 3 static characters in room 1, and one character (controlled by the Character Control System plugin) in room 6. In room 6, the 3 characters from room 1, even though they don't visually appear to be there, can still be interacted with. This really screws up with one of the interactions which includes a FaceCharacter line, which shuts the game down telling me the character isn't in the room.

It seems to be a bug/problem with the Collision Detector Plugin (v1.10) as all of these characters have collision detections assigned to them.  Has anyone else experienced this? The plugin hasn't been updated since 2002 so I guess it could be incompatible with current AGS versions... It's worked beautifully up til now so it's a pity.

Scorpiorus

Hmm, seems like its the CCS plugin conflicting with something. It by-design temporary move a controled character into the current room to perfom a walking. Any chance you can upload or send to me a game demonstrayting the problem?

Kinoko

I've zipped up the game files and uploaded them here:

http://www.anime.com.au/Katt/misc/bugtest.zip

This is all the bare essentials of the particular problem and I half expected it to go away... nope.

You can put EGO in room 2 or 3 and he can still (by pressing 'x' to interact) interact with the girls in room 1 by going to the same coordinates in any other room. If you go to the top (pink) girl, it'll crash because of the FaceCharacter line. The other two, you'll just get normal text window interactions.

I'm not sure if the Molerat interaction is still working in the 3rd room or not. It didn't for me but it's a much simper version of the proper code in my game (normally, if you go near him and contact, you'll do a little "injured" animation).

I don't think it's the CCS, I'm pretty positive its the Collision Detector. If I comment out the defining collision lines for a character, the glitch stop working for that character.

Scorpiorus

Ah, yeah this is how the Collision Detector (CD) plugin works. When checking for a collision it doesn't take into account whether characters are in the same room or not - that fact is transparent to it. It's not bug, I think, rather the way how it works, because the plugin actually checks sprites rather than their owners (characters or objects). It's even better because were it compare rooms it would surely use the character[].room variable using of which is not very compatible with the CCS plugin (there is a warning note about it in the CCS help file). It is that conflict I was talking about before.
So, all you need is to manually check characters' rooms with the CCS ccGetCharacterRoom function as it returns a correct room when a character is being controlled by the CCS.

Here is a function to replace the spriteSpriteColDetect calls with. It, of course, requires both the CD and CCS plugins to be enabled as it makes a use of their functions.

script header:
import function charCharColDetect(int CharID1, int CharID2);


main global script:
function charCharColDetect(int CharID1, int CharID2) {

   int slot1 = GetGameParameter(GP_FRAMEIMAGE, character[CharID1].view+1,

character[CharID1].loop, character[CharID1].frame);
   int slot2 = GetGameParameter(GP_FRAMEIMAGE, character[CharID2].view+1,

character[CharID2].loop, character[CharID2].frame);
   
   int room1;
   int room2;
   
   if (CharID1 != GetPlayerCharacter()) room1 = ccGetCharacterRoom(CharID1);
   else room1 = character[CharID1].room;
   if (CharID2 != GetPlayerCharacter()) room2 = ccGetCharacterRoom(CharID2);
   else room2 = character[CharID2].room;
   
   if (room1 == room2)
      return spriteSpriteColDetect(CharID1, CD_CHARACTER, slot1, CharID2, CD_CHARACTER,

slot2);
   else return CD_NO_COLLISION;
}

BTW, the CD plugin has a limitation where you have to pass sprite slots to its functions in order for the collision detection to be performed. At present, AGS has all means to retrieve the required sprite slots (possible even with scripting), therefore the charCharColDetect() function doesn't require you to pass them.

So, the related scripts can use charCharColDetect instead:

////////////////////////////// DEFINING COLLISIONS ///////////////////////
////////////////////////////// BORONIA RESIDENTS /////////////////////////
brynret = charCharColDetect(EGO, BRYN);
kayaret = charCharColDetect(EGO, KAYA);
maeretÃ,  = charCharColDetect(EGO, MAE);


///////////////////////////////// MONSTERS ///////////////////////////////
moleret2 = charCharColDetect(EGO, MOLERAT);
//////////////////////////////////////////////////////////////////////////

Kinoko

Ahhh, thanks. I didn't realise it worked that way...

Actually, I need to specify a sprite slot because I don't want pixel/pixel collision detection in most cases, rather say, for an interaction to take place when the characters feet are touching... or something like that. It would be fine if I had a purely top-down style game, but it's on an odd almost 45% angle, so it looks odd having interactions without the characters overlapping a bit :)

Given that... does the above code need to be changed?

Scorpiorus

Ah, I have just looked once more into the test game you had uploaded: sprite #62, you use it as a collision mask, I should have thought about that. :)

The code can be easily changed since it only requires to remove some lines and add two extra parameters:

script header:
import function charCharColDetectEx(int CharID1, int slot1, int CharID2, int slot2);


main global script:
function charCharColDetectEx(int CharID1, int slot1, int CharID2, int slot2) {

   int room1;
   int room2;
Ã,  Ã, 
   if (CharID1 != GetPlayerCharacter()) room1 = ccGetCharacterRoom(CharID1);
   else room1 = character[CharID1].room;
   if (CharID2 != GetPlayerCharacter()) room2 = ccGetCharacterRoom(CharID2);
   else room2 = character[CharID2].room;
Ã,  Ã, 
   if (room1 == room2) return spriteSpriteColDetect(CharID1, CD_CHARACTER, slot1, CharID2, CD_CHARACTER, slot2);
   else return CD_NO_COLLISION;
}

Kinoko


SMF spam blocked by CleanTalk