Cursor won't change!

Started by Edwin Xie, Fri 27/08/2004 06:56:00

Previous topic - Next topic

Scorpiorus

Then make an addition to the previous code:

repeatedly_execute:

if (IsGUIOn(3) || IsGUIOn(4)) {
    SetMouseCursor(6);
    SetLabelText(STATUSBARGUI_NAME_HERE, LABEL_NUMBER_HERE, " ");

}
else SetDefaultCursor();

Edwin Xie

#21
Thanks, when I did
if (IsGUIOn(3) || IsGUIOn(4)) {
Ã,  Ã,  SetLabelText(STATUSBARGUI_NAME_HERE, LABEL_NUMBER_HERE, " ");
Ã,  Ã,  SetMouseCursor(6);
Ã,  Ã, 
}
else SetDefaultCursor();

there was a parse error on "else". Notice that it is slightly different to your script.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Edwin Xie

Ok, questions to ask:
I want the status bar to change to "something" when I move over a button on the GUIs. How can I do that?

On the inventory GUI (its a custom GUI), when you click on the select button my cursor changes to the walk icon. What can I do to fix that? I haven't modified any script on the inventory GUI. And...would it help if I showed you the script?
Function show_inventory_window
Code: ags

function show_inventory_window () {
  // This demonstrates both types of inventory window - the first part is how to
  // show the built-in inventory window, the second part uses the custom one.
  // Un-comment one section or the other below.
  
/*  
// ** DEFAULT INVENTORY WINDOW
  InventoryScreen();
*/  
  // ** CUSTOM INVENTORY WINDOW
  GUIOn (INVENTORY);  
  // switch to the Use cursor (to select items with)
  SetCursorMode (MODE_USE);
  // But, override the appearance to look like the arrow
  SetMouseCursor (6);
}

Function interface_click
Code: ags

function interface_click(int interface, int button) {
  if (interface == ICONBAR) {
    if (button == 4) {  // show inventory
      show_inventory_window();
    }
    else if (button == 5) {   // game controls
      InterfaceOff(1);
      SetCursorMode(6);
      InterfaceOn(3);
    } 
    else if (button == 6)    // save game
      SaveGameDialog();
    else if (button == 7)   // load game
      RestoreGameDialog();
    else if (button == 8)   // quit
      GUIOn(4);
    else if (button == 9)    // about
      Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");
  }  // end if interface ICONBAR

  if (interface == INVENTORY) {
    // They clicked a button on the Inventory GUI
    
    if (button == 1) {
      // They pressed SELECT, so switch to the Get cursor
      SetCursorMode (MODE_USE);
      // But, override the appearance to look like the arrow
      SetMouseCursor (6);
    }
    
    if (button == 2) {
      // They pressed LOOK, so switch to that mode
      SetActiveInventory(-1);
      SetCursorMode(MODE_LOOK);  
    }
    if (button == 3) {
      // They pressed the OK button, close the GUI
      GUIOff (INVENTORY);
      SetDefaultCursor();
    }

    if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
      // scroll down
      game.top_inv_item = game.top_inv_item + game.items_per_line;
    }
    if ((button == 5) && (game.top_inv_item > 0)){
      // scroll up
      game.top_inv_item = game.top_inv_item - game.items_per_line;
    }
  }
  CentreGUI(3);
  if (interface == 3){
    if (button == 8) SetGameSpeed(GetSliderValue(3,8));
    else if (button == 9) SetMusicMasterVolume(GetSliderValue(3,9));
    else if (button == 10) game.text_speed = GetSliderValue(3,10);
    else {
    if (button == 0) SaveGameDialog();
    if (button == 1) RestoreGameDialog();
    if (button == 2) GUIOn(4);
    if (button == 3){
      SetCursorMode(6);
      RestartGame();
      }
    if (button == 4) 
    Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");
    }
  if (button == 11){
    InterfaceOff (3);
    InterfaceOn (ICONBAR);
    SetCursorMode (1);
    }
  }
