Small problem with cursor

Started by Draco, Tue 13/09/2011 15:43:22

Previous topic - Next topic

Draco

Hi,
I have this problem:
I want to make a menu for my game (when I'll finish it I'll upload it).
So I want to hide "Iconbar" and have cursor like a pointer.
I've tried this code for it:
function MenuRollDown() {
   Flag++;
   if ((55<Flag)&&(Flag<150)) gMenu.SetSize(320, (Flag-50)*2);
}

function MenuInit() {
   gMenu.SetSize(320, 1);
}

function MenuOn() {
   gMenu.Visible = true;
mouse.UseModeGraphic (eModePointer);
 gIconbar.Visible = false;
}

function MenuOff() {
   gMenu.Visible = false;
   mouse.UseModeGraphic (eModeWalkto);
 gIconbar.Visible = true;
}
So the problem is like this: when i start the game the cursor is in Walkto mode and I can't click on the menu buttons. I just want to have the cursor in pointer mode.
Is there any solution? ???

Draco

Khris

This should work:

above repeatedly_execute:

Code: ags
GUI*under_mouse;


inside it:

Code: ags
  GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu) mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
      if (um == gMenu) mouse.Mode = eModePointer;
    }
  }
  under_mouse = um;

Draco

Quote from: Khris on Tue 13/09/2011 17:35:50
This should work:

above repeatedly_execute:

Code: ags
GUI*under_mouse;


inside it:

Code: ags
  GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu) mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
      if (um == gMenu) mouse.Mode = eModePointer;
    }
  }
  under_mouse = um;


I have tried it, but it says "cannot assign initial value to global pointer" to this part:
GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse

Khris

Did you put the second block inside the repeatedly_execute function, i.e. between its { and } ?

Draco

Quote from: Khris on Wed 14/09/2011 17:38:53
Did you put the second block inside the repeatedly_execute function, i.e. between its { and } ?
OK, I forgot about that. Now the code is:
//====================================================================
//Repeatedly_execute:
//-------------------------------------------------------------------
GUI*under_mouse;

{GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu) mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
    if (um == gMenu) mouse.Mode = eModePointer;
    }
  }
under_mouse = um};
But it says there is unexpected { in this line:{GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse

Maybe I'm stupid or the AGS hates me, I really don't know.

Khris

Neither is the case :)

If you open the Global script (GlobalScript.asc) and scroll down to the function (or select it in the dropdown menu at the top), you'll get to this part:

Code: ags
...

function repeatedly_execute() {
  
  // Put here anything you want to happen every game cycle, even when
  // the game is paused. This will not run when the game is blocked
  // inside a command like a blocking Walk()
 
}

...


Now make it look like this:

Code: ags
...

GUI*under_mouse;

function repeatedly_execute() {
  
  GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu) mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
      if (um == gMenu) mouse.Mode = eModePointer;
    }
  }
  under_mouse = um; 
}

...


I didn't test this, so you might still get an error or it might not work as intended.

Snarky

#6
OK, Khris posted first, but this could still come in handy.

Quote from: Draco on Fri 16/09/2011 15:09:25
Maybe I'm stupid or the AGS hates me, I really don't know.

You're probably just not that experienced when it comes to programming. Find the part of the file that says something like:

Code: ags
function repeatedly_execute() {
  // stuff...
}


Take the code you have and move it inside that function, so it looks like this:

Code: ags

function repeatedly_execute() {
  GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu)
        mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
      if (um == gMenu)
        mouse.Mode = eModePointer;
    }
  }
  under_mouse = um;
  // stuff...
}


Make sure you don't change anything else that is in the function (the bit I call "// stuff..."). The way it works is that the "{ ... }" brackets define a block, and when that block follows a function declaration (a line that begins with the word "function"), it means "run this block of code any time the function is called". But if the block is just there by itself, AGS doesn't know what to do with it. The function "repeatedly_execute" is special in that AGS automatically calls it every game cycle, so anything you put in that function happens every time the game updates.

Draco

Quote from: Snarky on Fri 16/09/2011 15:36:38
OK, Khris posted first, but this could still come in handy.

Quote from: Draco on Fri 16/09/2011 15:09:25
Maybe I'm stupid or the AGS hates me, I really don't know.

You're probably just not that experienced when it comes to programming. Find the part of the file that says something like:

Code: ags
function repeatedly_execute() {
  // stuff...
}


Take the code you have and move it inside that function, so it looks like this:

Code: ags

function repeatedly_execute() {
  GUI*um = GUI.GetAtScreenXY(mouse.x, mouse.y);  // GUI currently under mouse
  if (um != under_mouse) {  // mouse moved over or off GUI
    if (under_mouse != null) {
      // mouse was moved away from GUI under_mouse
      if (under_mouse == gMenu)
        mouse.Mode = eModeWalk;
    }
    else {
      // mouse was moved over GUI um
      if (um == gMenu)
        mouse.Mode = eModePointer;
    }
  }
  under_mouse = um;
  // stuff...
}


Make sure you don't change anything else that is in the function (the bit I call "// stuff..."). The way it works is that the "{ ... }" brackets define a block, and when that block follows a function declaration (a line that begins with the word "function"), it means "run this block of code any time the function is called". But if the block is just there by itself, AGS doesn't know what to do with it. The function "repeatedly_execute" is special in that AGS automatically calls it every game cycle, so anything you put in that function happens every time the game updates.

OK, I've removed the code from the room2 (the room with menu) and the code with you said to me I have put in the right part of global script. Than it said: undefined symbol "under_mouse".

Khris

Please don't quote the entire post each time; your reply is going to appear below it anyway.

Like I explained, put the line "GUI*under_mouse;" directly above the line that says "function repeatedly_execute () {".

Did you miss my post...?

However, it seems like you don't want this menu to appear in every room, only in the startup screen, I guess.
In that case you have to create the room's repeatedly_execute event and use that function instead of the global one.

Btw, I apologize for not being as clear as I could have been from the start but looking at your first post with several custom functions and stuff it appeared as if you weren't new to coding.

Draco

I have written the code for global script to script for the menu room  in "aplication funcions" part and guess what? The problem was still there: mouse in walk mode, black squares instead of iconbar and when i click on the square when normaly is quit game button the mouse change to a pointer so the first part of the problem is solved (maybe) but I can't click to any of the menu buttons.
This is the code for menu buttons I've used (they are in global script) :

// Menu Gui
//
// The  following functions are executed in  response to mouse clicks
// on the Main Menu that appears at the beginning of the game.
//-------------------------------------------------------------------
function gMenuIntro_Click(GUIControl *control, MouseButton button) {
   player.ChangeRoom(3); 
}

function gMenuLoad_Click(GUIControl *control, MouseButton button) {
   mouse.Mode = eModeWalkto;
   RestoreGameDialog();
}

function gMenuPlay_Click(GUIControl *control, MouseButton button) {
   player.ChangeRoom(5);    // player is now updated when PC changes
}

function gMenuQuit_Click(GUIControl *control, MouseButton button) {
   player.ChangeRoom(4);
}


SMF spam blocked by CleanTalk