Multiple items shown as one icon [SOLVED]

Started by Matti, Wed 06/05/2009 11:57:35

Previous topic - Next topic

Matti

I want to ask if there's a not too difficult way to show several inventory items in one icon. I give you an example:

The player can have a variable amount of mushrooms in his inventory. If he has one mushroom, the icon image shows one mushroom. If he has four the icon shows four. Four shall be the maximum thus if he has five mushrooms, there's an icon with four and on one icon with one mushroom. If he has 9-12, there should be three icons.

Okay, here's a visualization:


Joe

#1
Of course there is.

You'd have to draw the different graphics for each number... so lets imagine you're doing it with coins and you can have a maximum of 3 coins, you've created an inventory itam called iCoin and you have drawn 3 graphics and their numbers are 1, 2 and 3.


Code: ags

//at the top of global script
int coins=0;

//at your getcoin code
coins++;
if(coins==1)iCoin.Graphic=1;
if(coins==2)iCoin.Graphic=2;
if(coins==3)iCoin.Graphic=3;


//at your losecoin code
coins--;
if(coins==1)iCoin.Graphic=1;
if(coins==2)iCoin.Graphic=2;




EDIT: Of course you could also change the name of the inventory item's name to "2 coins","3 coins"... and to make it as you want, I mean groups of mushrooms then you should create different inventory items like this: iMush1, iMush2.... and check in the script if your maximum per group is reached then add the new inv item.. and viceversa
Copinstar © Oficial Site

Matti

Quote from: Joe Carl on Wed 06/05/2009 12:21:13
I mean groups of mushrooms then you should create different inventory items like this: iMush1, iMush2.... and check in the script if your maximum per group is reached then add the new inv item.. and viceversa

Yeah, I thought about that too, but hoped for an easier way. The problem is that there are four players and each of them can carry mushrooms. So I will have to make iMush1, iMush2 etc. for all the players. But, well, it will work like this. Thanks..

Trent R

I assume you can only see one character's inventory at a time, right? In that case, you wouldn't need multiple items (iMush1, iMush2, etc).

As for Joe Carl's code, there's no need to use an extra variable. character.InventoryQuantity[] mixed with on_event(eEventAddInventory) should easily recreate the code you posted in a more intuitive way.


Also, I'd look at Khris's InvAmount module (I'm not sure if it has a thread) for some ideas on how to code it. I'd suggest using some custom properties to store the sprite numbers too.

~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

Khris

Quote from: Joe Carl on Wed 06/05/2009 12:21:13
Code: ags
  if(coins==1)iCoin.Graphic=1;
  if(coins==2)iCoin.Graphic=2;
  if(coins==3)iCoin.Graphic=3;


I just want to point out that the above can be done using:
Code: ags
  iCoin.Graphic = coins;

;D

Matti

Haha, yeah.  ;D

Well, now I'm going to just use a single icon representing the amount of mushrooms. It would have been very complicated otherwise, with four players having them and the ability to steal them from each other etc....

Everything's fine now.

Joe

Quote from: KhrisMUC on Wed 06/05/2009 21:29:58
Quote from: Joe Carl on Wed 06/05/2009 12:21:13
Code: ags
  if(coins==1)iCoin.Graphic=1;
  if(coins==2)iCoin.Graphic=2;
  if(coins==3)iCoin.Graphic=3;


I just want to point out that the above can be done using:
Code: ags
  iCoin.Graphic = coins;

;D

Haha. You're right Khris I just typed that since the coins grapihcs may not be 1, 2 or 3 and I'm pretty sure they are not.
Copinstar © Oficial Site

Khris

True. :)

Thing is, if they are 45, 46 and 47, one can use iCoin.Graphic = 44 + coins;
That's why one should always use consecutive numbers for stuff like that.

Joe

You're completely right and in my last game I've done it.
It's a great idea to save lines in script.
Copinstar © Oficial Site

Matti

Quote from: Trent R on Wed 06/05/2009 20:52:31
I assume you can only see one character's inventory at a time, right? In that case, you wouldn't need multiple items (iMush1, iMush2, etc).

No, unfortunately often two of the four inventorys are shown, so I need the variables. In addition it's possible to steal stuff from other players through clicking on an inventory item. But as I said I'm going to only use one single icon for the maximum possible amount of mushrooms and other stuff.

Quote from: Joe Carl on Thu 07/05/2009 19:10:21
Haha. You're right Khris I just typed that since the coins grapihcs may not be 1, 2 or 3 and I'm pretty sure they are not.

If you mean my mushroom graphics: They are indeed consecutive, as I'm trying to always have graphics that are related to each other in a row. Yeah, as you both have said, it can save some lines and some time..

SMF spam blocked by CleanTalk