Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Tue 16/09/2003 10:31:46

Title: Trouble with Gui and right clicking
Post by: on Tue 16/09/2003 10:31:46
Hi Im new to using Ags.

But already Ive had a problem ???
I plan to have a Sam and Max style Inventory system.  Ive drawn the pic and I was testing it out and I found that when i had it up I couldnt right click to scroll through the cursor options.

Its probably not tooo important but im a bit of a perfectionist.

So if anyone has had the same prob or knows how to fix it I would be much obliged.

Cheer. ;D
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Tue 16/09/2003 13:56:43
I have the same problem... when my cursor is over the GUI, I can not change the cursor with the right mouse button.
Any help would be appreciated! :D
Title: Re:Trouble with Gui and right clicking
Post by: SSH on Tue 16/09/2003 14:16:52
Maybe this manual excerpt will help:

Handle inventory clicks in script - normally, if the player clicks on an inventory item, it is processed internally by AGS. However, if you enable this option, then clicking an inventory item will call your on_mouse_click function with LEFTINV or RIGHTINV, and you then need to process it yourself. You can use the game.inv_activated variable to find out what they clicked on.
NOTE: this only works with custom Inventory GUI controls
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Tue 16/09/2003 14:23:15
Well, that works when overlapping the items themselves only, but the rest of the GUI still doesn't recognize right-clicks.
Title: Re:Trouble with Gui and right clicking
Post by: Ishmael on Tue 16/09/2003 15:46:35
There was a script for that somewhere... Probably buried under the dozens and dozend of new theads in either here of the Tech Forum....
Title: Re:Trouble with Gui and right clicking
Post by: Proskrito on Tue 16/09/2003 23:02:42
maybe the gui is in popup mode, and then when the gui is on, the game is paused, and then, if there is something like ' if (IsGamePaused() == 1){} ' in the on_mouse_click function, clicks arent registered?
just having a guess... ::)
EDIT: oh, but then left clicks shouldnt be registered also, and they are... :-\
Title: Re:Trouble with Gui and right clicking
Post by: Scorpiorus on Wed 17/09/2003 17:47:09
Any click on a GUI doesn't trigger on_mouse_click() function (unless it's not clickable) - that's the problem. Handle inventory clicks in script, as Bernhard said, works only for inventory window itself and not for the rest of GUI. Dorcan wrote a solution. It was here: http://host.deluxnetwork.com/~dorcan/script.php?id=1&page=1&langue=en (http://host.deluxnetwork.com/~dorcan/script.php?id=1&page=1&langue=en)... but the link doesn't seem to work now.


Another solution is to handle the right click inside the repeatedly_execute():

int rbutton_pressed = 0;
function repeatedly_execute() {


if (IsButtonDown(RIGHT)) {
if (rbutton_pressed == 0) {
SetNextCursorMode();
rbutton_pressed = 1;
}
}
else rbutton_pressed = 0;


}


The rbutton_pressed is needed to avoid repeatedly cycling when you hold the right button.

Also don't forget to remove the SetNextCursorMode(); line inside on_mouse_click() or you'll jump over the two cursor modes instead.

~Cheers
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Thu 18/09/2003 14:08:32
This works great, thanks! Now my interface is complete, heh. :D
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Fri 19/09/2003 15:25:50
I have a small problem with this code... if you click away a text with the right mouse key, it'll switch to the next icon. I need to find a way to lock changing cursors for a bit when the game is unpaused again.
Title: Re:Trouble with Gui and right clicking
Post by: on Sat 20/09/2003 05:26:22
Sweet thanks for that!

That was anoyying me a bit, im sur now i can fix it

Cheers ;D
Title: Re:Trouble with Gui and right clicking
Post by: Ishmael on Sun 21/09/2003 06:42:17
QuoteI have a small problem with this code... if you click away a text with the right mouse key, it'll switch to the next icon. I need to find a way to lock changing cursors for a bit when the game is unpaused again.

To do this, you'll need to create a custom display function:

function DisplayEx (string message) {}
// This function does not support the extra parameter, since I have no idea on how to pass it on as optional...
// but: First, display the message passed as parameter as usual
Display(message);
// then, set GlobalInt 79 to 1 for a few game loops
SetGlobalInt(79,1);
SetTimer(20,10); // set timer 20 to run for 10 game loops, which is usually 1/4 of a second.
while (IsTimerExpired(20) == 0) {
// Do nothing...
}
SetGlobalInt(79,0); // set the GlobalInt back to 0
}


and you need to modify the mouse click handling script:

int rbutton_pressed = 0;
function repeatedly_execute() {


if (IsButtonDown(RIGHT)) {
if (rbutton_pressed == 0) {
if (GetGlobalInt(79) == 0) SetNextCursorMode(); // do this change so the cursor mode will only be toggled if GI 79 is 0, which is not true in the following 10 game loops of a display with DisplayEx
rbutton_pressed = 1;
}
}
else rbutton_pressed = 0;


}



;)
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Sun 21/09/2003 13:08:14
I tried adding the code, but it didn't change anything. I played with it a bit, but the function doesn't seem to do anything at all. -_-
Title: Re:Trouble with Gui and right clicking
Post by: Gilbert on Mon 22/09/2003 04:05:44
Well, TK, there're a problm with your codes:
the
while (IsTimerExpired(20) == 0) {
// Do nothing...
}

part would be an endless loop, you MUST put a Wait() statement inside it instead of "doing nothing", and if you use waiting, you don't need a timer anyway.


So, try TK's codes, but replace the
SetTimer(20,10); // set timer 20 to run for 10 game loops, which is usually 1/4 of a second.
while (IsTimerExpired(20) == 0) {
// Do nothing...
}

part with
Wait(10);
I never checked, so I can't gaurantee it would work.
Title: Re:Trouble with Gui and right clicking
Post by: Ishmael on Mon 22/09/2003 11:06:08
Well, I theorized (sp? in case makes sense), thinking that the engine would check the timer once in every game loop... well I guess I was wrong.
Title: Re:Trouble with Gui and right clicking
Post by: Gilbert on Mon 22/09/2003 11:34:48
Yes the engine will update the timer once in each game loop. However, in a while loop, it won't advance a game loop unless you tell it to, so the while loop will just run within the same game loop, so the timer would probably never got updated within it.
Title: Re:Trouble with Gui and right clicking
Post by: Ishmael on Tue 23/09/2003 12:29:20
Oh, dammit......
Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Tue 23/09/2003 22:34:36
Well, The problem is that the displayex function itself doesn't do anything... i tried to only set a globalint to 1 under it but it didn't even do  that.
Title: Re:Trouble with Gui and right clicking
Post by: foz on Tue 23/09/2003 23:48:06
I had the same problem when making flashbax.

I can`t remeber exactly what i did but i think its something like this:

Set the interface to clickable:

then add to start...

int rbutton_pressed = 0;

then in the repeatedly.
f ((IsButtonDown(RIGHT)==0) && (rbutton_pressed == 1)){rbutton_pressed = 0;}
if (IsGamePaused()==0){

if  (IsButtonDown(RIGHT)==1){
     if (rbutton_pressed == 0) {
    SetNextCursorMode();
    rbutton_pressed = 1; }



thats it think......

You dont need to mess around with timers i did`nt.

hope this helps


Title: Re:Trouble with Gui and right clicking
Post by: Bernie on Fri 26/09/2003 12:13:34
No, doesn't work either... thanks though! :3
I'll just deactivate skipping text with mouse (keyboard only) for the time being until I find a fix for this.