Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Luca on Wed 17/07/2013 14:04:51

Title: [Fixed] Cursor imperfections during dialogs
Post by: Luca on Wed 17/07/2013 14:04:51
Hi guys!
I'm still working on a prototype and I encountered a pair of imperfections that I would like to fix :)

1)
The player is supposed to talk to the chest. Moving the mouse over the chest, the name appears over the cursor ("baule" means "chest" in italian :))
http://imageshack.us/photo/my-images/855/bso5.jpg/
Anyway, as you can see from the picture in the link, this feature works fine :)

The problem appears if I click on the chest to talk to it and I don't move the cursor, leaving it on the chest.
http://imageshack.us/photo/my-images/32/z4yf.jpg/
As you can see, the "mouseover name" remains on screen during the dialogue, even if a I move away the cursor.
How can I fix that automatically when dialogues start?
I think I could use a variable, but maybe there is another way.

Note: when the dialogue ends, all returns at normality.

2)
If I pass the cursor on an hotspot, it changes form.
During dialogues, it still changes form if I pass over an hotspot.
http://imageshack.us/f/32/taqd.jpg/
How can I deactivate this feature during dialogues?

Thank you :)
Title: Re: Cursor imperfections during dialogs
Post by: Ghost on Wed 17/07/2013 14:20:06
Quote from: Luca on Wed 17/07/2013 14:04:51
How can I fix that automatically when dialogues start?

Open your global script, find the function on_mouse_click, and add a line:

NameOfYourMouseOverLabel.Text = "";

This will, each time the mouse is clicked, delete the label's text.
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Wed 17/07/2013 14:34:26
Quote from: Ghost on Wed 17/07/2013 14:20:06
This will, each time the mouse is clicked, delete the label's text.

Yea! Thank you Ghost! :)
It works poperly now. The first issue has been fixed! :P

EDIT:
No, I was wrong :( It dectivates the label during dialogues, but at the end of it the label remains turned off :(
Title: Re: Cursor imperfections during dialogs
Post by: Snarky on Wed 17/07/2013 15:18:40
The first of your problems sounds like it's because the script doesn't run during dialogues, so it doesn't update (remove) the labels. On the other hand, the second problem sounds like it's because the script does run during dialogues, updating the cursor. Maybe one of them is in repeatedly_execute() and the other in repeatedly_execute_always()?

It's fixable, but you'll have to let us know what code you're using to get the label and the changing mouse cursors in the first place.
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Wed 17/07/2013 15:43:42
Quote from: Snarky on Wed 17/07/2013 15:18:40
It's fixable, but you'll have to let us know what code you're using to get the label and the changing mouse cursors in the first place.

Ok :)

1) Ok, I put it in the "repeatedly_execute()" and my spider senses say that I made a mistake...
Code (AGS) Select
function repeatedly_execute()
{
  if(GetLocationType(mouse.x,  mouse.y) != eLocationNothing)
    {
      gDescription.Visible = true;
      int mousex = mouse.x - 34;
      int mousey = mouse.y - 80;
      gDescription.SetPosition(mousex, mousey);
    }
  else if(gDescription.Visible == true)
    {
  gDescription.Visible = false;
    }


2) I didn't use any code for the animating cursor... I just touched the settings from the "mouse cursors" menu.
EDIT: In the "Walk To" cursor's options i selected:
- Animate: True
- AnimateOnlyOnHotspot: True
- AnimateOnlyWhenMoving: False
Title: Re: Cursor imperfections during dialogs
Post by: Snarky on Wed 17/07/2013 16:12:19
Try this instead:

Code (AGS) Select
function repeatedly_execute_always() // Note edit! +'_always'
{
  if(GetLocationType(mouse.x,  mouse.y) != eLocationNothing && !IsGamePaused()) // Note edit! +'&& !IsGamePaused()'
  {
    gDescription.Visible = true;
    int mousex = mouse.x - 34;
    int mousey = mouse.y - 80;
    gDescription.SetPosition(mousex, mousey);
  }
  else  // Note edit! -'if(gDescription.Visible == true)' It wasn't wrong, but I deleted the test because it's not necessary, and this way the program logic is simpler
  {
    gDescription.Visible = false;
  }
  ...
}


I've also fixed your indentation. As the saying goes, consistent indentation is next to godliness!

Quote from: Luca on Wed 17/07/2013 15:43:42
2) I didn't use any code for the animating cursor... I just touched the settings from the "mouse cursors" menu.

