Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kinoko on Tue 29/06/2004 04:21:40

Title: Collision Detection - SOLVED
Post by: Kinoko on Tue 29/06/2004 04:21:40
Ref: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14770.0

I'm using the Collision Detector plugin and trying to get it to work when two characters are touching, and then a specific (X - number 88) button is pressed.

At the moment, it works fine. When two characters are touching and X is pushed, a TypeLine function is run. While the text window is displayed, any key will remove the window (as it should) but if you push X to remove it, the window will just come up again instantly. I understand that this is working because I have the code in the 'repeatedly execute' part of the room script, but I'm not sure what I should do to get it to work the way I want.

What I'd like is for, if the TypeLine text window is currently displayed, pressing X will remove the window but won't set off the CD function again. Effectively, I guess, the CD function is disabled if a text window is on screen.

Here's what I have in my room script:

  // script for room: Repeatedly execute
int ret = boundingBoxColDetect (EGO, CD_CHARACTER, 11, 75, KAYA, CD_CHARACTER, 28, 75); 
if ((ret == CD_COLLISION) && (IsKeyPressed(88))) {
 
  FaceCharacter (KAYA, EGO);
  TypeLine (505, 100, 50, 1, 12, 200, 0, -1);
 
}


EDIT: I tried adding a SetGlobalInt (0,1); and a SetGlobalInt(0,0); line into the TypeLine script in the global script and changing the above code to if ((ret == CD_COLLISION) && (IsKeyPressed(88)) && (GetGlobalInt(0) == 0)) {.

This worked if, when the text window appeared, I *ever-so-quickly* tapped the X button. If I pressed it the way a normal person would, it would still bring the text window up again. I added a Wait(5); after the SetGlobalInt (0,0); line and it works pretty well now.

So, it's effectively solved but I just want someone's seal of approval on this method ^_^ I don't know if this is a messy way of doing it, or if there's a much easier way... this is going to be a VERY commonly used code in my game so I don't want to screw it up.

EDIT: Also, is there some way I can do this without using "ret"? If I do it this way, I have to come up with a new variable for EVERY line of text in the game...
Title: Re: Collision Detection
Post by: Kweepa on Tue 29/06/2004 06:13:16
Perhaps rather than testing IsKeyPressed, you should have the check in the on_key_press event function. That way, it will only come up when the key is actually pressed, not held down.
Title: Re: Collision Detection
Post by: Kinoko on Tue 29/06/2004 15:28:59
Good point, but I get an 'undefined token' error for 'on_key_press'...
Title: Re: Collision Detection
Post by: SSH on Tue 29/06/2004 16:06:43
That's because it's a function you write, not a function you call...
Title: Re: Collision Detection
Post by: Kinoko on Wed 30/06/2004 12:07:49
Apologies for my ignorance, but how do I use it, then?
Title: Re: Collision Detection
Post by: Jet Kobayashi Zala on Thu 01/07/2004 20:45:21
Quote from: Kinoko on Wed 30/06/2004 12:07:49
Apologies for my ignorance, but how do I use it, then?

Ahh, allow me. It's under the script menu, actually.
Title: Re: Collision Detection
Post by: Kinoko on Fri 02/07/2004 02:28:17
Er, not quite what I meant but thanks. Sorry, there was a little communication error on my part.

If I put that code into the global script under "on_key_press", I get an error when trying to save the game because this code comes before the place in the global script where these functions are actually created. I've moved the whole on_key_press section to the bottom of the script, and it works fine, but will this cause problems later?
Title: Re: Collision Detection
Post by: Gilbert on Fri 02/07/2004 02:43:16
I think that'll not cause any problems. I did this all the time, rearranging the order of functions to suit my needs.
Title: Re: Collision Detection - SOLVED
Post by: Jet Kobayashi Zala on Fri 02/07/2004 08:45:47
Yeah, it shouldn't make a big dif. You could have also moved the functions up. I always put my global defines and custom functions at the very top before any of the editor's functions.