GUI Visability Parse problem

Started by Ostyster, Thu 04/08/2016 00:07:59

Previous topic - Next topic

Ostyster

I want to make a GUI invinsible while other GUI's are shown and i tried

Code: ags

if ((gInventory.Visible = true) ||
      (gPanel.Visible = true) ||
      (gSaveGame.Visible = true) ||
      (gRestoreGame.Visible = true) ||
      (gRestartYN.Visible = true) )
  {
    gTextbox.Visible = false;
  }
  else
  {
    gTextbox.Visible = true;
  }


But if i want to run the game an error shows up saying:
Parse error in expr near 'gInventory'

I don't know what the problem is.
Please help me with my code or give me an alternative.

Crimson Wizard

This is simple, when you are writing conditions, equality check is done with "==", not "=".

"=" - is assignment, like "make X be 5".
"==" - is equality check operator "check that X equals to Y".

Ostyster

Thanks there is no error anymore but sadly the box doesn't get invisible

Crimson Wizard

Quote from: Ostyster on Thu 04/08/2016 00:33:44
Thanks there is no error anymore but sadly the box doesn't get invisible
That really depends on something else then. Like, where is this particular piece of code located in script, and does it gets called at all?

Ostyster

Ok i got it to work.
you hve to put this under "function repeatedly_execute() {"

Code: ags

 if ((gInventory.Visible == true) ||
    (gPanel.Visible == true) ||
    (gSaveGame.Visible == true) ||
    (gRestoreGame.Visible == true) ||
 (gRestartYN.Visible == true))
 {
    gTextbox.Visible = false;
 }
 else
 {
    gTextbox.Visible = true;


Then the GUI Textbox gets displayed while walking around but not when any other GUI (exept iconbar) is visible.

Matti

Btw, you don't need that many brackets and the "== true" isn't necessary. So you could write it like this:

Code: ags

if (gInventory.Visible ||
    gPanel.Visible ||
    gSaveGame.Visible ||
    gRestoreGame.Visible ||
    gRestartYN.Visible)

    gTextbox.Visible = false;

else gTextbox.Visible = true;

Crimson Wizard

#6
Quote from: Matti on Thu 04/08/2016 15:49:45
Btw, you don't need that many brackets and the "== true" isn't necessary. So you could write it like this:

Code: ags

if (gInventory.Visible ||
    gPanel.Visible ||
    gSaveGame.Visible ||
    gRestoreGame.Visible ||
    gRestartYN.Visible)

    gTextbox.Visible = false;

else gTextbox.Visible = true;


While I agree on what you did to simplify condition, I cannot agree with curvy brackets removal and putting "gTextbox.Visible = true" on same line with "else". Firstly, such things are related to chosen coding style, on other hand with multiline condition like that I find Ostyster's original code much easier to read.

Khris

Ok then :-D
Code: ags
gTextbox.Visible = !(gInventory.Visible || gPanel.Visible || gSaveGame.Visible || gRestoreGame.Visible || gRestartYN.Visible);

SMF spam blocked by CleanTalk