SOLVED! Converting Data Types

Started by Baron, Tue 30/11/2010 02:22:49

Previous topic - Next topic

Baron

Quick query -does anyone know how to extract a clean number from a pointer?  I'd like to be able to keep track of what inventory items a player has thought of using (i.e. player.ActiveInventory, but save the item number that was in use after ActiveInventory changes to a new item).  I'd like to save this as a char/short/int, but ActiveInventory is apparently a pointer and I can't easily grab the raw number with something like

Quote
int oldinv = player.ActiveInventory

because there is a data type mismatch, or something like that.  I fleetingly considered writing out a function that lists every item and converts it into an int, but there must be an easier way to convert or extract that information from a pointer.  Any ideas?

EDIT -Topic Title.

Gilbert

InventoryItem.ID

I think you can use something like player.ActiveInventory.ID, but I'm not sure about it. In case that doesn't work, you can always use a workaround:
Code: ags

InventoryItem* tmpinv = player.ActiveInventory;
int invid = tmpinv.ID;


RickJ

You can do as Gilbet suggests.  But why not just keep a list of pointers?  You can create a pointer array as Gilbet show you

Code: ags

InventoryItem* ListOfItems[100];

Baron

BAM -that's nailed it!  Thanks Gilbet.

@RickJ -An array is a good idea for keeping track over time (I just need the next to last one for now), but it was extracting that item number for use in add/remove inventory (or whatever it's called now) that was hanging me up.  Thanks for the ideas!

monkey0506

#4
@Gilbet:

To help clarify, you can call members of members (such as the ID member of the ActiveInventory member of the player keyword), the only real restriction is that you can't call non-static members of non-static members..

The simplest way to explain what I mean by that is again to show an example. So, DateTime.Now is a static member of the DateTime type (and is in fact an instance of the type). DateTime.RawTime is a non-static member of the DateTime type.

DateTime.Now.RawTime should therefore be valid, but due to this limitation in AGS, it isn't. If RawTime were static then it would be fine, but since RawTime is non-static, you can't directly access it via a static member (Now); you must store the static member into a temporary pointer first.

I hope that makes sense..

Khris

Quote from: monkey_05_06 on Tue 30/11/2010 06:45:07the only real restriction is that you can't call non-static members of non-static members..

Regarding your example I guess you meant "you can't call non-static members of static members."

monkey0506


SMF spam blocked by CleanTalk