Fading in GUI not working?[SOLVED]

Started by T800System, Tue 08/01/2013 23:58:11

Previous topic - Next topic

T800System

Me again :X Sorry, but I'm having trouble with getting my GUI to fade in?

I'm using this line:

int trans = gInventory.Transparency;
while (trans < 100) {
  trans++;
  gInventory.Transparency = trans;
  Wait(1);
}

(with amended gInventory to correspond with my GUI name)

Every time I try to test it, the game won't load and says there's a compilation error. "Expected integer value after "=""

Thing is, when I put a number after the "=" it still won't work, and says that it expected a "," or ";" and not "gInventory". So, I try both a "," and a ";" - and still, no dice. It just says "unexpected gInventory" after that.

Can anyone enlighten me as to what I'm doing wrong here? Thanks :Z

Ghost

#1
Code: ags

gMainTitle.Transparency = 100;
int trans = gMainTitle.Transparency;
while (trans > 0)
{
	trans--;
	gMainTitle.Transparency = trans;
	Wait(1);
}

This is code from a WiP of mine, and it compiles and works perfectly- almost the same as your code.

For transparency, 0 is "fully visible" and 100 is "totally invisible", so to fade the GUI IN you must set its transparency to 100, though this doesn't explain why your code doesn't compile...

T800System

Quote from: Ghost on Wed 09/01/2013 00:15:03
Code: ags

gMainTitle.Transparency = 100;
int trans = gMainTitle.Transparency;
while (trans > 0)
{
	trans--;
	gMainTitle.Transparency = trans;
	Wait(1);
}

This is code from a WiP of mine, and it compiles and works perfectly- almost the same as your code.

For transparency, 0 is "fully visible" and 100 is "totally invisible", so to fade the GUI IN you must set its transparency to 100, though this doesn't explain why your code doesn't compile...

Interesting, I will try this.

This may be a stupid question, but I'm a noob to AGS and so I'm entitled to ask it :P Where am I supposed to be putting this code? In the room script file or the global script?

Ghost

That depends. Do you want to use this code repeatedly, for example whenever the player clicks an "open inv button"? Then it would go into the global script, probably as a function of its own:

Code: ags

function OpenInventory()
{
    // code
}


This will allow you to call the function from anywhere (from other functions in GlobalScript AND from rooms AND from other script files).

Room scripts are specific to a room- so you could put it there, but then only call it in that very room- relatively useless.  ;)

T800System

Quote from: Ghost on Wed 09/01/2013 00:34:54
That depends. Do you want to use this code repeatedly, for example whenever the player clicks an "open inv button"? Then it would go into the global script, probably as a function of its own:

Code: ags

function OpenInventory()
{
    // code
}


This will allow you to call the function from anywhere (from other functions in GlobalScript AND from rooms AND from other script files).

Room scripts are specific to a room- so you could put it there, but then only call it in that very room- relatively useless.  ;)

I want it to come on every time the player is presented with dialog option. My dialog options are presented using a GUI, so I want them to fade in. Does this code need to be part of a function then?

Ghost

Yes. Open your global script, and somewhere at the top create the OpenInventory() function. It doesn't really matter where you put it, but any function that uses OpenInventory() must be below!

Think of a function as a "building block". You want to keep them simple in order to build something larger from them. With a function that opens the inventory, you can re-use it over and over. If you later decide to add a different fading effect or use an altogether different GUI, you only need to change your code ONCE (in the function).

AGS uses event handlers for when buttons are clicked or a dialog starts. You can put any code into an event handler. So just set up your dialog GUI, create your options, set up the proper event handlers, and then call your "OpenInventory()" from there.

This is pretty basic stuff but it'll get you a long way.  (nod)

T800System

Quote from: Ghost on Wed 09/01/2013 01:00:22
Yes. Open your global script, and somewhere at the top create the OpenInventory() function. It doesn't really matter where you put it, but any function that uses OpenInventory() must be below!

Think of a function as a "building block". You want to keep them simple in order to build something larger from them. With a function that opens the inventory, you can re-use it over and over. If you later decide to add a different fading effect or use an altogether different GUI, you only need to change your code ONCE (in the function).

AGS uses event handlers for when buttons are clicked or a dialog starts. You can put any code into an event handler. So just set up your dialog GUI, create your options, set up the proper event handlers, and then call your "OpenInventory()" from there.

This is pretty basic stuff but it'll get you a long way.  (nod)

