"Selected Graphic" for Inventory Items (Solved for now)

Started by Mugs, Sat 07/03/2009 20:20:47

Previous topic - Next topic

Mugs

I looked everywhere for a solution to my problem,  but I couldn't find one.  Anyways...


I want the graphic of an inventory item to change when it is selected.  This is so that the player knows which inventory item is selected (the game does not use inventory cursors). 

I don't know what details to provide,  but here are some details anyways:

iPencil =  Name of inventory item ("Normal" graphic slot is 46  -  The desired "selected" graphic slot is 48) 
cPlay = Player character (Note:  I plan to have many player characters in the game)

Please tell me if I am missing any necessary details.


Thank you in advance.

Cool stuff I found out: Men are four times more likely to be struck by lightning than women.  Wow, really? [dirty joke] Maybe this has to do with the fact that us men have "lightning rods"? [/dirty joke]

AdamM

Off the top of my head, do you see any problems with this?

Code: ags
function repeatedly_execute() {

 if (cPlay.ActiveInventory == iPencil) {
  iPencil.Graphic = 48
 }

 else {
 iPencil.Graphic = 46
 }

}

Mugs

Thank you very much.   I knew that the solution would probably involve iPencil.Graphic,  but it didn't work when I tried it on my own.

The code seems to be working fine, however, I might run into a problem later on.  Its kinda hard to explain. 

I'll post an update if ever I run into another problem.
Cool stuff I found out: Men are four times more likely to be struck by lightning than women.  Wow, really? [dirty joke] Maybe this has to do with the fact that us men have "lightning rods"? [/dirty joke]

AdamM

Oh, I can't believe I forgot the semicolons. I'm such an amateur!

Trent R

I'd suggest using some custom properties. Either use one in conjuction with the CursorGraphic property, or use two custom properties. Then you can call something like iPencil.Graphic=iPencil.GetProperty("Selected").

If you have 'handle inventory clicks in script' set to true, I believe you can take this further and have it do it all for you. Otherwise, you'd probably have to hardcode it all with a rep_exec like Adam posted.



~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

Since 3.1.2 there's InventoryItem.CursorGraphic.
I didn't test it, but I guess it'll still return the slot if "Use selected inventory graphic for cursor" isn't checked.

SMF spam blocked by CleanTalk