Using multiple Items on Inventory

Started by Fuchs, Mon 20/02/2012 07:28:16

Previous topic - Next topic

Fuchs


Hey guys, its me!
This time I have 3 very important questions.
1. First of all:
How can I use multiple items on an inventory item?
I would like to trigger different events for each item I use on another item in the inventory. But once I use the “use active inventory” in the Item-sidebar function I can only add one.
for example:
function iDorn_UseInv()
{
if (cOli.ActiveInventory == iZahnseide){
   cOli.LoseInventory(iDorn);
  cOli.LoseInventory(iZahnseide);
  cOli.AddInventory(iDornmitSchnur);
}
}
But if I try to add another one AGS says “the function UseInv. Is already defined for this item”. So what do I do?
2.
Then I have a hotspot, and at the first time the player examines it he gets an item. How do I turn that function off, after it occurred once?!
3.
The last question would be:
How do I trigger events in rooms the player is not inside at the moments in which they occur. I want the player to push a button in one room, but in another room the door opens.

Thank you very much in advance you guys! I have been trying and working a lot with AGS lately and these are the questions I gathered within a longer period of work. I am sure after I got these things covered I will be quiet for a while! ;-P
Fuchs

Gudforby

For your first question: You don't need another function for that, you just check the same way you have already done. Simply add an "else if) and check for another inventory object.

Code: ags

function iDorn_UseInv()
{
  if (cOli.ActiveInventory == iZahnseide)
  {
    cOli.LoseInventory(iDorn);
    cOli.LoseInventory(iZahnseide);
    cOli.AddInventory(iDornmitSchnur);
  }
  else if (cOli.ActiveInventory == iSomethingElse)
  {
    //your code here
  }
  else if...
}


For the second question: Game.DoOnceOnly command should work here.

For your last question, there are several ways to do that. You could either define a variable (i.e. door_open, and set this to true when the button is pushed. You can then check this variable when entering your other room to see if the door should be open or closed.

If you want to turn objects or hotspots on and off in another room, I recommend this module: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14203.0

Fuchs

Thank you very much! I will try this right away!

Fuchs

I only have one more question concerning the Game.DoOnlyOnce command:
How and where exactly do I put it into the script? Can you give me an example please?! No matter what I do, AGS says that I rather forgot a ( or a ) or that there are not enough parameters in the function (?). So obviously I am doing something wrong! And how do I use modules? ;_;

NickyNyce

#4
Here is an example of one way to use it. In my Drawers interact function, I used Game.DoOnceOnly like this...

function hDrawer_Interact()
{
 if(Game.DoOnceOnly("PickUpSyringe"))  // name this anything you want, just make sure you never use the same name twice
 {
   cScar.Walk(324, 300, eBlock, eWalkableAreas);
   cScar.FaceLocation(324, 0, eBlock);
   cScar.Say("Let's see what's in here");
   cScar.AddInventory(iSyringe);
   cScar.Say("There's a syringe with blood in it, I'll take it");
   aSound3.Play(eAudioPriorityNormal);
   oInvSyringe.Visible=true;
   Wait(40);
   oInvSyringe.Visible=false;
 }
 else
 {
   cScar.Walk(324, 300, eBlock, eWalkableAreas);
   cScar.FaceLocation(324, 0, eBlock);
   cScar.Say("The drawer is empty");    
 }
}

This will run the Game.DoOnceOnly and my character will pick up the syringe, after that, anytime he interacts with the drawer he will say the drawer is empty. You can use Game.DoOnceOnly in after fade in, or for looking at hotspots or objects. This works pretty much the way (first time enters room does), In First time enters room, you can have your character say...Hello...after that, the next time he enters the room he won't say it anymore, it will only happen once  ;)

Ryan Timothy B

Just a side note for you Nicky, you have duplicate code for the walk and face direction code. This would be better:
Code: ags

function hDrawer_Interact()
{
  cScar.Walk(324, 300, eBlock, eWalkableAreas);
  cScar.FaceLocation(324, 0, eBlock);
  if(Game.DoOnceOnly("PickUpSyringe"))
  {
    //pick up syringe code here
  }
  else
  {
    //drawer is empty
  }
}

NickyNyce

#6
Yes Ryan, you're right, it does clean up the code, thanks.

As for the variable part Fuchs, you can do this. Like Gudforby mentioned.

Make a variable, name it (ButtonPress), make it a bool and set it to false. In the room with the button, when the character interacts with it, put this anywhere in the code...ButtonPress=True;

Now in the room with the door, make an object of a closed door covering your BG of an open door (name it oClosedDoor) and set the visiblity to true. In the before fade in of this room, put this to check if the button was pressed.

If(ButtonPress==true){
oClosedDoor.Visible=false;
}

Gudforby

#7
Double post - delete

Gudforby

#8

Yup, that should do it.

If you want to use modules though, just download the module from the link. It seems it was this one I thought about: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=20650.0
The one I mentioned earlier had a broken link.

Then you unzip it. In AGS, right click on the Scripts pane, and select "Import Script". Find the unzipped files and import the *.scm-file. It then adds to your scripts. included in the zip is a txt-file which shows you how to use the module while scripting.

Fuchs

Oh thank you so much! Now it finally works!!!

Does anybody else here know this feeling when something in AGS works just the way you want it to, and then you feel like "jes i am one step further towards my own game!!!"? Its such a wonderful feeling, and for me, as a rook in Scripting its like falling in love for the first time!  :D

Fuchs

I was just thinking, what if i just go in the room and press the button and say "oDoorvisible = false"? Because theoretically, if i create an Object, each object should have only one unique name. So AGS should actually not care for which room the object is in, right?! Maybe if i place the function in the global script?
???

Gudforby

Room objects are room specific, so that will not work, unfortunately

Khris

Yes, for one, it's possible to have two or more objects with the same name as long as they are in separate rooms, but the actual reason is that only the current room is loaded into memory.
So even if you paid attention and gave all objects unique names, AGS wouldn't know what you're referring to by oDoor if they player is in another room.

You can access room objects in the global script, but not by using their room name. When a room is loaded, the object[] array is set up so its elements point to the room objects. Say oDoor has ID 0, then as long as the room is loaded, you can use object[0] in the global script to do something to it.

So the way to do it is to store all game-wide changes in global variables and update the rooms in the before fadein event.

SMF spam blocked by CleanTalk