Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Mon 03/01/2011 17:59:28

Title: SOLVED: GUI button code problem
Post by: barefoot on Mon 03/01/2011 17:59:28
Hi

Ive started to have a few problems with the following GUI.. particularly with the button GUI that opens them up.

Could someone please check below code and see where i may have errored...

At the moment a gui comes up when no clue is found... ie the else statement..


function Button7_OnClick(GUIControl *control, MouseButton button)
{

 
  if (player.HasInventory(ihair)) {
   ghair.Visible=true;
    gdocs.Visible=false;
}
 if (player.HasInventory(idoc)) {
   gdocs.Visible=true;
    ghair.Visible=false;
   
}


 if(player.HasInventory(ihair)&& player.HasInventory(idoc)){
   ghair.Visible=false;
    gdocs.Visible=false;
     ghairdoc.Visible=true;
 
}



   if(player.HasInventory(iphoto)){
     gprofile.Visible=true;

 
 
 
   }

    if(player.HasInventory(idisguise)){
       gdablodis.Visible=true;
 
 
  }

    if(player.HasInventory(icordainates)){
       gcords.Visible=true;
 
 }
 
 
  if(player.HasInventory(idisguise)&& player.HasInventory(icordainates)){
   gcorddisguise.Visible=true;
   
   
   
   }
 
 
  if(player.HasInventory(iphoto)){
   gcorddisguise.Visible=true;
   
   
      }
 
 
  if(player.HasInventory(idis)){
   gbossdiss.Visible=true;
   
   
     }
 
 
  if(player.HasInventory(iprint)){
   gprints.Visible=true;
 
 
 
   }
 
 
  if(player.HasInventory(inote2)){
   gprofnote.Visible=true;
 
 
 
}

 else { gnotepad.Visible=true;

}

}


Cheers if someone could check for me..

barefoot



Title: Re: GUI button code problem
Post by: Matti on Mon 03/01/2011 18:11:09
Currently your else statement is called whenever this isn't true:


if(player.HasInventory(inote2)){
  gprofnote.Visible=true;
}


Everything else isn't taken into account. Instead of


if..
if..
if..
if..
else..


you need to use "else if":


if..
else if..
else if..
else if..
else..


I don't know if that is your problem, but it seems to be.
Title: Re: GUI button code problem
Post by: barefoot on Mon 03/01/2011 18:22:59
That sounds logical Matti.. guess  im going senile..  :=

just trying to get this bit right at the end:


}
    else {
gnotepad1.Visible=true;

}
}


barefoot