if (interface == 4)
  SetCursorMode(6);
  SetMouseCursor(6);
  DisableCursorMode(0);
  DisableCursorMode(1);
  DisableCursorMode(2);
  DisableCursorMode(3);
  DisableCursorMode(5);
  {
  if (button == 0)
  QuitGame(0);
  else if (button == 1)
  GUIOff(4);
  EnableCursorMode(0);
  EnableCursorMode(1);
  EnableCursorMode(2);
  EnableCursorMode(3);
  EnableCursorMode(5);
  SetCursorMode(0);
  }
}
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Moox

#23
Look up status bar in the manual, therse a little section on the variable about hotspots and set label text

Scorpiorus

Quotethere was a parse error on "else". Notice that it is slightly different to your script.
You have to place the code within the repeatedly_execute function body, not outside of it:

function repeatedly_execute() {

<<<put it here>>>

}


Also be sure to consult the AGS manual Text scripting tutorial on how functions are declared.


Quotewant the status bar to change to "something" when I move over a button on the GUIs. How can I do that?

Again, inside the repeatedly execute:

if (GetGUIAt(mouse.x, mouse.y) == GUI_NAME_HERE) {
   if (GetGUIObjectAt(mouse.x, mouse.y) == BUTTON_NUMBER_HERE) SetLabelText(GUI_NAME_HERE, STATUSBAR_LABEL_NUMBER_HERE, "something");
}

QuoteOn the inventory GUI (its a custom GUI), when you click on the select button my cursor changes to the walk icon. What can I do to fix that?
Depends on what you mean by "fix that". Can you be more specific?

Edwin Xie

Quote from: Scorpiorus on Sun 05/09/2004 07:49:18
..........
QuoteOn the inventory GUI (its a custom GUI), when you click on the select button my cursor changes to the walk icon. What can I do to fix that?
Depends on what you mean by "fix that". Can you be more specific?

On the inventory GUI there is three buttons on the bottom, right? The first one is 'look', second one is 'select' and the third one is 'OK'. When I click on the second one, 'select', it changes to the 'use' cursor but the script overrides it to the 'pointer' cursor. Now, when you click the 'select' button, it switches to the 'walk' cursor, completely ignoring the cursors 'use' and 'pointer'.

QuoteDepends on what you mean by "fix that". Can you be more specific?

"Fix that" means, "I got a problem, ..............(whatever the problem is), what can I do to fix my problem.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Scorpiorus

Quote from: Edwinxie on Mon 06/09/2004 01:56:22"Fix that" means, "I got a problem, ..............(whatever the problem is), what can I do to fix my problem.
Yeah, that's all fine, except that you are supposed to replace all these dots with a detailed description of what's wrong and *in which way* you would like it to behave instead. ;)

Quote from: Edwinxie on Mon 06/09/2004 01:56:22On the inventory GUI there is three buttons on the bottom, right? The first one is 'look', second one is 'select' and the third one is 'OK'. When I click on the second one, 'select', it changes to the 'use' cursor but the script overrides it to the 'pointer' cursor. Now, when you click the 'select' button, it switches to the 'walk' cursor, completely ignoring the cursors 'use' and 'pointer'.
I'm still not quite sure what you mean but looking into the script it seems that interaface 4 is messing things, here is a new version of the whole interface_click():

