Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: rtf on Sun 25/07/2004 05:28:05

Title: ProcessClick function not working (SOLVED)
Post by: rtf on Sun 25/07/2004 05:28:05
Well, I was supposed to make this script for another forum member who needed help, but I guess I need some help too.  :P

It's a script for an interface like Perils of Poom.  (Left click on nothing: walk to.  Left Click on something: Interact.  Right click on anything: Look



int overhotspot;

__________________________________________

function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  if ((overhotspot == 0) && (GetHotspotAt(mouse.x, mouse.y)) || (GetCharacterAt(mouse.x, mouse.y)) || (GetObjectAt(mouse.x, mouse.y))){
//if the mouse is over a hotspot, object, or character

    overhotspot = 1;
    }
  else{ //if the mouse isn't over a hotspot, object, or character
    overhotspot = 0;
  }
}

function on_mouse_click(int button) {
  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); //This is what isn't working
     }
  }
  else if (button==RIGHT) {  //Look at the thing.
    ProcessClick(mouse.x, mouse.y, MODE_LOOK);
    }
  }



The problem is that when I left-click on nothing, where I'm supposed to walk, nothing happens.(if you were reading the comments, you'd be way ahead of me  ;)  ) 

Everything else works perfectly.

Help?
Title: Re: ProcessClick function not working.
Post by: Gilbert on Mon 26/07/2004 03:25:32
;) That's because character and object # start at 0, so, GetCharacterAt() and GetObjectAt() behave differently compared to GetHotspotAt(), that they  willreturn -1 instead of 0 if nothing was there (so overhotspot will still  become 1 when over nothing in your original code), so you should change it to:

if ((overhotspot == 0) && (GetHotspotAt(mouse.x, mouse.y)) || (GetCharacterAt(mouse.x, mouse.y)>=0) || (GetObjectAt(mouse.x, mouse.y)>=0)){
Title: Re: ProcessClick function not working.
Post by: Sektor 13 on Mon 21/02/2005 13:17:11
this kind of left and right mous click is awesome, there is just one problem, sometimes when you click on hotspot nothing happens, that can be several clicks until go you get desired action, and that is not very good  >:( is there any better solution?
Title: Re: ProcessClick function not working.
Post by: Sektor 13 on Mon 21/02/2005 13:42:35
hmm it works normal with character, but not with hotspot, a removed ...((overhotspot == 0) &&... from the code, and the clicks are normal, but character would't walk ! ?
Title: Re: ProcessClick function not working.
Post by: Ashen on Mon 21/02/2005 13:50:27
I'm not sure, but there might also be a problem with the 'or' functions in the rep_ex - at least, I usually get one when I use so many conditons, but that might just be me.
Anyway, couldn't you simplify it to:

function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  if ((overhotspot == 0) && (GetLocationType (mouse.x, mouse.y) != 0)){
  //if the mouse is over a hotspot, object, or character
    overhotspot = 1;
  }
  else { //if the mouse isn't over a hotspot, object, or character
    overhotspot = 0;
  }
}


In fact, you could probably just use GetLocationType in on_mouse-click, and skip the rep_ex bit completely.


function on_mouse_click(int button) {
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button==LEFT) {
    if (GetLocationType (mouse.x, mouse.y) != 0) { // if the mouse is over a hotspot, object, or character
      ProcessClick (mouse.x, mouse.y, GetCursorMode ());
      if (GetCursorMode () != MODE_USE) SetCursorMode (MODE_USE);
    }
    else ProcessClick (mouse.x, mouse.y, MODE_WALK); // if the mouse isn't over a hotspot, object, or character
  }
  else if (button==RIGHT) {  //Look at the thing.
    ProcessClick(mouse.x, mouse.y, MODE_LOOK);
  }
}

I've compressed the code a little as well, hope you don't mind. I tested it, and it works for me. If it doesn't work for you for some reason, or if I've got the wrong end of the stick, just ignore it.
Title: Re: ProcessClick function not working.
Post by: Sektor 13 on Tue 22/02/2005 10:20:41
Actually code belongs to  "releasethefrogs" he posted it, i was just using it,..

As for you code, Ashen, it works perfectly and its shorter, thank you..
Title: Re: ProcessClick function not working.
Post by: Ashen on Tue 22/02/2005 12:42:29
I knew that. Honest. When I said 'you', I meant 'the person using the code', it just looked like I meant you because yours was the last post. Yeah, that's it. Anyway, unless you're the 'other forum member who needed help', the code's for some third person anyway.

Whatever, glad I could help.