Collision Detection - SOLVED

Started by Kinoko, Tue 29/06/2004 04:21:40

Previous topic - Next topic

Kinoko

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

  // 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...

Kweepa

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.
Still waiting for Purity of the Surf II

Kinoko

Good point, but I get an 'undefined token' error for 'on_key_press'...

SSH

That's because it's a function you write, not a function you call...
12

Kinoko

Apologies for my ignorance, but how do I use it, then?

Jet Kobayashi Zala

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.

Kinoko

#6
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?

Gilbert

I think that'll not cause any problems. I did this all the time, rearranging the order of functions to suit my needs.

Jet Kobayashi Zala

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.

SMF spam blocked by CleanTalk