Hot Spots don't always register clicks [SOLVED]

Started by , Fri 07/01/2005 20:28:30

Previous topic - Next topic

flangard

Hello everyone!

I'm new to AGS, and I've been experimenting with it for a few days to see if it's the right adventure maker for me. So far it seems great, except for one bug (?) that troubles me. I've searched the manual (but not read it completely), the FAQs and the forums, but didn't find anything about it.

The problem is this: Half of the times when I try to interact with Hot Spots or objects, the game doesn't register the click, as if the object weren't there. My character just walks near the point I clicked, but nothing else happens. This occurs whenever there's any actions associated with the Hot Spot or object, like picking it up. Half of the time it doesn't work and I have to click a few times to make anything happen. This might get really annoying in the long run. Clicking always works fine when I only want to Look At my target, though.

Is this a common "feature", or is it just me? In case it matters, I'm using the ARARCOST template, which simplifies the GUI to only two mouse buttons (left for interacting, right for looking).

I'd be grateful for any ideas on how to fix this.

(I hope this message was legible, for English isn't my native language. :))

flangard

Sorry, forgot to mention: I'm using the version "2.62 November 2004" of AGS.

Candle

Try making the hotspots a litttle bigger .

strazer

It's possible the GUI template you use internally switches cursor modes but uses the same cursor graphic for all of them.
If you click on something in Walk mode, nothing will happen. Interactions are only triggered by the other cursor modes.

flangard

Thanks for the answers!

Candle, I think the hotspots are well big enough. I'm not missing them by accident, I'm sure of that. :)

strazer, Is that so? I don't understand anything about scripting yet, but I found this block of code. I think this might be what was added by the template:

Code: ags
#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(int button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  
Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  }
Ã,  else if (button==LEFT) {
Ã,  Ã,  Ã,  if (overhotspot == 1){
Ã,  Ã,  Ã,  if (GetCursorMode() == MODE_USE){
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, MODE_USE);
Ã,  Ã,  Ã, }
Ã,  Ã, else if(GetCursorMode() == 4){
Ã,  Ã,  Ã, ProcessClick(mouse.x, mouse.y, 4);
Ã,  Ã,  Ã, SetCursorMode(MODE_USE);
Ã,  Ã,  Ã, }
Ã,  
Ã,  Ã, }
Ã,  Ã, else if(overhotspot == 0){ 
Ã,  Ã,  Ã, ProcessClick(mouse.x, mouse.y, MODE_WALK);
Ã,  Ã,  Ã, }
Ã,  }
Ã,  else if (button==RIGHT) { 
Ã,  Ã, if(GetCursorMode() == 4){
Ã,  Ã,  Ã, SetCursorMode(MODE_USE);
Ã,  Ã,  Ã, }
Ã,  Ã, else{
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, MODE_LOOK);
Ã,  Ã,  }
Ã,  }
Ã,  }
#sectionend on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE


Since I'm guite the newbie, I can't say if there's anything wrong with the code, or even if it's the right piece of code. Does that look right? Can anyone tell me if something can be done with it to make it work better?

strazer

#5
The problem could be that the variable "overhotspot" isn't updated correctly.
Could you please post the contents of your repeatedly_execute function? I suspect it's there that overhotspot is assigned its value.

Edit:

Btw, you should update the code with proper indentation to make it more readable:

Code: ags

function on_mouse_click(int button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button==LEFT) {
    if (overhotspot == 1) {
      if (GetCursorMode() == MODE_USE) {
        ProcessClick(mouse.x, mouse.y, MODE_USE);
      }
      else if(GetCursorMode() == MODE_USEINV) {
        ProcessClick(mouse.x, mouse.y, MODE_USEINV);
        SetCursorMode(MODE_USE);
      }
    }
    else if(overhotspot == 0) {
      ProcessClick(mouse.x, mouse.y, MODE_WALK);
    }
  }
  else if (button==RIGHT) {
    if(GetCursorMode() == MODE_USEINV) {
      SetCursorMode(MODE_USE);
    }
    else {
      ProcessClick(mouse.x, mouse.y, MODE_LOOK);
    }
  }

}

