Difficulty repositioning the cursor and having it stick

Started by bx83, Wed 16/06/2021 13:09:38

Previous topic - Next topic

bx83

I have the following code:

Code: ags
function repeatedly_execute_always()
{
  mouse.Update(); //update the position of the mouse hopefully this tick
  ...


Code: ags
function UpdateMouseGraphic()
{
...
if (gInventory.Visible) {                                      //looking at an icon IN THE INVENTORY
      if (mouse.y >= 175 && (mouse.x <= 180 || mouse.x >= 1170) && !JustHitTabInv) {
        gInventory.Visible = false;
          if (player.ActiveInventory==null)
            mouse.Mode = PreviousMouseModeOutsideInventory;
        return;
      }
    ...


Code: ags
function on_key_press(eKeyCode keycode)
{
...
if (keycode == eKeyTab) {
    if (!gInventory.Visible) {
      mouse.SetPosition(400, 350);
      mouse.Update();          <--- plus there's this, still does nothing
      gInventory.Visible=true;
      PreviousMouseModeOutsideInventory=mouse.Mode;
      mouse.Mode=eModeLookat;
      JustHitTabInv=true;
    } else{
      gInventory.Visible=false;
    }
  }
...


When I hit TAB, the first function to run is on_key_press(). It correctly sets the position of my cursor; inventory comes up; since the mouse isn't now beyond the 'outside border' of the inventory, the inventory remains open.
The next functions to run are repeatedly_execute_always() and UpdateMouseGraphic(). mouse.update() get's run at least 40 times before any change to mouse position happens.

Then, I move the mouse slightly upward; it returns to it's original position down in the far-left -- having never updated the variables for mouse position I set 500 times in the last few seconds -- the cursor moves instantly outside the inventory GUI, and the GUI disappears.


...wtf?
How can I get the mouse to just update and remember it's position?


bx83

Where should I call it? Already read the manual, no clues there.

bx83

Took away the extra .Update in on_key_press() and got rid off the JustHitTabInv switch, so it's no longer used. Still same problem.

Would anyone be able to shed some light on this? It's fairly essential, all I want to do is move the mouse over a GUI window and have it stay there, thats it.

Crimson Wizard

#4
A note on Mouse.Update, it does opposite to what you seem to think: it does not apply your values, it assigns script mouse.x/y variables to real mouse position (other way around).

Quote from: bx83 on Thu 17/06/2021 01:52:14
Would anyone be able to shed some light on this? It's fairly essential, all I want to do is move the mouse over a GUI window and have it stay there, thats it.

To clarify, are you saying that mouse glitches away as soon as player moves it instead of starting from the new position, or do you want to "glue" mouse to that position until you allow it to go?

If latter, there's Mouse.SetBounds, if former - maybe that's an engine bug.

Also, if all that is to keep GUI popped up, maybe the better approach would be to use "normal" gui style and script showing it up yourself, according to your own rules.
Alternatively, since AGS 3.5.0 you may change PopupY property at runtime, which allows you to temporarily make it stay regardless of mouse position (if you set it to very high values)

bx83

Quoteare you saying that mouse glitches away as soon as player moves it instead of starting from the new position

This is exactly what I'm saying, on the nose, absolutely. How do I do this?

I want to:
0. get the mouse at 50,50
1. enter new coords 300,300 for the mouse
2. have it move there, and the cursor too; NOW, the on-screen cursor, the values within the engine, and the starting position for the mouse is now universally 300,300. 50,50 is overwitten; it's gone. The end. 300,300 is where the mouse is.
3. have it stays there, so next time it's moved it moved from the *new* position of 300,300, not the *old* position of 50,50.

So that's it, ultimately. There may be better way of doing this, but I just want to: move the mouse to new coords, and have it stick there as its new position.

Crimson Wizard

#6
Simply mouse.SetPosition is supposed to do that. If it does not - that could be engine bug.
Are you using AGS 3.5.0, or some other version?

bx83

Removed all uses of mouse.Update(); mouse is now flipping back to original position when moved :/      (as it was before with mouse.Update)
I'm using AGS 3.5.0.31

bx83

I've upgraded to 3.5.1.7 - error still happens. Must be something in my code; but I can't find a single instance of mouse.Update() or mouse.x==some_variable, or anything else like this.

It seems when the gInventory GUI checks if the mouse is outside the inventory borders (and only in UpdateMouseGraphic()), and then closes the gInventory window -- it returns the mouse to it's old location; BUT it has nothing to do with running the UpdateMouseGraphic() function, so I'm stumped. When I *don't* run this function: the mouse still changes position on Tab being hit, and it still moves back to it's previous position when I move it.

So I'm stumped. SetPosition just won't stick. Or - there's some constant change/update to mouse position I'm missing in my rat's nest of code :/

bx83

Alright, fk it - I just changed rules to "hit tab, inventory window doesn't disappear; click on inventory icon, it does". Much simpler.

If anyone (of good character) wants to look at my (expensive, soon-to-be-commercialised) code, I'll PM you the project file; otherwise, it looks like this is unsolved.

Crimson Wizard

#10
I made a test game in 3.5.0, and simply calling mouse.SetPosition works well.

Used following code:
Code: ags

// room script file
function on_key_press(eKeyCode key)
{
	if (key == eKeySpace)
		mouse.SetPosition(100, 100);
}


Guess there's something else in the script that breaks it, but I have no idea what can it be, unless you have another mouse.SetPosition call elsewhere.


Quote from: bx83 on Fri 18/06/2021 01:29:09
Alright, fk it - I just changed rules to "hit tab, inventory window doesn't disappear; click on inventory icon, it does". Much simpler.

Frankly that may be better for players too, imo players may get confused if their mouse changes position unexpectedly.

bx83

Out of blooody-mindedness, I added code; still happens, SetPosition won't stick.
Now looking at all the code. SetFloatingText() runs each mouse move but isn't the culprit - commented out, error still happens.
I'm gonna find this eventually - otherwise I won't get to use SetPosition() in later games.  (what, I'm going to rewrite the codebase from scratch?)

Crimson Wizard

Quote from: bx83 on Fri 18/06/2021 08:02:25
Out of blooody-mindedness, I added code; still happens, SetPosition won't stick.

Can you try that in a completely new empty game? I'd suggest to always do that if there's a suspicion that command works incorrectly.


bx83

I start a game based on the VerbCoin template; I add the code; the error is happening. VerbCoin was the original template I used (though later deleted the script for it, and did mine custom).
I started a Blank game; made 1 character and 1 room; put that code in that room; the error still happens.
SetPosition is broken.

Crimson Wizard

Can you send me any game with this broken behavior please?

Have anyone else experienced this? Do you have any testers that may check out your real game?

Matti

Works fine for me. SetPosition is definitely not broken.

Laura Hunt

Quote from: Crimson Wizard on Sat 19/06/2021 12:35:31
Can you send me any game with this broken behavior please?

Have anyone else experienced this? Do you have any testers that may check out your real game?

I use SetPosition in IOAWN4T and it works as expected, both when compiling with 3.4.3 and 3.5.0.31.

Crimson Wizard

Maybe this be an operating system or device problem?

Here's a test game I made, where you need to press Space key to move the mouse:
https://www.dropbox.com/s/vbnefk8k7cv8uc6/test--mousepos.zip?dl=0

bx83

Will send the file when I can tomorrow, over here it's 11pm
It's possible it a bug, I'm running the AGS editor in Parallels 16.5.0, a Mac VM of Windows 10.

eri0o

In case it's an environment bug, please test with the SDL version of the engine and report if it reproduces there, it's a different backend, so if the bug is on backend maybe it works differently with it.

I have used SetPosition in my games because of my arrowselect module and I haven't had the reported problem, but I haven't used parallels and I think it has specific Windows drivers for it.

SMF spam blocked by CleanTalk