GUIOff

Started by Sewer Agent, Fri 18/02/2005 16:11:12

Previous topic - Next topic

Sewer Agent

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.

Ishmael

Could you post the bits of script you've used?
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Sewer Agent

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

}

Ishmael

#3


   {
   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
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Sewer Agent

It just says unexpected "}" when I test the game. I think I will have to start from scratch lol!

strazer

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:

Code: ags

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

	}

}

Sewer Agent

#6
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.

strazer

#7
Me too. Use the [ code ] tag to preserve them when posting here.
Try the code I have provided.

Edit:

Don't do

Code: ags

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


but

Code: ags

	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.

Sewer Agent

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.

RickJ

#9
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

Ishmael

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");
  }
}
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

RickJ

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

SMF spam blocked by CleanTalk