Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: SilverWizard_OTF on Sun 22/08/2004 21:37:24

Title: Gui script
Post by: SilverWizard_OTF on Sun 22/08/2004 21:37:24
I made a gui called INTRO, and i have inserted this code (edit script  gui's window).

{
    if(interface==INTRO) {
      if(button==0) {
        do_dance();
        }
      }
Where do_dance() is a function that i made.

The problem is: When i go to test my game, it gives an error:
        "There was an error compiling your script. The problem was in main script.  Error(Line 80):  Already referenced name as import"

After that, when i click yes (i want to fix the script) it goes me to the Global Script, where is my function do_dance().

I can't understand why is this happening. It happens ONLY if i insert the code that i mentioned before. (Gui script).

Thanks for your time
Title: Re: Gui script
Post by: strazer on Sun 22/08/2004 22:09:45
Try putting the do_dance function at the top of the global script, before all others.
Title: Re: Gui script
Post by: SilverWizard_OTF on Mon 23/08/2004 10:37:54
Thanks, that worked.
Hey,  by the way, i have created a Gui but when i say to be revealed (It is GuiOff at start), then it is dissappeared immediately. Why is that  happening?
Title: Re: Gui script
Post by: strazer on Mon 23/08/2004 15:49:48
Glad it worked.
I think the error message "Already referenced name as import" could be more intuitive. Chris?

As for your second problem, you say the GUI disappears immediately. Do you see it before it disappears? If not, are you sure it is shown at all?
What code are you using and where did you put it?
Title: Re: Gui script
Post by: SilverWizard_OTF on Mon 23/08/2004 20:42:58
Actually, i have just created a new Gui (with some buttons) and i  adjusted it as visible.
When the game starts (before fade in) i say: GuiOff( //this Gui).
And when i want to appear it again, i say: GuiOn.
   Actually i want to Pause the game when this Gui will be revealed, and Unpaused, when it will be turned off. Of course, when the game is paused, i want to be able to interact with gui buttons. How can i do that?

Thanks for your help
Title: Re: Gui script
Post by: Pumaman on Mon 23/08/2004 20:49:54
If the GUI is set as Popup Modal, it will pause the game automatically when turned on.

As for that earlier error message, I agree that it could be more intuitive so I'll reword it for the next version.
Title: Re: Gui script
Post by: SilverWizard_OTF on Mon 23/08/2004 20:51:10
Just one question: Could you add a Go to command? I think it would be REALLY useful.
Title: Re: Gui script
Post by: Gilbert on Tue 24/08/2004 02:49:28
I think a goto command can cause more troubles than convenient, it may not work good under function oriented languages (C-style) in my opinion.
Title: Re: Gui script
Post by: SilverWizard_OTF on Tue 24/08/2004 19:42:09
after fade in:

string name;
InputBox("Your name is", name);
//other things
Let's say that i want to have an error message when player will set e.g. numbers than a name and then to be returned to start, to type his name.

Can you do that without a go to command?
Title: Re: Gui script
Post by: Rui 'Trovatore' Pires on Tue 24/08/2004 20:14:16
You can get around it by making your own costum GUI instead of InputBox and then checking if the textbox's data is valid, and if so proceed to the next thing.
Title: Re: Gui script
Post by: Ashen on Tue 24/08/2004 20:21:20
And / or use a combination of StrContains Ã, and Run(object/hotspot/character/inventory)Interaction commands, e.g.

Ã, // script for object2: Talk to object
string name;
InputBox ("Name?", name);
if (NumCheck (name) == 1){
Ã, Display ("Hi, %s!", name); // No numbers, so run script
Ã, // other things
}
else { // Numbers, so run error script
Ã, Display ("No numbers");
Ã, RunObjectInteraction (2, MODE_TALK); // Starts script running again
}

Where NumCheck is a custom function that checks the input for numbers. Looks something like this:


function NumCheck (string input) {
Ã, if (StrContains (input, "0") != -1) return 0; // Returns 0 if 0 is in line
Ã, else if (StrContains (input, "1") != -1) return 0; // Returns 0 if 1 is in line
Ã, else if (StrContains (input, "2") != -1) return 0; // Returns 0 if 2 is in line
Ã, else if (StrContains (input, "3") != -1) return 0; // Returns 0 if 3 is in line
Ã, else if (StrContains (input, "4") != -1) return 0; // Returns 0 if 4 is in line
Ã, else if (StrContains (input, "5") != -1) return 0; // Returns 0 if 5 is in line
Ã, else if (StrContains (input, "6") != -1) return 0; // Returns 0 if 6 is in line
Ã, else if (StrContains (input, "7") != -1) return 0; // Returns 0 if 7 is in line
Ã, else if (StrContains (input, "8") != -1) return 0; // Returns 0 if 8 is in line
Ã, else if (StrContains (input, "9") != -1) return 0; // Returns 0 if 9 is in line
Ã, else return 1; // No numbers, so return 1
}


Although there may be a more elegant way to search for all numbers at once.
Works for me, anyway. Feel free to use it if it's any good for you.
Title: Re: Gui script
Post by: SilverWizard_OTF on Wed 25/08/2004 13:10:19
Thank you, your help was very valuable!
I agree with you, there many ways to do something. However, it isn't bad to  include as much as it can to AGS (even if it is a Go to script command!). Maybe SOMEONE in a very SPECIAL case, needs something like that.
ReDrum, thanks for your idea. And Ashen, thanks for your code.