Super Short Scripts

From Adventure Game Studio | Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article is a stub.
You can help by expanding it.

Foreword

Welcome to the Super Short Scripts wikipage. This is meant as a place to put extremely easy scripts, that anyone could write. Hopefully, beginners will be able to come to this page and understand scripting better by reading easy and well-documented scripts.

Requirements

To keep this page clean, I propose a few requirements:

  1. State the purpose of the function or script and where it could be used.
  2. Well-named functions and variables should reflect their purposes.
  3. Comment and explain each necessary line.
  4. Feel free to sign the scripts you add with the three tilde notation (~~~).

Scripts

Generic Look At Inventory

Added by laboheme.
Instead of writing a Look Interaction for all of your inventory items, this function will display the item's Description property as set in the Properties Pane. Just remember to set the 'Look at inventory item' event to i_Look for each inventory item.

 function i_Look()  {  //Naming convention follows the default iInvItem_Look interaction that is generated when you click the ellipsis button.
   InventoryItem *iL;  //Creates a Pointer to an inventory item, placed inside the function
   iL = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);   //Gets the item at the mouse location and stores it in the iL pointer.
   Display("%s",iL.Name);  //This is called Description when editing your item, but is called Name for scripting
 }



Toggle All GUIs

Posted on forums by matt. Cleaned and added by laboheme.
Allows you to toggle all of your GUIs' visibility off at once. Although most likely not used, you can also use it to toggle all of the GUIs on.

 function ToggleAllGUIs (bool visible) {
   int guis = Game.GUICount;  //Gets the count of all GUIs in the game, but remember that it also counts GUI 0
   int cgui = 0; //Short for Current Gui, used in the while loop
   while (cgui < guis) {  //Has to be less than, otherwise it will return an out of bounds
     gui[cgui].Visible = visible;  //Uses the GUI array to toggle the visibility of the current GUI
     cgui++;   //Increments to the next GUI
   }
 }



Catch-All Yes/No

Posted on forums by Akumayo. Added by laboheme.
A nice little function that works as a replacement for Yes/No GUI's and such, and works much faster/easier. It's a simple solution for idiot-proofing or double-checking.

In global script top:

 function YesOrNo() {
   Display("Yes (y) or No (n)");
   if (IsKeyPressed(89) == 1 || IsKeyPressed(78) == 1) {
     if (IsKeyPressed(89) == 1) {
       return 1;
     }
     if (IsKeyPressed(78) == 1) {
       return 0;
     }
   }
   else {
     Display("You have to pick one!");
     YesOrNo();
   } 
 }

In global script header:

 import function YesOrNo();

Example of use:

 Display("Do you really want to steal that hat?");
 int stealit = YesOrNo();
 if (stealit == 1) {
   Display("You steal the hat.");
   player.AddInventory(ihat);
   karma --; 
 }
 else {
   Display("You decide not to steal the hat, because your a good person.");
   karma ++; 
 }
 Will ask the player if they want to steal the hat, make them click 'y' or 'n' to answer, and take action depending on that answer.