Code: ags
function interface_click(int interface, int button) {

Ã,  Ã,  if (interface == ICONBAR) 
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (button == 4)Ã,  Ã,  // show inventory
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  show_inventory_window();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else if (button == 5)Ã,  Ã,  // game controls
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  InterfaceOff(1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  InterfaceOn(3);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else if (button == 6)Ã,  Ã,  // save game
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SaveGameDialog();
Ã,  Ã,  Ã,  Ã,  else if (button == 7)Ã,  Ã, // load game
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  RestoreGameDialog();
Ã,  Ã,  Ã,  Ã,  else if (button == 8)Ã,  Ã, // quit
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetMouseCursor(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisableCursorMode(0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisableCursorMode(1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisableCursorMode(2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisableCursorMode(3);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisableCursorMode(5);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  GUIOn(4);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else if (button == 9)Ã,  Ã,  // about
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");
Ã,  Ã,  }Ã,  // end if interface ICONBAR



Ã,  Ã,  if (interface == INVENTORY) // They clicked a button on the Inventory GUI
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (button == 1) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // They pressed SELECT, so switch to the Get cursor
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode (MODE_USE);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // But, override the appearance to look like the arrow
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetMouseCursor (6);
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  Ã,  Ã,  if (button == 2) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // They pressed LOOK, so switch to that mode
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetActiveInventory(-1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(MODE_LOOK);Ã,  
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  Ã,  Ã,  if (button == 3) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // They pressed the OK button, close the GUI
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  GUIOff (INVENTORY);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetDefaultCursor();
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  Ã,  Ã,  if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // scroll down
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  game.top_inv_item = game.top_inv_item + game.items_per_line;
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  Ã,  Ã,  if ((button == 5) && (game.top_inv_item > 0))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // scroll up
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  game.top_inv_item = game.top_inv_item - game.items_per_line;
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }



Ã,  Ã,  CentreGUI(3);

Ã,  Ã,  if (interface == 3)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  8) SetGameSpeed(GetSliderValue(3,8));
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  9) SetMusicMasterVolume(GetSliderValue(3,9));
Ã,  Ã,  Ã,  Ã,  if (button == 10) game.text_speed = GetSliderValue(3,10);
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  0) SaveGameDialog();
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  1) RestoreGameDialog();
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  2) GUIOn(4);
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  3)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  RestartGame();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  if (button == 4) 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");

Ã,  Ã,  Ã,  Ã,  if (button == 11)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  InterfaceOff (3);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  InterfaceOn (ICONBAR);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode (1);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }



Ã,  Ã,  if (interface == 4) 
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã, if (button == 0)Ã,  QuitGame(0);
Ã,  Ã,  Ã,  Ã, if (button == 1) {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, GUIOff(4);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(3);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(5);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, SetCursorMode(0);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã,  }

}


Hope that'll help, otherwise try to be as much specific as possible on what's going on wrong and how you wan t it to be.

Edwin Xie

#27
That helped a little, but cursor 6 is not shown, just cursor 2. I'll go over the script. If I can't find why I'll modify this post.

EDIT: Yeah, I couldn't find the problem. Do you mind if I post the entire global script?
SPECIFIC PROBLEM: You see, everyone's game has an inventory GUI. The cursor looking button is the select button and that is the problem. When you click it, it was supposed to change to the 'use' cursor but gets its appearance overrided to look like the arrow:

Code: ags

 if (button == 1) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // They pressed SELECT, so switch to the Get cursor
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode (MODE_USE);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // But, override the appearance to look like the arrow
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetMouseCursor (6);
Ã,  Ã,  Ã,  Ã,  }


See what I mean? But now it just changes to MODE_USE and not executing SetMouseCursor (6);. Do you see now?
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Scorpiorus

#28
First of all, go to the GUI Editor and see what left click action the arrow button is set to. It has to be Run script rather than Set Cursor Mode.

If it's already set to Run Script then try calling Display from within the related part of the script:
Code: ags
if (button == 1) 
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("We've just clicked on an arrow button!"):
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // They pressed SELECT, so switch to the Get cursor
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode (MODE_USE);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("Changed cursor mode to MODE_USE!"):
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // But, override the appearance to look like the arrow
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetMouseCursor (6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("Changed cursor appearance to mode 6"):
Ã,  Ã,  Ã,  Ã,  }


...and see if messages are actually displayed on clicking the button.

Edwin Xie

#29
Uh, just be careful with your semicolons.