If the mouse cursor changes over hotspots, there's some code somewhere that makes that happen.

Gah! AGS has a hardcoded editor feature for this. Uagh! If you want to fix it, you'll probably have to drop it and replace it with code instead. (Which is why I think these hardcoded features are a waste; they almost never do exactly what you need, so you have to replicate them in code anyway.)
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Wed 17/07/2013 16:25:00
Thank you :)

1) I just tried with your corrections but it does exactly the same as before :(

2)Yea, I suppose that coding all the aspects would be better. I'll search the code on the manual before bothering you all again on this aspect :)
Title: Re: Cursor imperfections during dialogs
Post by: Snarky on Wed 17/07/2013 16:53:27
Point (1) is probably related to this (http://www.adventuregamestudio.co.uk/forums/index.php?topic=19463.msg237074#msg237074), and should be fixable by:

Quote from: Khris on Fri 21/06/2013 03:03:56
In General settings -> Dialog is an option called "Run game loops while dialog options are displayed". It should allow you to at least use rep_ex_always.

To do an animating cursor over hotspots only when game is not paused, try something along the lines of:

Code (AGS) Select

function repeatedly_execute_always()
{
  // ...
  if (GetLocationType(mouse.x, mouse.y) != eLocationNothing && !IsGamePaused())
  {
    mouse.ChangeModeView(eModeWalkto, MOUSEANIMATION);  // Where MOUSEANIMATION is the view number of the animation you want to play
  }
  else
  {
    mouse.ChangeModeView(eModeWalkto, -1);  // Stop animating. You can also reset the graphic with Mouse.UseDefaultGraphic() if necessary
  }
  // ...
}


It's possible that setting the view every cycle will stop the animation from actually running; in that case you need a flag to only call ChangeModeView once.
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Wed 17/07/2013 18:18:16
Thank you again :)

1) Almost fixed. Now, if I click on the chest to begin the dialogue, the name remains on screen untill I move the mouse, then the name disappears and all works fine :)

2) Thinking at the situation I asked myself "why am I using views? there is no real animation... the cursor just changes graphic" so I used your code touching the graphic and not the view. It works fine, BUT there are two problems :) Hurray!
a) now the cursor is always visible, also during scripts. Later I would like to add the possibility to cancel an action before the character reaches the point to perform it, but the cursor can't be always visible :D
b) still the cursor changes during dialogs, if over an hotspot :(
Title: Re: Cursor imperfections during dialogs
Post by: Snarky on Thu 18/07/2013 10:35:54
OK, I tried to replicate your situation myself.

1) Can't replicate; it works for me. What string are you using for the label on gDescription? I'm assuming @OVERHOTSPOT@
2.a) Don't really understand what you mean by this. You want the cursor to go away during blocking actions? What does the wait cursor look like? Are you changing it anywhere?
2.b) Right, here we have a problem. When you set "Run game loops while dialog options are displayed," apparently AGS doesn't consider the game to be paused while dialogs are running. This is a bug, in my opinion. I can't find any simple way to test whether a dialog is currently running. I tried changing the dialog options to be displayed in a text window gui, and testing whether that gui is visible, but it doesn't detect it (this is another bug, in my opinion).

As a workaround, you can track it yourself. I wrote a script to help out:

Code (AGS) Select

// DialogState.ash
struct DialogState
{
  import static bool IsActive();
};

import void StartTracked(this Dialog*);
import int StopTracked(this Dialog*);

// DialogState.asc
bool isActive;

static bool DialogState::IsActive()
{
  return isActive;
}

void StartTracked(this Dialog*)
{
  isActive = true;
  this.Start();
}

int StopTracked(this Dialog*)
{
  isActive = false;
  return RUN_DIALOG_STOP_DIALOG;
}


Now instead of calling myDialog.Start(), you have to always call myDialog.StartTracked(). And instead of putting a "stop" in the dialog script, you always have to end it with " return this.StopTracked();" (note opening space).

Now change the line that says "if (GetLocationType(mouse.x, mouse.y) != eLocationNothing && !IsGamePaused())" to "if(GetLocationType(mouse.x,  mouse.y) != eLocationNothing && !IsGamePaused() && !DialogState.IsActive())" and you should be set!

