SOLVED: difficulties with mouse.mode

Started by maximusfink, Thu 28/06/2012 03:38:46

Previous topic - Next topic

maximusfink

Hi I have a problem that I've been trying very hard to figure out but I keep hitting a wall...

I have a sequence where the player has to pick up a gun and fire it at a target in the distance. My goal is to have the player click on the gun with the interact cursor, then have the cursor mode switch to 'crosshair' which is a custom cursor I've created. In this cursor mode that can only be obtained by using the interact cursor with the gun, the player will be able to shoot the target in the distance, which is another character.

function gun_Interact()
{
    gun.Visible = false;
    bikeman.ChangeView(3);
    mouse.Mode(eModeCrosshair);
    Wait(200);
    bikeman.ChangeView(1);
    gun.Visible = true;
}

this is the room script dealing with the gun object. bikeman is the player character. I found that when I used mouse.Mode to change to one of my normal cursors (talk, look, interact) while simply changing the mouse.UseModeGraphic, the crosshair cursor graphic would appear. But I don't see why I shouldn't be able to have the cursor itself. I looked at everything I could find about mouse.Mode but to no avail, maybe I'm just using it the wrong way?

monkey0506

Well seeing as you didn't say what problem it is that you're actually having with this code, I can only assume that it's because you're trying to use mouse.Mode which isn't a function as if it were a function.

Code: ags
function gun_Interact()
{
  gun.Visible = false;
  bikeman.ChangeView(3);
  mouse.Mode = eModeCrosshair; // mouse.Mode is a property, not a function
  Wait(200);
  bikeman.ChangeView(1);
  gun.Visible = true;
}


Now of course, what this would actually do is hide the gun (Object/Character), change bikeman's view to 3, change the mouse to the Crosshair cursor, wait 5 seconds (based on the default 40 FPS), change bikeman's view back to 1, and make the gun (Object/Character) visible again. The way you have it coded right now is blocking, which means that all this would happen while not allowing any user input throughout. Based on your description, I don't know (read as: doubt) that this is probably your intended behavior...?

Crimson Wizard

#2
Quote from: maximusfink on Thu 28/06/2012 03:38:46
But I don't see why I shouldn't be able to have the cursor itself.
I've read this several times and couldn't figure out what do you mean by "not able to have the cursor". Then I read monkey's response and realized you might be meaning that you cannot move the cursor with the mouse. Is that the case?
Then that's surely because you are blocking game execution by Wait command, as monkey has pointed out. Wait simply "pauses" most of the game action, including player controls.
What you should possibly do, is:
1. When player interacts with gun, make cursor change; and also make the timer start!
Code: cpp

#define GUN_TIMER_ID   10  // an optional value
function gun_Interact()
{
    gun.Visible = false;
    bikeman.ChangeView(3);
    mouse.Mode = eModeCrosshair;
    SetTimer (GUN_TIMER_ID, 500);
}

2. When player clicks somewhere, while cursor is set to crosshair, make it shoot.
3. When enough time has passed and regardless of whether player made a shot or not, change cursor back and put the gun back (or something like that, depending on what you want). Timer checking should be probably done inside room's "repeatedly execute" function:
Code: cpp

function room_RepExec()
{
    if (IsTimerExpired(GUN_TIMER_ID))
    {
        bikeman.ChangeView(1);
        gun.Visible = true;
    }
}



As a side-note, I may recommend to use "player" instead of using actual character name, i.e.:
Code: cpp

player.ChangeView(3);

This may come handy if for some reason you'll decide to change character name in the future.

monkey0506

#3
Quote from: Crimson Wizard on Thu 28/06/2012 07:41:29I've read this several times and couldn't figure out what do you mean by "not able to have the cursor". Then I read monkey's response and realized you might be meaning that you cannot move the cursor with the mouse. Is that the case?

Blocking functions don't prevent the mouse cursor from moving around on the screen, but it will display the wait cursor (or hide the mouse if that cursor image is set to 0) and prevent any clicks from being processed. So yes to the rest of the post, just wanted to clarify that blocking doesn't prevent moving the cursor around the screen.