EDIT: Ok, I figured out the problem, (thanks scorpiorus for doing the display things) now I know what happens (with the help of scorpiorus). First it switches to MODE_USE, then it changes to cursor 6 but in 1 millisecond (with the messages I found out what was fishy) it changes BACK to MODE_USE. Can you explain that?
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Scorpiorus

Hmm, it is possible that you have some code in repeatedly_execute that overrides the cursor appearance back to normal, can you post your global script repeatedly_execute function?

Edwin Xie

Hmm, I think I posted the repeatedly_execute function but I'll post it again:
Code: ags

function repeatedly_execute() {
// LEC Statusline
string bunky;
string texty;
int cursy;

StrCopy (texty, "");
cursy=GetCursorMode();

if (cursy==0) StrCat(texty,"Walk to ");
else if (cursy==1) StrCat (texty,"Look at ");
else if (cursy==2) StrCat(texty,"Use ");
else if (cursy==3) StrCat(texty,"Talk to ");
else if (cursy==4) {
StrCat(texty,"Use ");
GetInvName (player.activeinv, bunky);
StrCat(texty,bunky);
StrCat(texty," with ");
}
else if (cursy==5) StrCat(texty, "Pick up ");
else if (cursy==8) StrCat(texty, "Open ");

GetLocationName(mouse.x,mouse.y,bunky);
StrCat(texty,bunky);
SetLabelText (0,0,texty);

if (IsGUIOn(1) || IsGUIOn(3) || IsGUIOn(4)) {
    SetMouseCursor(6);
    SetLabelText(0,0, " ");
}
else SetDefaultCursor();
}
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Scorpiorus

#32
Only the recent version of the repeatedly_execute function has a meaning, thus I can see what's currently being wrong with it.

So, here is a new repeatedly_execute version taking into account that a cursor shouldn't be reset if the INVENTORY GUI is on:

function repeatedly_execute() {
// LEC Statusline

Ã,  Ã,  string bunky;
Ã,  Ã,  string texty;
Ã,  Ã,  int cursy;

Ã,  Ã,  StrCopy (texty, "");
Ã,  Ã,  cursy=GetCursorMode();

Ã,  Ã,  if (cursy==0) StrCat(texty,"Walk to ");
Ã,  Ã,  else if (cursy==1) StrCat (texty,"Look at ");
Ã,  Ã,  else if (cursy==2) StrCat(texty,"Use ");
Ã,  Ã,  else if (cursy==3) StrCat(texty,"Talk to ");
Ã,  Ã,  else if (cursy==4) {
Ã,  Ã,  Ã,  Ã,  StrCat(texty,"Use ");
Ã,  Ã,  Ã,  Ã,  GetInvName (player.activeinv, bunky);
Ã,  Ã,  Ã,  Ã,  StrCat(texty,bunky);
Ã,  Ã,  Ã,  Ã,  StrCat(texty," with ");
Ã,  Ã,  }
Ã,  Ã,  else if (cursy==5) StrCat(texty, "Pick up ");
Ã,  Ã,  else if (cursy==8) StrCat(texty, "Open ");

Ã,  Ã,  GetLocationName(mouse.x,mouse.y,bunky);
Ã,  Ã,  StrCat(texty,bunky);
Ã,  Ã,  SetLabelText (0,0,texty);

Ã,  Ã,  if (IsGUIOn(1) || IsGUIOn(3) || IsGUIOn(4) || IsGUIOn(INVENTORY)) {
Ã,  Ã,  Ã,  Ã,  SetMouseCursor(6);
Ã,  Ã,  Ã,  Ã,  SetLabelText(0,0, " ");
Ã,  Ã,  }
Ã,  Ã,  else SetDefaultCursor();
}

Edwin Xie