Sorry, I still don't understand :P Are you just using OpenInventory() as an example? I don't see how getting a GUI to fade in has anything to do with opening an inventory? O.o

I applaud you for taking the time to explain it to me, but could you perhaps explain it again - this time as if it was to someone with no history of scripting? :P

Matt Frith

The Tween module makes all this stuff very trivial.  Whenever I start a new game project, importing this module is the first thing I will do.  If you don't know how to import modules simply find the scripts tab in AGS, right click and select 'import script' and then select the file from wherever you've downloaded it to.

You could achieve what you want in one line of code.  For example,
Code: AGS
gInventory.TweenTransparency(2.5,0,eLinearTween,eNoBlockTween)[/b]


Ghost

Okay, you called your GUI gInventory. So I assumed it would have an inventory window on it- that's pretty common, to name a GUI after what it does. And in that case fading in gInventory would be the same as "opening the player's inventory".
If you're talking about your dialog options, I wonder why you'd use a GUI when you can use AGS's build-in dialog display? Is that what you're doing, making your own dialog system?

GUIs and understanding scripting are extremely important. I suggest you have a look at a set of tutorials a fellow AGSer posted on YouTube- they explain with some depth almost anything you will need to make your first little game (they are better than the manual's tutorial in my opinion).
Start here -> http://www.youtube.com/watch?v=1Ml_DR76Cl4


Khris

T800Sytem:
First of all, please don't needlessly quote the entire previous post; there's a Reply button at the bottom (or the option to remove the quote from the text field before posting). Quoting is a way to address a specific statement and will only clutter up the thread visually if (ab)used like you do.

Now, as for where code goes, room specific code goes into room scripts and all other code goes into the global script. Furthermore, like Ghost said, everything except variable declarations must be inside a function block so AGS knows when to call it.
Imagine you're adding the interaction code lines for twelve room objects and simply write them one after another into the room script. How would AGS know when to call which lines?
As is explained in Part 3 of the manual's tutorial, you have to link an event to a function and put the code in there.

Unfortunately, there's no way to automatically fade in the GUI right before a dialog is started. What you have to do is put the code in a custom function in the global script, import the function in the global header, then call it every time you are starting a dialog in script.

So, let's assume you have created a new Dialog GUI, set its name to "gDialog" in its properties, its Visibility to "Normal, initially off" and have set the GUI as dialog GUI in General Settings -> Dialog -> Use GUI for dialog options.

Add this to the top of the global script:
Code: ags
// fade Dialog GUI in / out
void FadeDialogGUI(bool in) {
  int i = in * 100;
  int speed = 2;
  gDialog.Transparency = i;
  gDialog.Visible = true;
  while (i != !in * 100) {
    i = i - in*speed + !in*speed;
    if (i < 0) i = 0;
    if (i > 100) i = 100;
    gDialog.Transparency = i;
    Wait(1);
  }
  game.dialog_options_x = 5;
  game.dialog_options_y = 5;
}


And this to GlobalScript.ash:
Code: ags
import void FadeDialogGUI(bool in);


Call a dialog:
Code: ags
  FadeDialogGUI(true);
  dDialog0.Start();

In the dialog script, at the end:
Code: ags
  FadeDialogGUI(false);
stop


Tested, working.

monkey0506

If you use the custom dialog rendering functions (probably more advanced than T800 is ready for yet) then you can use dialog_options_get_dimensions to indicate that a dialog is being started and repeatedly_execute to indicate that it has ended.

Khris

Right, I was thinking of doing the fade in there but for some reason didn't think it would work, don't know why.

T800System

Sorry about the quoting, it's common practice at a lot of other forums I've used but I will make sure not to do it here.

Thanks a lot for taking the time to help me, Khris. I tried that code and it does indeed work. I think I had best have another read of the manual - hopefully I won't need to script anything as tricky as this for a while though.

oh & @ Ghost: yeah, I've watched most of densming's tutorial videos and I found them to be very helpful, but really they only cover the basic features. I am trying to not get ahead of myself and just stick to the basics. I'm sure you can appreciate that when you're new to the program and you want to script something like GUI fade-ins, it can be quite daunting - and I wasn't having much luck doing it myself, even after trawling through dozens of older forum posts and the manual - so that's why I made this thread. But you have all succeeded in helping me and it is working now, so many thanks for that :)

SMF spam blocked by CleanTalk