Here's my demo game project if you need to have a closer look at how it all fits together: https://www.dropbox.com/s/wregvffnqu1s97x/testcursor2.rar
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Thu 18/07/2013 23:40:19
Quote from: Snarky on Thu 18/07/2013 10:35:54
OK, I tried to replicate your situation myself.
Here's my demo game project if you need to have a closer look at how it all fits together: https://www.dropbox.com/s/wregvffnqu1s97x/testcursor2.rar
Thank you!
Tomorrow I will try everything :) Wow guys, this community is fantastic :D
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Fri 19/07/2013 19:03:43
Ok, here I am :)
Fort point 2, the cursor issue that doesn't disappear when a function is performed and changes when overspot during dialogues, I just put the "change graphic" code in the "repeatedly_execute" part.
Sorry, but I learned the repeatedly_execute_always thing only two post ago :D
Anyway, now it disappears correctly (even if I want to change it later) and it doesn't change graphic during dialogues :)

For point 1 there is still that little issue: if I'm with cursor over the chest, for a while the name of the hotspot appears (until I move the cursor away :))
It's only a imperfection, I know, but I would like to have the most polished game possible :)

About the code you posted, I think I have to learn something about dialogues... what is "myDialog.Start()"?
I never used it...  :-[

Thank you (again!)
Title: Re: Cursor imperfections during dialogs
Post by: Snarky on Fri 19/07/2013 19:56:07
myDialog is just an example name for whatever you call your dialog. For example, this dialog (nice graphics, btw!):

(http://img32.imageshack.us/img32/150/z4yf.jpg)

You've created this dialog in the dialog designer and given it a name, right? If you called it myDialog, just as an example, you could put myDialog.Start() in the code, and it would launch that dialog when it runs that bit of code. Since you're not familiar with that way of doing it, I assume you've just set the OnClick event of the chest to "launch dialog topic" or whatever it's called? Mmm... that won't work with this fix, you'll have to set it to run a function instead.

However, before you follow any of my other advice, try this: Just change this line...

Code (AGS) Select
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing && !IsGamePaused())
// Or if(GetLocationType(mouse.x,  mouse.y) != eLocationNothing && !IsGamePaused() && !DialogState.IsActive()) if you already made the change I suggested last post


...to this...

Code (AGS) Select
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing && IsInterfaceEnabled())

Since monkey set me right (http://www.adventuregamestudio.co.uk/forums/index.php?topic=48697.msg636462600#msg636462600) that IsPauseGame() doesn't have anything to do with what we're interested in.

That might fix everything, and you don't have to mess around with DialogState and StartTracked or any of that. However, you might want to read through the scripting tutorial in the AGS manual and get a bit more familiar with how coding works in AGS and what the different things do.
Title: Re: Cursor imperfections during dialogs
Post by: Luca on Sat 20/07/2013 00:57:25
Quote from: Snarky on Fri 19/07/2013 19:56:07
Code (AGS) Select
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing && IsInterfaceEnabled())

Since monkey set me right (http://www.adventuregamestudio.co.uk/forums/index.php?topic=48697.msg636462600#msg636462600) that IsPauseGame() doesn't have anything to do with what we're interested in.

That might fix everything, and you don't have to mess around with DialogState and StartTracked or any of that. However, you might want to read through the scripting tutorial in the AGS manual and get a bit more familiar with how coding works in AGS and what the different things do.

Ok, I just didn't understand what did you mean with "myDialog", but yea, I used that code and I forgot it :P (I started using AGS following a tutorial... there are many thing I still don't remember properly).
Anyway I just used your last code and it works PERFECTLY :)
Thank you so much Snarky! The issue is fixed :)

Reading your code I assume that during dialogues the interface is considered disabled by default, right?

Also thank you for the comment about the graphics :) This is only a prototype for us, but we hope we could make a good game :)
Title: Re: [Fixed] Cursor imperfections during dialogs
Post by: monkey0506 on Sat 20/07/2013 03:38:41
To be totally clear, the interface is always disabled during dialogs (see IsInterfaceEnabled). This is not the same as pausing the game. It may be confusing at first, but just recognize that they are separate terms in AGS. ;)
Title: Re: [Fixed] Cursor imperfections during dialogs
Post by: Luca on Sat 20/07/2013 06:50:39
Quote from: monkey_05_06 on Sat 20/07/2013 03:38:41
To be totally clear, the interface is always disabled during dialogs (see IsInterfaceEnabled). This is not the same as pausing the game. It may be confusing at first, but just recognize that they are separate terms in AGS. ;)

Thank you Monkey :) you've been absolutely clear!