Quote from: Crimson Wizard on Thu 28/06/2012 07:41:29
Code: cpp
#define GUN_TIMER_ID   10  // an optional value

Okay, okay, so just another couple of nit-picky things. First off, AGS doesn't support native coding in C++ yet. :P (For AGS code you can use [code=ags][/code]). Also, saying "an optional value" seems somewhat ambiguous. Is the entire macro optional? Is the value the macro is defining optional (i.e., is an empty macro acceptable?), or is the actual value itself optional? Of course what you meant was that the value 10 could be anything between 1 and 20, as those are the available timers. ;) (P.S. I myself am not a big fan of the current "SetTimer" function simply because it's rather ambiguous and easy to collide with other timers; it's just as easy to just use a simple int timer in a situation like this...)

Quote from: Crimson Wizard on Thu 28/06/2012 07:41:29As a side-note, I may recommend to use "player" instead of using actual character name, i.e.:
Code: cpp
player.ChangeView(3);


This may come handy if for some reason you'll decide to change character name in the future.

Yes, but only if bikeman is indeed the player character. :P

Edit: The forums are trying to be all smart about me trying to circumnavigate the formatting of the code tags. Lol.


monkey0506

Nonsense, you can't just go around quoting people just to make me look foolish! (roll)

maximusfink

#6
Oh sorry, I should have gone into more detail. At first I kept getting an error message saying something like: PE04 parse error at 'mouse.'  or variations of that as I kept messing around with it. When I got past those errors and ran the game, clicking on the gun with the interact cursor would do everything I told it to do, except instead of switching to the "crosshair mode" the cursor would just disappear until the timer ran out. When I changed mouse.Mode to mouse.UseModeGraphic I was able to get the cursor to change in appearance while still being in interact mode.

Thanks for the responses, I'll keep working at this. It sounds like it's the Wait function that's causing problems, I didn't realize it took control from the player. I'll start using the SetTimer function.

maximusfink

Code: ags

function gun_Interact()
{
    gun.Visible = false;
    bikeman.ChangeView(3);
    mouse.Mode = eModeCrosshair;
    SetTimer (GUN_TIMER_ID, 200);
}

function room_RepExec()
{
    if (IsTimerExpired(GUN_TIMER_ID))
    {
        bikeman.ChangeView(1);
        gun.Visible = true;
    }
}


Okay, so this is what the code looks like right now. I defined GUN_TIMER_ID in global.ash. Now when I click on the gun, it disappears and the mouse cursor changes appropriately. It seems like everything under function gun_interact is working. But I think it's ignoring the SetTimer function, because the View never changes back, and the gun object never reappears (I haven't even bothered with changing the mouse mode back yet).

I have it set to cycle cursors with scroll, and when I scroll up the crosshair cursor reverts to my normal set of cursors, but that's an unrelated issue.

Also, bikeman isn't actually the player.character, he's a separate character used to represent the player character in this room, because the events are being depicted from an abnormal angle if that makes any sense.

I'm sure there's some very simple detail I'm overlooking.

Crimson Wizard

Is the function room_RepExec actually bound to corresponding event? This is done on the Room editor, on properties/events panel.

maximusfink

Ahhh That is what I was missing, thank you.

monkey0506

Quote from: maximusfink on Thu 28/06/2012 17:57:56Also, bikeman isn't actually the player.character

Hahah, I win! :P

So, is this resolved now?

If you were experiencing a parse error near 'mouse', that may be because you were treating it like a function, or because of some issue with braces or parenthesis or some such. In cases like that, if you can't figure it out, best to post the exact error message (Ctrl+C when the error message is displayed to copy most errors to the clipboard) and exact code snippet that is causing the issue. In any case, it looks like this is solved?

maximusfink

Yeah this is solved. No doubt I'll encounter more snags as I move forward but I'm getting more familiar with the scripting. Thanks a bunch guys!

SMF spam blocked by CleanTalk