How to remove an item from the inventory when used?

Started by Scrungo, Sat 05/09/2020 03:27:04

Previous topic - Next topic

Scrungo

Hello! I'm a TOTAL newbie with AGS, I downloaded it earlier today, so I'm sorry if this is a stupid question I'm asking lol.

So, in my game, what I'm trying to do is make my character pick up a pillow on their bed and add it to their inventory (I got that working) and then be able to USE the pillow on the bed to put it back and remove it from the inventory.
The problem is that it wont leave the inventory when I USE it on the bed!
(I'm using the TumbleWeed template, if that helps any.)
Code: ags
function oBed_UseInv()
{
 if (player.ActiveInventory == iPillow) {
   player.Say("Fine, I'll make my bed!"); 
   player.LoseInventory(InventoryItem iPillow);
   oPillow.Visible = true;
   }
 }


He also says "That won't do any good." after trying to USE the pillow on the bed as well, and I'm not sure how to fix that either.

I've been able to Google search previous problems, but I've been having trouble finding a solution to this. I'm also not the best at coding lol.

Thank you!!!!  ;-D

Slasher

#1
Hi and welcome to the ags forums.

Well, the pillow would be an object that when to interact with it you pick it up (make pillow invisible) and pillow goes in your inventory.
Now, if you use pillow inventory on the bed the pillow will appear again  (make pillow visible).

One way depending how you have the bed and pillow set up

Code: ags

//In the properties panel for the Pillow use interact event and code as 
oPillow,Visible=false; // Pillow now invisible. 
cDummy.AddInventory(iPillow); // Pillow now added to inventory.

// Now got to bed object and in it's properties panel for the Bed select Use Inv event and code as 
if(cDummy.Activeinventory==iPillow){
oPillow,Visible=true;
cDummy.LoseInventory(iPillow);
}


Hope this helps.....

Just realised you're using the TumbleWeed template

Scrungo

#2
Nope, it didn't work. :(
The pillow is still in the inventory after I USE it on the bed. However, the other parts of the code work (Making the pillow visible again, and the dialogue).
And when Dummy does that, he walks down a few steps and then says "That won't do any good." and I'm still not sure why that happens.  ???

The code now looks like this (It didn't change much from before, but just in case it helps at all, I decided to post it again.):

Code: ags
function oBed_UseInv()
{
  
  if(player.ActiveInventory==iPillow){
   player.Say("Fine, I'll make my bed!");
   oPillow.Visible=true;
   player.LoseInventory(iPillow);
  }
}


I'm honestly stumped!  ???

Slasher

#3
If cRoger is the main player then it should work as it did when you picked pillow up...

Check out all oBed events....

You could and an 'else if' if player uses another inv item on the bed:
Code: ags

if(cDummy.Activeinventory==iPillow){
oPillow,Visible=true;
cDummy.LoseInventory(iPillow);
}
else if(player.Activeinventory!=null) {      //any other active inventory item
cDummy.Say("That won't do any good.");
 }
}




Scrungo

Nope, it doesnt work. The pillow stays in the inventory.
When the pillow USEd on the bed, the pillow on the bed becomes visible, and the text "Fine, I'll fix my bed!" appear, but iPillow doesnt leave the players inventory.
I even tested, you can repeat the dialogue sequence if you attempt to USE the pillow on the bed once more, even after the pillow on the bed is visible again.

Slasher

Read above post...

If you can make it active you should be able to Add and Lose it... Check the inv pillow spelling etc etc

Scrungo

#6
Adding that sort of elif to the bed wouldn't do much, since the inv pillow is the only inventory item in this "game". (Really more of a test adventure for me to learn AGS.)
Trust me, before making this thread, I more than triple checked spelling of it everywhere, and did again before posting this.

Are there any alternate ways to lose an inventory item that I could try out?

Slasher

#7
Quote from: Scrungo on Sat 05/09/2020 08:27:58
Adding an elif to the bed wouldn't do much, since the inv pillow is the only inventory item in this "game". (Really more of a test adventure for me to learn AGS.)
Trust me, before making this thread, I more than triple checked spelling of it everywhere, and did again before posting this.

Are there any alternate ways to lose an inventory item that I could try out?
Not that I know of....Not sure why you are not losing after using it..

This action is a very major part of ags...

Maybe it's the Tumbleweed template coding..


Scrungo

Quote from: Slasher on Sat 05/09/2020 08:30:49
Maybe it's the Tumbleweed template coding..

Yeah, that's what I'm starting to think... :/

Oh well.  :(

Slasher

#9
The Tumbleweed template uses different scripts then a normal template like Serra Style.

Check out the Global and Room Scripts for commands used....

Cassiebsg

Can you show the pick up code?
Are you allowing picking up the item multiple times? And in settings you have Inventory->Display multiple icons  for multiple items=false?

Maybe you have just picked up the pillow more than once and when you lose it, you only lose 1 of them, thus at least one remains in inventory?
Try setting the Display multiple icons  for multiple items=true and see if your character then happens to have more than one pillow in inventory.

I'm not familiar with the Tumbleweed template, so I don't know if there's some oddity coded that could be interfering with the normal way AGS works.
There are those who believe that life here began out there...

Scrungo

Quote from: Cassiebsg on Sat 05/09/2020 10:17:52
Can you show the pick up code?

Yeah sure!
(this is in the middle of the function "oPillow_AnyClick()" with other verbs on it, so that's why it might come off as a bit disjointed on here)
Code: ags
    // PICKUP
    else if(Verbs.UsedAction(eGA_PickUp)) {
      player.Say("Fine, its really comfy.");
      oPillow.Visible = false;
      oKey.Visible = true;
      player.AddInventory(iPillow);
    }


I'm going to sleep after posting this, so I'll try stuff out later when I wake up.
Good night, and thank you guys for the help!!!! :D

Cassiebsg

#12
Okay, from that snip of code, I can't see that's it's possible to get more than one pillow in inventory.
You sure the player isn't starting with a pillow already in inventory? Maybe you gave him one to test some other code and forgot to remove it?

EDIT: Only other thing I can think of, is try to use player.LoseInventory instead for cRoger or cDummy.... if they're the player doesn't matter, but if their not, it does matter.
There are those who believe that life here began out there...

Crimson Wizard

#13
In above script examples you keep alterating between "cDummy", "cRoger" and "player". You have to be consistent there. Who is "cDummy" and "cRoger"? is anyone of these a player character? who is a character that has a pillow in inventory? Who is a character whose inventory is displayed by inventory window?

Personally I'd suggest to use "player" in all interactions, except when you must specifically reference particular character of course.

Scrungo

Quote from: Crimson Wizard on Sat 05/09/2020 14:36:16
In above script examples you keep alterating between "cDummy", "cRoger" and "player". You have to be consistent there. Who is "cDummy" and "cRoger"? is anyone of these a player character? who is a character that has a pillow in inventory? Who is a character whose inventory is displayed by inventory window?
Ok, this is my bad for not clarifying earlier.
When I started out, I made my own character (cDummy), since this game I'm making is just a test to test all all various kinds of things in AGS before I start making ACTUAL games, so I wanted to try making my own character.
But between the first post, and my next post with code with the inconsistency, I decided to change back to cRoger, due to him looking better than the character I made. (And yes, I also changed any and all code with "cDummy" to "cRoger")
There are no other playable characters, just me switching between the character I wanted to use for the game is all.
I'll go back and edit previous posts to make it consistent to how it is in my code currently, sorry for the confusion.


Quote from: Cassiebsg on Sat 05/09/2020 12:20:28
You sure the player isn't starting with a pillow already in inventory? Maybe you gave him one to test some other code and forgot to remove it?

EDIT: Only other thing I can think of, is try to use player.LoseInventory instead for cRoger or cDummy.... if they're the player doesn't matter, but if their not, it does matter.
Nope, the pillow isn't in the starting inventory, I just checked.
and sadly, changing the code to player.LoseInventory didn't do anything :(

Crimson Wizard

#15
To clarify, is this line run when you use pillow: "player.Say("Fine, I'll make my bed!");"?

Oh right, nevermind you already said this...

If it's just a test game, could you upload it somewhere for us to look in?

Scrungo

Quote from: Crimson Wizard on Sat 05/09/2020 22:52:25
If it's just a test game, could you upload it somewhere for us to look in?
How should I go about doing that?
I would doubt that the EXE would suffice, unless AGS is able to decompile games.

Crimson Wizard

Quote from: Scrungo on Sat 05/09/2020 23:14:05
Quote from: Crimson Wizard on Sat 05/09/2020 22:52:25
If it's just a test game, could you upload it somewhere for us to look in?
How should I go about doing that?
I would doubt that the EXE would suffice, unless AGS is able to decompile games.

I could try exe too, maybe something comes up... but game sources are the files that lie in the project root folder: *ash/*asc, *.agf, *.crm files and so on.

Scrungo

Quote from: Crimson Wizard on Sat 05/09/2020 23:42:54
I could try exe too, maybe something comes up... but game sources are the files that lie in the project root folder: *ash/*asc, *.agf, *.crm files and so on.
Alright, what would be the best of of going about that?
Would compressing them into a .zip file, and uploading it to something like Mediafire, and then sending the link here be fine with you, or does the AGS Forum not allow links to downloads like that?


SMF spam blocked by CleanTalk