One Cursor, Multiple Operations (SOLVED)

Started by DazJ, Mon 21/07/2008 14:22:55

Previous topic - Next topic

DazJ

I've searched on the forums for an answer for this and there are some. However, these date back to 2004 and 2005 so the scripting is obsolete and any attempt by myself to recode it in the latest language failed miserably.

When the player left-clicks I want to make my character WALK around the screen as normal but I also want it to INTERACT with objects too when I left-click on a hotspot/object.

When the player right-clicks on the mouse I want it to either LOOK/TALK to objects/characters/hotspots.

Can anybody offer any advice on this please?


Matti

Where is the problem?

Just always use "any click" on the objects/hotspots/characters and then script something for the two possibilities left and right mouseclick.

DazJ

But the Walk cursor won't interact with anything, the character just walks over to it.

Matti

#3
Ah, right, sorry.

An idea would be to use the interaction-cursor instead of the walk-cursor and put in the rep-ex-section of the main script something like cEgo.walkto(mouse.x,mouse.y). I don't know if this is going to work, but it just came to my mind...


Edit: Well I guess then there would be a problem when clicking on a hotspot/object.

Edit 2: Ah, and of course there need to be an if-statement like

if (mouse.IsButtonDown(eMouseLeft)) before the walk.to command.


But I better shut up since I'm not quite familiar with these cursorthings...

DazJ

LOL thanks matti I appreciate the help...anyone else have any ideas?

OneDollar

#5
Here's the code I used in my game, which had the same control method (written in AGS 3.0):
Code: ags

function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {

  if (IsGamePaused() == 1){
    //Game is paused, so do nothing on any mouse click
  }else{
    if (button == eMouseLeft){
      //left mouse button
      if (GetLocationType(mouse.x, mouse.y) == eLocationNothing){
        //not over hotspot so walk
        ProcessClick(mouse.x, mouse.y, eModeWalkto);
      }else{
        //over a hotspot/object etc
        if (mouse.Mode==eModeUseinv){
          //using inventory on hotspot
          ProcessClick(mouse.x, mouse.y, eModeUseinv);
        }else{
          //not using inventory, so interact
          ProcessClick(mouse.x, mouse.y, eModeInteract);
        }
      }  
    }else if (button == eMouseRight){
      //right mouse button
      if (mouse.Mode==eModeUseinv){
        //inventory item out, so cancel it
        mouse.Mode=eModeInteract;
      }else{
        //no inventory item out, so look
        ProcessClick(mouse.x, mouse.y, eModeLookat);
      }
    }else if (button == eMouseWheelNorth){
      //mouse wheel up
    }else if (button == eMouseWheelSouth){
      //mouse wheel down
    }
  }

}


Essentially you just need to perform a check to see if your mouse is over something or not before deciding whether to use or walk. There's also a bit extra in there for handling inventory items. If you need anything explaining further just ask

DazJ

Cheers OneDollar. I've imported the code but the character won't walk at all. He's interact with things yes but he won't walk.

Khris

Debugging 101:

Code: ags
        //not over hotspot so walk
        Display("walk");
        ProcessClick(mouse.x, mouse.y, eModeWalkto);


Also make sure you did draw walkable areas (not walkbehinds or regions).

OneDollar

EDIT: Khris got in first with a very similar post ;)

That's... odd. I replaced it with the on_mouse_click code in the default game template and it works fine, so unless I've overlooked something vital you're down to checking that your character is on walkable areas and so on.

Standard debugging practice: try putting the line
player.Say("I should start walking");
just before the
ProcessClick(mouse.x, mouse.y, eModeWalkto);
line to check that the if functions are working properly, and make sure that the character says that line when you think he should start walking. If that happens its most likely a walkable areas issue, because ProcessClick(mouse.x, mouse.y, eModeWalkto); is pretty much the AGS default walk to control.

DazJ

#9
Now I DO have a problem and I don't know what the hell it is.

I noticed that the character wouldn't walk anymore and couldn't fix this so I reverted back to the original code that comes with AGS:

Code: ags

function on_mouse_click(MouseButton 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 == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );


and the character STILL won't move. He IS on a walkable area. I've set him up on different coordinates but he still won't move. The cursor is the WALK cursor but he just won't budge.

EDIT: SOLVED THIS PROBLEM.

DazJ

I've replaced the code again with the code you gave me and it works seemlessly! THANKYOU!

OneDollar

Glad to hear it. Can't think what would have been going wrong before

Khris

Just for reference, could you post how you solved the problem?

DazJ

For some reason the 'Automatically move the player in Walk Mode' option on the General Settings tab had been unchecked, God knows how. Once that was checked, the code that OneDollar provided worked an absolute treat.

Again, thankyou everyone for your help.

SMF spam blocked by CleanTalk