Help! I'm trying to get the script to make the left click work as a walk_to mode, and the right click as interact mode. But no matter what I write it won't accept it.
Could anyone explain it to me like I was a very, very dense person?
There are two ways to go about this.
The regular way is to just change the mouse Mode. Changing the mode effects how the game responds to a mouse click.
Using AGS v2.7 beta:
ex:
mouse.Mode = eModeInteract;
Other modes are: eModeLookat, eModePickup, eModePointer, eModeTalkTo, eModeUseInv, eModeWait, eModeWalkto
If you are in eModeWalkto, then left clicking will cause the character to walk to that position.
However, you could script this yourself....for example, by using this code in the on_mouse_click function:
character[player.ID].Walk(mouse.x, mmouse.y, eNoBlock, eWalkableAreas);
player.ID = character that the player is controlling
mouse.x = current x position of the mouse...
eNoBlock = game is not locked while walking
eWalkableAreas = character will only walk over walkable areas
To have the right click interact with an object on the screen, you could go to the Interaction of an object (in the room editor) and put script in the "any click on object"...and check to see if it was a right click
if (button == eMouseRightInv) {
ProcessClick(mouse.x, mouse.y,eModeLookat);
}
this code is pretty obvious, it checks to see if you right clicked, then simulkated a click in eModeLookat on the object
your best bet is to keep it in eModeWalkto to handle the walking and then use script like this to control the right clicking on objects
so, you'll need to pu that on the script of every object
note: using older version of AGS where you don't have mouse.Mode, use SetCursorMode(). the code to make the character walk to a spot would also be a little different but since you don't need to code that if you leave it in eModeWalkto I won't go into that.
Right. Let's see. I'm kinda new here, so... I'm in the v. 2.62 (As far as I know, the only version that can be downloaded from here), and there's nothing about eModes, or eNoBlock.
There is not a single word that starts with "e" on the whole script.
My head hurts now. I gonna lay down for a while.
yep, notice the comment at the bottom of my post. you use a different function. however, the code you need which I just gave you is the same. the 2.7 version can be downloaded from a sticky thread in the technical forum (if you want), I can't tell you why it's not on the downloads section...that confused me for a long time too. it is technically a beta version.
Please, don't encourage others to use a un-released version unless you both know what you're doing.
Though V2.7 has reached prefinal stage and the changes should be stable now, it's still not a publicly announced version.
The short way, for 2.62:
Open up the Global Script, and find the on_mouse_click function. (Clicking it in the 'Script' drop-down menu will take you right there.) It should look something like:
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) {
ProcessClick(mouse.x, mouse.y, GetCursorMode() );
}
else { // right-click, so cycle cursor
SetNextCursorMode();
}
}
Change it to:
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) {
ProcessClick(mouse.x, mouse.y, MODE_WALK); // Left click = walk to
}
else { // right-click, so cycle cursor
ProcessClick(mouse.x, mouse.y, GetCursorMode()); //Right click = run interaction
// if you only use one interaction mode, you could change this to ProcessClick(mouse.x, mouse.y, MODE_USE);, or whatever mode you're using
}
}
You might need a way to change cursor modes, of course, but I assume you've taken care of that. Also, you won't need to have 'Walk To' as a cursor mode, 'cause that could get confusing.
Thanks, Ashen, that worked like a charm.
QuotePlease, don't encourage others to use a un-released version unless you both know what you're doing.
Though V2.7 has reached prefinal stage and the changes should be stable now, it's still not a publicly announced version.
I'm sorry that my recommendation does not coincide with yours, but I can't help recommending what I feel is a good option.