Inventory GUI

Started by Franco, Thu 11/12/2008 19:39:30

Previous topic - Next topic

Franco

Hi all!
Can someone help me with this problem?
I need to create a new inventory GUI, because I need to use two inventory in my game. Is this possible? And if ok, how can I chose to add an object the character picks up in inventory 1 or in inventory 2?
Thank you!

Franco

Ghost

#1
To create an "inventory GUI", just make a new Inventory Window on an existing GUI or create a new GUI with a new inv. window.

Name your inventory window...

Now, since each character can have its own inventory but you can't have two windows for one character, a common trick is having a "dummy" character that never appears in a room, and adding inventory to him that is then displayed in the new window.

Just make a "cDummy", starting room -1, and then use the InvWindow.CharacterToUse
command to make your "new inventory window" refer to this character. And voila, that's it ;) - now you can use player.AddInventory to give stuff to your "main window" and cDummy.AddInventory to store inventory in the second window.

Franco

Thank you Ghost, but I have bad explained.
I need two inventory for the same character. I will use two buttons on the backround, one to open inventory1 and another to open the inventory2. My problem is to set an objet finishing in inventory1 or inventory2. How can I make this?
Thank you!

Ghost

#3
You explained well!

Do your inventory windows need to display DIFFERENT items? If that is the case, you can use my method. The reason is that inventory is always added to a player, and the windows are just a way to show what a player has. So for two windows that hold different stuff you will NEED two characters.

Do not worry about the cDummy character, it will never appear in the game. Think of it as a placeholder: For example, if your character must have two inventory windows, one for small, one for large items, just give all small items to the player, and all large ones to the Dummy. To "switch" between the windows you can write the following into the button on_click function:

if (invPlayer.Visible)
{
  invDummy.Visible = true;
  invPlayer.Visible = false;
}
else
{
  invDummy.Visible = false;
  invPlayer.Visible = true;
};

This will work well. You don't even need to use cDummy.Say or similar to work with the items in his inventory.



Franco

Good trick!
I'll try!
Can I contact you if I will found troubles?
For the moment thank you again!

Franco

Sorry, but I have another stupid question. I'm not very expert in GUI script. How can I link the inventory GUI I created with the dummy?

Ghost

#6
Sorry, my bad ;)

You need to set a CharacterToUse property, like this:

Code: ags

invWindow2.CharacterToUse = cDummy;

Put this in the game_start section of your global script.

This will change the inventory window to display the inv. of cDummy. If you need a more lengthy explanation, check the manual for "CharacterToUse".

As you might already have realised, this method can be extended- think of using characters as "tabs"- in an RPG you could make a cWeapons character who gets all the swords and axes, a cSpells character to hold spell scrolls, and so on. Setting their starting room to -1 makes them totally "invisible", and you needn't bother to give them views or similiar.
Hope this helped ;)

[edit] And yes, should you need some help, just drop a line.

Franco

Ok thank you! I'll try!

Franco

Ok great! It works!
Now I have a button in the custom inventory GUI that switch between inventory window 1 e inventory window 2. The problem is that when it is visible the dummy window I cannot pick the item and use it into the game, because the game crashes. I tryed SetActiveInventoy, but it doesn't work. What can I do?

Ghost

#9
Do you use player.SetActiveInventory or cDummy.setActiveInventory? If possible, can you post your code?

Additionally, try to put this into your room's on_room_load:

cDummy.ChangeRoom(Number Of Your Room Here!, -100, -100);

and see if you can now select inventory without crashing... It may be that you must have the Dummy in the same room as the player (to be honest, I never before had two inv. windows in a game...)

Dualnames

Why does the game crash? and when does it crash?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Trent R

I believe it's because cDummy is not the character. When you try to SetActiveInventory with an inventory item that the player doesn't have, then it crashes.

One solution could be to make cDummy's view the same as the cEgo, and change the player character when you open the corresponding Inventory.

But there are many solutions, this is only one (which may not work with your game)

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Ghost

#12
Trent almost beat me to it  :=
I solved it, though I am not sure if my solution is the best one; anyway- I made a small example room and zipped the whole commented package.


http://www.mediafire.com/download.php?gcddwgjn5rq

Features:
- Two inventories; each one can hold any amount of stuff, but you can simply decide if an item must go into Inv1 or Inv2.
- One additional button on the standard inventory GUI allows you to switch between Inv1 and Inv2
- You can easily select an item from any inventory, and you can even get an item from Inv1, switch to Inv2 and use the formerly selected item there.
- Contains crude placeholder graphics and one lame Diablo joke.

How does it work?
Extremely simple- you have two IDENTICAL characters. Each character has an inventory. AGS allows you to refer to a character by name (like "cEgo" and "cDummy"), or by "player" (always the currently activated player character).
So what we do is this: Clicking the "switch inventory" button checks if player is cEgo or cDummy, and then switches the characters (and positions so that you do not end up with two clones in one place). Simple as that ;) Since you can always refer to "player", it isn't really important which character you are- in all other scripts just say "player.DoSomething", and that's it.

Check your PM too!

Trent R

I figured someone would elaborate on what I said. Good work Ghost!

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Dualnames

Good job, Ghost. you even sprited...yay.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Franco

Yes, the Ghost's solution is a good solution!
I'll try it!
Thank you all!

SMF spam blocked by CleanTalk