I see what the problem is, some script (probably hard-coded somehow makes the cursors stay that way in GUIs and it would not let it allow it to change. And in that case, I think you should read the Global Script to find any problems. Sorry if there is too much script in this topic.

Code: ags

// main global script file

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
  // called when the game starts, before the first room is loaded
}
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
// LEC Statusline

    string bunky;
    string texty;
    int cursy;

    StrCopy (texty, "");
    cursy=GetCursorMode();

    if (cursy==0) StrCat(texty,"Walk to ");
    else if (cursy==1) StrCat (texty,"Look at ");
    else if (cursy==2) StrCat(texty,"Use ");
    else if (cursy==3) StrCat(texty,"Talk to ");
    else if (cursy==4) {
        StrCat(texty,"Use ");
        GetInvName (player.activeinv, bunky);
        StrCat(texty,bunky);
        StrCat(texty," with ");
    }
    else if (cursy==5) StrCat(texty, "Pick up ");
    else if (cursy==8) StrCat(texty, "Open ");

    GetLocationName(mouse.x,mouse.y,bunky);
    StrCat(texty,bunky);
    SetLabelText (0,0,texty);

    if (IsGUIOn(1) || IsGUIOn(3) || IsGUIOn(4) || IsGUIOn(INVENTORY)) {
        SetMouseCursor(6);
        SetLabelText(0,0, " ");
    }
    else SetDefaultCursor();
} 
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


function show_inventory_window () {
  // This demonstrates both types of inventory window - the first part is how to
  // show the built-in inventory window, the second part uses the custom one.
  // Un-comment one section or the other below.
  
/*  
// ** DEFAULT INVENTORY WINDOW
  InventoryScreen();
*/  
  // ** CUSTOM INVENTORY WINDOW
  GUIOn (INVENTORY);  
  // switch to the Use cursor (to select items with)
  SetCursorMode (MODE_USE);
  // But, override the appearance to look like the arrow
  SetMouseCursor (6);
}

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {
  // called when a key is pressed. keycode holds the key's ASCII code
  if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses
  if (keycode==17)  GUIOn(4);   // Ctrl-Q
  if (keycode==363) SaveGameDialog();   // F5
  if (keycode==365) RestoreGameDialog();  // F7
  if (keycode==367) RestartGame();  // F9
  if (keycode==434) SaveScreenShot("scrnshot.bmp");  // F12
  if (keycode==9)   show_inventory_window();  // Tab, show inventory

  if (keycode==19)  Debug(0,0);  // Ctrl-S, give all inventory
  if (keycode==22)  Debug(1,0);  // Ctrl-V, version
  if (keycode==1)   Debug(2,0);  // Ctrl-A, show walkable areas
  if (keycode==24)  Debug(3,0);  // Ctrl-X, teleport to room
}
#sectionend on_key_press  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(int button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button==LEFT) {
    ProcessClick(mouse.x, mouse.y, GetCursorMode() );
  }
  else {   // right-click, so cycle cursor
    SetNextCursorMode();
  }
}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {

    if (interface == ICONBAR) 
    {
        if (button == 4)    // show inventory
        {
            show_inventory_window();
        }
        else if (button == 5)    // game controls
        {
            InterfaceOff(1);
            SetCursorMode(6);
            InterfaceOn(3);
        }
        else if (button == 6)    // save game
            SaveGameDialog();
        else if (button == 7)   // load game
            RestoreGameDialog();
        else if (button == 8)   // quit
        {
            SetCursorMode(6);
            SetMouseCursor(6);
            DisableCursorMode(0);
            DisableCursorMode(1);
            DisableCursorMode(2);
            DisableCursorMode(3);
            DisableCursorMode(5);
            GUIOn(4);
        }
        else if (button == 9)    // about
            Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");
    }  // end if interface ICONBAR



    if (interface == INVENTORY) // They clicked a button on the Inventory GUI
    {
        if (button == 1) 
        {
            Display("We've just clicked on an arrow button!");
            // They pressed SELECT, so switch to the Get cursor
            SetCursorMode (MODE_USE);
            Display("Changed cursor mode to MODE_USE!");
            // But, override the appearance to look like the arrow
            SetMouseCursor (6);
            Display("Changed cursor appearance to mode 6");
        }


        if (button == 2) 
        {
            // They pressed LOOK, so switch to that mode
            SetActiveInventory(-1);
            SetCursorMode(MODE_LOOK);  
        }

        if (button == 3) 
        {
            // They pressed the OK button, close the GUI
            GUIOff (INVENTORY);
            SetDefaultCursor();
        }

        if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) 
        {
            // scroll down
            game.top_inv_item = game.top_inv_item + game.items_per_line;
        }

        if ((button == 5) && (game.top_inv_item > 0))
        {
            // scroll up
            game.top_inv_item = game.top_inv_item - game.items_per_line;
        }
    }



    CentreGUI(3);

    if (interface == 3)
    {
        if (button ==  8) SetGameSpeed(GetSliderValue(3,8));
        if (button ==  9) SetMusicMasterVolume(GetSliderValue(3,9));
        if (button == 10) game.text_speed = GetSliderValue(3,10);
        if (button ==  0) SaveGameDialog();
        if (button ==  1) RestoreGameDialog();
        if (button ==  2) GUIOn(4);
        if (button ==  3)
        {
            SetCursorMode(6);
            RestartGame();
        }
        if (button == 4) 
            Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");

        if (button == 11)
        {
            InterfaceOff (3);
            InterfaceOn (ICONBAR);
            SetCursorMode (1);
        }
    }



    if (interface == 4) 
    {
       if (button == 0)  QuitGame(0);
       if (button == 1) {
           GUIOff(4);
           EnableCursorMode(0);
           EnableCursorMode(1);
           EnableCursorMode(2);
           EnableCursorMode(3);
           EnableCursorMode(5);
           SetCursorMode(0);
       }

    }

}