flangard

Here:

Code: ags
#sectionstart repeatedly_executeÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
Ã,  // put anything you want to happen every game cycle here
Ã,  
Ã,  //For this, I made it so that whenever the the mouse is hovering over a hotspot, object, or character, 
Ã,  //a variable (overhotspot) will be set to "1".Ã,  That way, I can use an IF statement later on under
Ã,  //on_mouse_click. Man, I am such a genius.
Ã,  
Ã,  Ã, if ((overhotspot == 0) && (GetHotspotAt(mouse.x, mouse.y)) || (GetCharacterAt(mouse.x, mouse.y)>=0) || (GetObjectAt(mouse.x, mouse.y)>=0)){ //If the mouse is hovering over something...
Ã,  Ã,  overhotspot = 1; //Then the variable is set to one.
Ã,  Ã,  }
Ã,  else{ //If the mouse isn't hovering over something...
Ã,  Ã,  overhotspot = 0; //I think you get the idea.
Ã,  }
}
#sectionend repeatedly_executeÃ,  // DO NOT EDIT OR REMOVE THIS LINE

strazer

#7
(removed)

I think the if-clause is missing two brackets, so the logic gets screwed up:

if ((overhotspot == 0) && ((GetHotspotAt(mouse.x, mouse.y)) || (GetCharacterAt(mouse.x, mouse.y)>=0) || (GetObjectAt(mouse.x, mouse.y)>=0))) { //If the mouse is hovering over something...

flangard

Thanks, strazer, but that didn't seem to help.

Well, perhaps it's my imagination, but that _may_ have increased the success ratio by 1/3 or something. Meaning the clicks register a bit more often now, but still fail regulary. Then again, that's more likely just a coincidence.

Any other ideas? Or perhaps even links to other templates for the same kind of two-button-gui?

strazer

Then maybe try this after all:

Code: ags

if ((GetHotspotAt(mouse.x, mouse.y)) || (GetCharacterAt(mouse.x, mouse.y)>=0) || (GetObjectAt(mouse.x, mouse.y)>=0)) { //If the mouse is hovering over something...
    overhotspot = 1; //Then the variable is set to one.
    }
  else{ //If the mouse isn't hovering over something...
    overhotspot = 0; //I think you get the idea.
  }

flangard

Wow, that worked! Everything runs smoothly now, thank you very much for your effort. Now I can continue making my game with my mind at ease. :)

I think I'll mail a link to this thread to the maker of the the ARARCOST template, when I have the time. But now I gotta go.

Thanks again!


monkey0506

BTW, just so you understand WHY it works, and not just THAT it works:

You had:

Code: ags
if ((((((((((/*yes, I'm exaggerating*/overhotspot == 0/*stuff*/)))))))))) {
 Ã, overhotspot = 1;
 Ã, }
else { // if overhotspot == 1, even if it's still over a hotspot, set it to 0
 Ã, overhotspot = 0;
 Ã, }
 Ã, }


If you see what I commented, if overhotspot was already set to 1, then it was automatically set to 0, even if it's still over a hotspot. Then, it had to wait till the next time the loop was run (the next game loop) to set it back to 1 if the cursor is still over a hotspot. This is why you were having problems. repeatedly_execute() was struggling back and forth every game loop to try and figure out what the correct value is. By removing the "overhotspot == 0" parameter from the if statement, you only set overhotspot to 0 if the cursor is not over a hotspot, thus removing the struggle in repeatedly execute (yes, I'm trying to be funny. I know, it's not working). Anyways, when you removed that parameter, overhotspot is not changed as much (i.e. it's only changed once a game loop if the cursor has moved on/off of a hotspot) so that's why it now works. I hope you got something out of this senseless babbling. ???

SMF spam blocked by CleanTalk