Process Click

Started by Alynn, Thu 08/01/2004 13:51:37

Previous topic - Next topic

Alynn

And here is my process_click
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 ((GetCursorMode()==0) && (GetHotspotAt(mouse.x, mouse.y) == 0)){
      MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
    }
    else {
      ProcessClick(mouse.x, mouse.y, GetCursorMode());
    }
  }
  else {   // right-click, so cycle cursor
    if ((character[0].room != 1) || (IsGUIOn(4)==1)){
      SetNextCursorMode();
    }
  }
}


The part I'm most concerned with is the button==LEFT code block The first part checks if it is in walk mode, that worked fine unless the hotspot reacted to walking (like walking between the upstairs and downstairs floors on a certain room). So, I added the second part which checks if the mouse is over a hotspot. The downside to doing it this way is by clicking walk on anything that is a hotspot and no interaction for it, it does nothing.

I've tried different ways, but nothing seems to give me the best of both worlds (unless I really want to add a moveCharacter command to EVERY hotspot, which I really don't want to).

Just putting this out there in case anyone else can think of something that I haven't already :)

Barcik

I don't quite understand. What is the problem with the hotspot reacting to walking? And can you please explain in-depth about your problem, as I don't really see it.
Currently Working On: Monkey Island 1.5

Scorpiorus

I'm not sure about the problem as well, but in case you mean he doesn't walk to hotspot check if you ticked Don't automaticaly move character in Walk mode option. Or is it something else?

Ishmael

Have you tried:

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 ((GetCursorMode()==0) && (GetHotspotAt(mouse.x, mouse.y) == 0)){
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}
else if (GetCursorMode()==0) {
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}

else {
ProcessClick(mouse.x, mouse.y, GetCursorMode());
}
}
else { // right-click, so cycle cursor
if ((character[0].room != 1) || (IsGUIOn(4)==1)){
SetNextCursorMode();
}
}
}
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Alynn

Quote from: TK on Thu 08/01/2004 19:27:17
Have you tried:

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 ((GetCursorMode()==0) && (GetHotspotAt(mouse.x, mouse.y) == 0)){
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}
else if (GetCursorMode()==0) {
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}

else {
ProcessClick(mouse.x, mouse.y, GetCursorMode());
}
}
else { // right-click, so cycle cursor
if ((character[0].room != 1) || (IsGUIOn(4)==1)){
SetNextCursorMode();
}
}
}

Unfortunitly, I have tried that, and it doesn't work because hotspots that do react to MODE_WALK wont fire with that code. For those of you that are unsure of what I mean, I have some hotspots that react to MODE_WALK mostly to do with rooms that have multiple floors. The reason for this is because it makes more sense to me to walk to the upper floor and not interact with the upper floor to move upstairs. The game is set to Don't automaticly move character, which is why I have the setup I do (otherwise it ignores the hotspot code that reacts to MODE_WALK). Here is one of the hotspots that reacts to walk mode (under any click on hotspot)

Code: ags

if (GetCursorMode()==0) {
    MoveCharacterBlocking(0, 210, 160, 0);
    MoveCharacterBlocking(0, 190, 160, 0);
    MoveCharacterBlocking(0, 75, 65, 1);
    FaceLocation(0, character[0].x, character[0].y + 10);
    DisableHotspot(1);
    EnableHotspot(2);
    SetWalkBehindBase(4, 40);
    upstairs = 1;
  }


This basicly moved the character to the correct location at the foot of the stairs then moves them up the stairs, after that moves the baseline for the second floor walkbehind so the character now appears to be walking on the floor, then disables the walk up hotspot, and enables the walk downstairs hotspot.

The only work around I see at this point is adding a if (GetCursorMode()==0) MoveCharacter(blahblahblah), which I would have to do for EVERY hotspot...

I'm beginning to think that probably I need to add it to unhandled event, but I didn't see anything that had to do with walk mode in unhandled event. The other though I thought of but haven't tried yet is setting the rooms that have hotspots that react to MODE_WALK have its own on mouse click funtion that has a ClaimEvent() function to it...

Any more thoughts?

Wolfgang Abenteuer