#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE

Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

monkey0506

#34
Quote
Code: ags
if (interface == 3)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  8) SetGameSpeed(GetSliderValue(3,8));
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  9) SetMusicMasterVolume(GetSliderValue(3,9));
Ã,  Ã,  Ã,  Ã,  if (button == 10) game.text_speed = GetSliderValue(3,10);
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  0) SaveGameDialog();
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  1) RestoreGameDialog();
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  2) GUIOn(4);
Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  3)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  RestartGame();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  if (button == 4) 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");


 if (interface == 4) 
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã, if (button == 0)Ã,  QuitGame(0);
Ã,  Ã,  Ã,  Ã, if (button == 1) {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, GUIOff(4);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(1);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(3);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, EnableCursorMode(5);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, SetCursorMode(0);
Ã,  Ã,  Ã,  Ã, }


I'm pretty sure you should be using else if statements here. i.e.:

Code: ags

Ã,  Ã,  Ã,  Ã,  if (button ==Ã,  8) SetGameSpeed(GetSliderValue(3,8));
Ã,  Ã,  Ã,  Ã,  else if (button ==Ã,  9) SetMusicMasterVolume(GetSliderValue(3,9));
Ã,  Ã,  Ã,  Ã,  else if (button == 10) game.text_speed = GetSliderValue(3,10);
Ã,  Ã,  Ã,  Ã,  else if (button ==Ã,  0) SaveGameDialog();
Ã,  Ã,  Ã,  Ã,  else if (button ==Ã,  1) RestoreGameDialog();
Ã,  Ã,  Ã,  Ã,  else if (button ==Ã,  2) GUIOn(4);
Ã,  Ã,  Ã,  Ã,  else if (button ==Ã,  3)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetCursorMode(6);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  RestartGame();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else if (button == 4) Display("The Adventures of Bob I [[Made with Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2004 Chris Jones");


I'm pretty sure...

EDIT: Also,
if (interface==ICONBAR){
//bleh
}
else if (interface==INVENTORY){
//bleh
}
else if (interface==3){
//bleh
}
else if (interface==4){
//bleh
}

