Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Brian925 on Mon 16/01/2023 18:33:10

Title: Code not fading transparency, anything obvious about my code?
Post by: Brian925 on Mon 16/01/2023 18:33:10
I'm trying to fade in a GUI and I'm not sure if how it's embedded is getting in the way. I was also curious if having the GUI set to "pause game when shown" would cause the fade not to happen. I got the code to work for everything except the fading part until I started messing with the brackets and getting errors. Thanks for looking.

function btnInvOK_Click(GUIControl *control, MouseButton button) {
// They pressed the OK button, close the GUI. Everything should always be set to invisible.
gInventory.Visible = false; //Makes overlay Inventory GUI close
  gIconbar.Visible=true; //restores visibility of Top Bar GUI
  gIconbar.Clickable=true; //restores functionality of Top Bar GUI
 
  if(onmega == 1) {
  gGB1.Visible=false;
  else //GETTING A PARSE ERROR HERE AT 'ELSE'
  gGB1.Visible=false;}
   
  if(podtoinventory == 1){
  gGIOPod1.Visible=false;
  else
  gGIOPod1.Visible=false;}
 
  if (blend1done == 1){
  gAnn1000.Visible=false;}
  else
  if(blendglovematch==1){
  Wait(20);
  gAnn1000.Visible=true;}
  int trans2 = gAnn1000.Transparency;
  while (trans2 > 0){
  trans2--;
  gAnn1000.Transparency = trans2;}
  Wait(1);
 
  else
  gAnn1000.Visible=false;
  gArena.Visible=false;
  mouse.Mode=eModeInteract;
 }
Title: Re: Code not fading transparency, anything obvious about my code?
Post by: newwaveburritos on Mon 16/01/2023 19:02:24
I think formatting the code so that it's easier to read the if/else statements.  I personally am having trouble following where these begin and end.  I'm also not sure what these variables are but I can say that this:

Code (AGS) Select
  int trans2 = gAnn1000.Transparency;

  while (trans2 > 0){
     trans2--;
     gAnn1000.Transparency = trans2;}
     Wait(1);

won't work because the Wait(1) is outside the while statement.  I think cleaning up the brackets with help you read it and figure out where it's going wrong.

Code (AGS) Select
  int trans2 = gAnn1000.Transparency;

  while (trans2 > 0){
    trans2--;
    gAnn1000.Transparency = trans2;
    Wait(1);
  }
Title: Re: Code not fading transparency, anything obvious about my code?
Post by: Matti on Mon 16/01/2023 19:30:28
Quote from: newwaveburritos on Mon 16/01/2023 19:02:24won't work because the Wait(1) is outside the while statement.

I also think that this is the problem.

You already fixed this in the first code you posted though (making both codes in your post identical), which is a bit confusing  ;)
Title: Re: Code not fading transparency, anything obvious about my code?
Post by: Snarky on Mon 16/01/2023 19:55:20
(Used mod powers to unfix the first code block in @newwaveburritos's post so the problem appears.)
Title: Re: Code not fading transparency, anything obvious about my code?
Post by: Khris on Mon 16/01/2023 20:43:11
You have
  if(onmega == 1) {
  gGB1.Visible=false;
  else //GETTING A PARSE ERROR HERE AT 'ELSE'
  gGB1.Visible=false;}
First of all, the proper syntax is
if (condition) statement/block
else statement/block


A block is multiple statements grouped together, it starts with a { and ends with a }. You've put "else" *inside* the first block instead of behind it.

Next, you're doing the same thing regardless of the outcome of the test. You probably meant to use "true" instead of "false" in one of the two lines.

Finally, setting a single variable to true or false based on the outcome of a conditional check doesn't require an if/else statement in the first place. You can simply do:

  gGB1.Visible = onmega != 1;The right side will evaluate to true or false already, so you can directly use that to set the .Visible property.