One mouse mode interaction walking problem!

Started by Duckbutcher, Tue 13/02/2018 14:12:35

Previous topic - Next topic

Duckbutcher

Hi guys, hope you can help me out!

I'm making a quick game for a friend, using an adaptation of the sierra template that comes with AGS 3.4 and wanted to really strip out all the interactions and have one mouse click handle everything. Initially I simply disabled everything except the walk function and thought I'd put all the interactions with hotspots, objects and characters into anyclick script and use conditionals to check if an item is being used and so on.

I then discovered that the walk mode doesn't appear to use the anyclick script and is its own entity, so ended up keeping interact, so I now have two mouse modes which I can swap between using a right click.

However, I wanted to have the inventory open with a right click and had really got myself set on just having one interaction mode, so I attempted to have the interact function also walk the character. I put a command in game_start forcing the cursor to interact mode (essentially disabling the walk mode) and tried this in the global script:

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) {
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode); 
    player.Walk(mouse.x,mouse.y, eNoBlock, eWalkableAreas);
    
  }


Initially it seemed fine - the cursor still interacts with my hotspots, and the character seemed to walk around, like I intended. However, something a little odd happens - the character walks fine in one direction, follows my clicks to the pixel, but if I turn the other direction, the character refuses to walk. He just takes a couple of half steps and won't go any further. He even walks in the opposite direction from my click! I've checked my walkable areas and they're all fine, tried starting him in a different room, and even returned the script to its previous state and the problem disappeared. One thing I noticed is that this only seems to happen in scrolling rooms. Is there something obvious I'm missing? Let me know if you have any ideas! Thanks guys.

Khris

#1
You're passing screen coordinates into a function that expects room coordinates.

I'd also modify the code slightly:
Code: ags
  else if (button == eMouseLeft) {
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) 
      player.Walk(mouse.x + GetViewportX(), mouse.y + GetViewportY()); // eNoBlock, eWalkableAreas are the default values
    else Room.ProcessClick(mouse.x, mouse.y, mouse.Mode); 
  }

Duckbutcher

Thanks a bunch, it's working great now. Cheers!

SMF spam blocked by CleanTalk