Scorpiorus

I couldn't see anything wrong with the main global script and decided to test it in AGS. And it worked fine for me. Can you post a script of the room you are in when operating with GUIs?

How large is your game? Can you upload it (or send to me) so I could take a look?

monkey0506

So do you NOT have to use else if statements? I thought it wouldn't work right without else if statements... Ok...

Scorpiorus

Quote from: monkey_05_06 on Sun 12/09/2004 20:55:10
So do you NOT have to use else if statements? I thought it wouldn't work right without else if statements... Ok...
Yep, usually it's a good idea to have elseifs since without them nasty things can happen, like:

if (x=1) {Display("1"); x++;}
if (x=2) {Display("2"); x++;}
if (x=3) {Display("3"); x++;}

In this case (if x initially is 1) all three Display commands will be run because x is increased to the next value.

Using elseifs sorts it out:

if (x=1) {Display("1"); x++;}
Ã,  Ã,  else if (x=2) {Display("2"); x++;}
Ã,  Ã,  Ã,  Ã,  else if (x=3) {Display("3"); x++;}

They are nested and thus only a single Display is called.

Provided, however, you don't change variables that are used to check the condition, you can do without elseifs. Both "interface" and "button" are not to change within the interface_click function so it's not really a problem here. But, yes, using elseifs is considered to be a good programming practice since it not only helps to avoid logical mistakes but also can save some processor time.

Edwin Xie

Gee, the part you quoted monkey_05_06, Scorpiorus did that part. And I believe the part that has been messing my things up was the part where there is the "load", "play" and "quit", so I will show it to you, and possibly the otehr room scripts.

Load/Play/Quit Room Script:
[code}
// room script file

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for room: Player enters screen (before fadein)
//change mouse to the 'pointer' cursor and also, this might have been the problem
DisableCursorMode(0);
DisableCursorMode(1); 
DisableCursorMode(2);
DisableCursorMode(3);
DisableCursorMode(4);
DisableCursorMode(5);
DisableCursorMode(7);
DisableCursorMode(8);
DisableCursorMode(9);
DisableCursorMode(10);
SetMouseCursor(6);
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot2_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot2_a() {
  // script for hotspot2: Any click on hotspot
RestoreGameDialog();   
}
#sectionend hotspot2_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot3_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot3_a() {
  // script for hotspot3: Any click on hotspot
GUIOn(4); 
}
#sectionend hotspot3_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for room: Player leaves screen
InterfaceOn(0);
InterfaceOn(1);
SetLabelText (0,0,"  ");
}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE
Code: ags


I believe the problem was at the disable cursor mode part. Also, it was supposed to be at cursor 6 but somehow it started at cursor 5.

Here's the other room scripts (which they should be fine) but room 1 has a script that is linked to room load/play/quit and it works fine, probable a problem to others though and ignore the score part:

Room 1:

function room_a() {
  // script for room: Player enters screen (before fadein)
GiveScore(100);
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot1_a() {
  // script for hotspot1: Use inventory on hotspot
SetLabelText (0,0,"Walk to @OVERHOTSPOT@"); 
}
#sectionend hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for room: First time player enters screen
EnableCursorMode(0);
EnableCursorMode(1);
EnableCursorMode(2);
EnableCursorMode(3);
EnableCursorMode(4);
EnableCursorMode(5);
EnableCursorMode(6);
SetCursorMode(MODE_WALK); 
}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE
Code: ags

Room 2 should be fine since this room has absolutely not script because the room script is empty :P.

Anyway, if you want to know more on what game this script is for, find "The Adventures of Bob I" in the Games in Production forum, the screenshot is from room 2.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Scorpiorus

Hmm, strange. By the way, what if you comment out the "else SetDefaultCursor();" line inside the repeatedly_execute function, does a cursor still change to the hand image when you press that GUI button?

SMF spam blocked by CleanTalk