ProcessClick function not working (SOLVED)

Started by rtf, Sun 25/07/2004 05:28:05

Previous topic - Next topic

rtf

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?
I fail at art.

Gilbert

;) 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)){

Sektor 13

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?

Sektor 13

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 ! ?

Ashen

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

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.

Code: ags

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.
I know what you're thinking ... Don't think that.

Sektor 13

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

Ashen

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.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk