Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sun 11/04/2010 13:47:43

Title: Item containers
Post by: Gepard on Sun 11/04/2010 13:47:43
I have the following script in "while player stands on region":

if (IsKeyPressed(83)==1) { //while key "S" is pressed
  gObsah.Visible = true; //simple gui shows up...
     container.Text = "container:"; //...with this label. The name can be anything for example wardrobe or box etc.
     if (GetGlobalInt(103)==0) {
       object[3].Visible = true;
       object[4].Visible = true;
       object[5].Visible = true;
       }

     if (GetGlobalInt(103)==1) {
       object[4].Visible = true;
       object[5].Visible = true;
       }

     if (GetGlobalInt(103)==2) {
       object[3].Visible = true;
       object[5].Visible = true;
       }

     if (GetGlobalInt(103)==3) {
       object[3].Visible = true;
       object[4].Visible = true;
       }

     if (GetGlobalInt(103)==4) {
       object[3].Visible = true;
       }

     if (GetGlobalInt(103)==5) {
       object[4].Visible = true;
       }

     if (GetGlobalInt(103)==6) {
       object[5].Visible = true;
       }

     else {}
     }
}


After clicking on a certain object there is this:

if (carry+9 <= carryweight) {  
object[3].Visible = false;
player.AddInventory (ibeans);
if (GetGlobalInt(103)==0) {
SetGlobalInt (103,1);
}
if (GetGlobalInt(103)==2) {
SetGlobalInt (103, 6);
  }
if (GetGlobalInt(103)==3) {
SetGlobalInt (103, 5);
  }
if (GetGlobalInt(103)==4) {
SetGlobalInt (103, 7);
  }
}


As you can see it is really long script. What I wish is to simplify this in any way. Any suggestions please?
Title: Re: Item containers
Post by: Matti on Sun 11/04/2010 14:15:00
The first if-part can be shortened to this:


 if (GetGlobalInt(103)==0 || GetGlobalInt(103)==2 || GetGlobalInt(103)==3  || GetGlobalInt(103)==4) object[3].Visible = true;
 if (GetGlobalInt(103)==0 || GetGlobalInt(103)==1 || GetGlobalInt(103)==3  || GetGlobalInt(103)==5) object[4].Visible = true;
 if (GetGlobalInt(103)==0 || GetGlobalInt(103)==1 || GetGlobalInt(103)==2  || GetGlobalInt(103)==6) object[5].Visible = true;


The second one doesn't need the brackets:


if (GetGlobalInt(103)==0) SetGlobalInt (103, 1);
if (GetGlobalInt(103)==2) SetGlobalInt (103, 6);
if (GetGlobalInt(103)==3) SetGlobalInt (103, 5);
if (GetGlobalInt(103)==4) SetGlobalInt (103, 7);
Title: Re: Item containers
Post by: Gepard on Sun 11/04/2010 16:16:40
Thanks for the reply. Seems I have found even easier solution. Everytime character stands on the region and presses "S" key I let the script to show all the objects. However, when he clicks on selected object, corresponding item it will be added to his inventory and the object will move outside the room coordinates so its not visible anymore :) Next time all three objects are shown, but player can only see the remaining two.