Do you mean you need it to walk to given coordinates when the WALK icon is clicked on a certain hotspot, rather than simply walking to mouse.x, mouse.y?  If it were me, what I'd do is make another separate cursor mode (one of the custom ones) and then have the cursor mode change to that when you move the mouse over one of those hotspots that are supposed to react to the walk cursor.  You could even use the same graphic as you do for the walk cursor.  Using the walk icon for interactions other than simply walking has always been a bit difficult for me to do, so I've found it easier to just use a new cursor mode and change the hotspot interaction to the "Any click on hotspot", then specify the given cursor mode (just use the if (GetCursorMode() == #) { line at the beginning of the "Any click" interaction to rule out the other cursor modes).  That way, the walk icon will work like normal, and the custom cursor mode can handle everything else.

That may be backtracking a bit, though, but I guess I'm not quite sure what you need the Walk icon to do differently than it normally does. *shrugs*

~Wolfgang

Scorpiorus

hmm, to be honest, I still can't get what the trouble is. You have a hotspot, so when you click on it in walk mode the character is supposed to go upstairs, correct? You said you don't want to write that code for each hotspot, but you only need to write the code for certain hotspots that react in that special way. Can you clarify it a bit more please? :P

Alynn

The problem lies on other hotspots than those, when you click on them he does nothing. I would like the standard (Walk to the nearest coord to that spot) unless you guys thing that really wont bother too many people... So for every other hotspot, I would have to add a if (GetCursorMode()==0) MoveCharacter(so on and so forth), I'm trying to avoid that.

I'm just looking at that it may annoy some people that if they happen to be over a hotspot and click he wont walk and they will generally get annoyed with that... but if you guys think it's not going to make that much difference then I wont worry about it...

Proskrito

#8
what about using something like 'if (IsInteractionAvailable(mouse.x,mouse.y,GetCursorMode() ) )' to see if there is any interaction available for the current cursor mode?or maybe using properties for those special hotspots?
(that is, if i understood it correctly ) ;)
EDIT: oh, you want it only for walk interaction, right? then forget about the first one...

EDIT 2: OR you could fake a 'walk to' mode that acts like the talk or look one: (if you have cursor mode 8 or 9 free)
What i did for it is using cursor mode 9 as 'Walk to' mode, so you should disable the real one.
Then, in the on_mouse_click function, put something like:
Code: ags

if (button==LEFT){
if (GetCursorMode()==9){
  if (IsInteractionAvailable(mouse.x,mouse.y,9) ) ProcessClick(mouse.x, mouse.y,9);
 else ProccesClick(mouse.x,mouse.y,MODE_WALK);
}
...
} else if (button....

then instead of 'SetCursorMode(0)' you should write 9.
oh, and then change the name of the cursor 9 from 'Usemode2' to 'Walk to', and in the interaction editor you'll see a nice 'Walk to hotspot' interaction, that if you set some command to it, it will do that, and if you dont, it will just act like the default walk to mode  :) ;)

Scorpiorus

#9
Quote from: Alynn on Thu 08/01/2004 22:30:01
The problem lies on other hotspots than those, when you click on them he does nothing. I would like the standard (Walk to the nearest coord to that spot) unless you guys thing that really wont bother too many people... So for every other hotspot, I would have to add a if (GetCursorMode()==0) MoveCharacter(so on and so forth), I'm trying to avoid that.

I'm just looking at that it may annoy some people that if they happen to be over a hotspot and click he wont walk and they will generally get annoyed with that... but if you guys think it's not going to make that much difference then I wont worry about it...
Aha, got it, now it makes sense to me.
Try the next script. I'm not sure about it is exactly what you want but anyway:

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 ((GetCursorMode()==0) && (GetHotspotAt(mouse.x, mouse.y) == 0)){
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}
else {
 
      int hotspot = GetHotspotAt(mouse.x, mouse.y);
      int pointX  = GetHotspotPointX(hotspot);
      int pointY  = GetHotspotPointY(hotspot);
   //give player a command to start a move...
   if (GetCursorMode() == MODE_WALK) {     
      if (pointX != -1) MoveCharacter(0, pointX, pointY);
      else MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
   }

   //override moving with another action  
      ProcessClick(mouse.x, mouse.y, GetCursorMode());

   }
[/color]
}
else { // right-click, so cycle cursor
if ((character[ 0 ].room != 1) || (IsGUIOn(4)==1)){
SetNextCursorMode();
}
}
}

EDIT: to add comments & some modifications

~Cheers

Alynn

#10
Scorpiorus, as they say in the Guiness Commercials

"BRILLIANT!"

It worked perfectly... It took me reading the script 2 times to wrap my head around what you did, but when it finally made sense I'm amazed... I gotta get better with this API (well maybe its more an ASI)...

That would have just never occured to me to walk it to the spot then process the click (which happens so fast that if there was an interaction the walk gets overrode)....

Damn... and I call myself a programmer... (well I'm paid to be one but I cant code AGS :()

Edit: Well I CAN, I just miss simple things like that :(

Scorpiorus

I'm glad you found it working as it should. :)

QuoteThat would have just never occured to me to walk it to the spot then process the click (which happens so fast that if there was an interaction the walk gets overrode)....
In fact, the move isn't even started then (because AGS moves character only when all scripts are finished). I just messed with the emulation of MoveCharacter command some time ago and investigated the work of built-in move command quite well.

Also, I just looked at the script again and realized that
Quoteif ((GetCursorMode()==0) && (GetHotspotAt(mouse.x, mouse.y) == 0)){
MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}
can be removed as its job is done by else MoveCharacter(0, GetViewportX()+mouse.x, GetViewportY()+mouse.y);

~Cheers

Alynn

Again beautiful work... now it makes more sense to me that that other crappy code I wrote went away...

* Alynn does the happy dance of LOVE.

SMF spam blocked by CleanTalk