Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Sewer Agent on Fri 18/02/2005 16:11:12

Title: GUIOff
Post by: Sewer Agent on Fri 18/02/2005 16:11:12
Now I have no idea why my program is doing this but it is. I made a third GUI for my game known as the options screen. I told the save button to save and the load button to restore e.t.c but it didn't work and instead of the options menu doing this the buttons on one of my other GUI's did this. Then I deleted the options screen and it was fine. So I have decided to leave that alone for the moment but for some reason, on my inventory screen, the GUIOff command doesn't work! It just doesn't work. I've put it onto other buttons and tried to use it on them but it just doesn't work. I was wondering if anyone could help.

Thanks.
Title: Re: GUIOff
Post by: Ishmael on Fri 18/02/2005 16:17:01
Could you post the bits of script you've used?
Title: Re: GUIOff
Post by: Sewer Agent on Fri 18/02/2005 16:19:23
Here's what I have at the moment:.

{
  if (interface == ICONBAR)     
{
   {
        //Walk.
   if (button == 0)
   SetCursorMode(0);
   }
   
   {
        //Look.
   if (button == 1)
   SetCursorMode(1);
   }
   
   {
   if (button == 2)
   SetCursorMode(2);
   }
   
   {
   if (button == 3)
   SetCursorMode(3);
   }
   
   {
   if (button == 4)
   // show inventory
   GUIOn (INVENTORY);
   }

   if (interface == INVENTORY)
{
    // They clicked a button on the Inventory GUI
   
    if (button == 2)
   {
   GUIOff (INVENTORY);
   }

    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;
   }
}

}
Title: Re: GUIOff
Post by: Ishmael on Fri 18/02/2005 16:37:46


   {
   if (button == 4)
   // show inventory
   GUIOn (INVENTORY);
   }
}
   if (interface == INVENTORY)
{



Seems to be missing a bracket atleast, I couldn't find nothing else...

----- EDIT -----

On a completely unrelated note, this was my 2000th post on the forums :D
Title: Re: GUIOff
Post by: Sewer Agent on Fri 18/02/2005 16:41:27
It just says unexpected "}" when I test the game. I think I will have to start from scratch lol!
Title: Re: GUIOff
Post by: strazer on Fri 18/02/2005 16:42:51
Yes, you didn't close the first interface part, therefore nesting the second interface part in the first one.
Try to indent your code properly, so it's more readable:


function interface_click (int interface, int button)
{
if (interface == ICONBAR)
{
if (button == 0)
    {
//Walk.
SetCursorMode(0);
}
   
if (button == 1)
{
//Look.
SetCursorMode(1);
}
   
if (button == 2)
{
SetCursorMode(2);
}
   
if (button == 3)
{
SetCursorMode(3);
}
   
if (button == 4)
{
// show inventory
GUIOn (INVENTORY);
}

}


// They clicked a button on the Inventory GUI
if (interface == INVENTORY)
{
   
if (button == 2)
{
GUIOff (INVENTORY);
}

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;
}

}

}
Title: Re: GUIOff
Post by: Sewer Agent on Fri 18/02/2005 16:45:03
I have indented the code via the tab key.

Ish I tried it again and it works (I had another } at the wrong point lol!). Thanks all.
Title: Re: GUIOff
Post by: strazer on Fri 18/02/2005 16:46:41
Me too. Use the [ code ] tag to preserve them when posting here.
Try the code I have provided.

Edit:

Don't do


{
if (button == 2)
SetCursorMode(2);
}


but


if (button == 2)
{
SetCursorMode(2);
}


otherwise only the first line after the if-clause gets executed if the expression is true.   

Edit 2:

Of course, if you only have one line anyway, you don't necessarily need the brackets, but I always use them in case I add something later so I don't forget to add them.
Title: Re: GUIOff
Post by: Sewer Agent on Fri 18/02/2005 16:47:32
Ish was right, as were you. The problem was I had another } at the end and so it wasn't working! Thanks again.

Is taht how you do the code?! Now I know, thanks.
Title: Re: GUIOff
Post by: RickJ on Sat 19/02/2005 10:12:55
I always enter the braces in matching pairs.  For example if I write "{" then I immediately put "}" on the next line.  After that I then fill-in code between the two matching braces.  Just get in the habit of doing it that way and you will hardly ever have a mis-matched brace problems.   If you think it takes too long to hit the Home and UpArrow keys, just think how long and hard it is to find a mis-matched brace.  ;)

*** Edit *** spelling
Title: Re: GUIOff
Post by: Ishmael on Sat 19/02/2005 10:38:35
I always put braces on the matching if, else or function lines, that way I can keep up with them... I don't like the way the braces are layed out in the new template :( It confuses me...

function doBlah(int which) {
  if (which == 0) {
    DisplaySpeech(EGO,"Blah");
  } else if (which == 1) {
    DisplaySpeech(EGO,"BLAH!");
  } else {
    DisplaySpeech(EGO,"Bleh");
  }
}
Title: Re: GUIOff
Post by: RickJ on Sat 19/02/2005 11:22:25
Ishmael,

I currently do the same as you and have done it Strazer's way in the past.  Strazer's way is probably better for beginners, however it is mostly a matter of personal preference.  In either case, I still enter braces in pairs so that they are always matched.  The only time I have any possibility of errors is when clipping stuff out of existing code.   Entering new code for me is virtually error free, with regard to mismatched braces.   Getting new code to do what I want is another matter entirely.  ;D