Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Necro on Wed 23/07/2003 22:37:26

Title: CJ - Inv Position of selected Item
Post by: Necro on Wed 23/07/2003 22:37:26
I have 6 slots to display items , with arrows that scroll it left and right.

Is there anyway of getting the index of the item that you clicked on??

I know game.top_inv_item returns the index of the 1st slot but what I need is a way of returning the index of the seleceted item.
Title: Re:Inv Position of selected Item
Post by: Proskrito on Thu 24/07/2003 13:49:07
i think player.activeinv returns the item that you have selected. or you could make GetInvAt(mouse.x,mouse.y) just after clicking on it, or, if you want to know the indexes of all items displaying beforehand, and the inv is in a fixed position as yours seems to be, you could make GetInvAt with the coordinates of the inventory slots, but maybe there is a smarter sollution.
Title: Re:Inv Position of selected Item
Post by: Necro on Thu 24/07/2003 16:27:38
thats just gonna be a big mess of if statements GetInvAt(x,y) , I wanna try and avoid that if possible. But I may have no choice

Title: Re:Inv Position of selected Item
Post by: Ishmael on Thu 24/07/2003 19:56:52
QuoteIs there anyway of getting the index of the item that you clicked on??

the game.inv_activated global variable
Title: Re:Inv Position of selected Item
Post by: MrColossal on Thu 24/07/2003 20:41:52
i thought i told you on #ags?

eric
Title: Re:Inv Position of selected Item
Post by: Necro on Fri 25/07/2003 00:25:02
no you didnt tell me on #AGS.

game.item_activated returns the item number, NOT the item position (index) which is what I need
Title: Re:Inv Position of selected Item
Post by: MrColossal on Fri 25/07/2003 01:08:36
woopsie my bad, i misunderstood you
Title: Re:CJ LOOK! Inv Position of selected Item
Post by: Necro on Fri 25/07/2003 01:31:53
I DID IT!!

But AGS still needs a function to find index of a selected item!

---

   int i=0;
   int pos=1;
   int oldpos = game.top_inv_item;
   while (i != game.inv_activated) {
     if (character[BOB].inv != 0) pos++;
     i++;
   }  
   DisplaySpeech(BOB,"POS %d",pos);
   DisplaySpeech(BOB,"I %d",i);

---

POS displays position number
I is just a counter
Title: Re:CJ - Inv Position of selected Item
Post by: RickJ on Fri 25/07/2003 02:22:21
I don't think you need to use a while loop to dop this.  How about something like this:

function gsGetInvWindowIndex(int item) {
  int pos=item - game.top_inv_item;
  if ((pos > game.num_inv_displayed)||(pos<0)) pos=-1;
  return pos;
}

I haven't tested it but it should return the position of the specified item is in the window and a minus one otherwise.  You could do the following for your purposes.
 
  int mypos;
  mypos=gsGetInvWindowIndex(game.inc_avtivated);

The endpoints may be off by 1;  haven't tried it so I don't know.



Title: Re:CJ - Inv Position of selected Item
Post by: Necro on Fri 25/07/2003 08:01:47
nope that doesnt work. Not when you have scrolled your inv windows on a bit anyway. and yes its off by one. so is my code above btw i think.
Title: Re:CJ - Inv Position of selected Item
Post by: Pumaman on Fri 25/07/2003 13:52:42
You know the width of your inventory items. (because you probably set it with SetInvDimensions).

You also know the X,Y location of your inventory GUI.

Finally, you know the mouse co-ordinates.

So the index would be something like:

((mouse.x - GUI_X_POSITION) / InvItemWidth)
Title: Re:CJ - Inv Position of selected Item
Post by: Necro on Sat 26/07/2003 13:13:22
punaman , that would give me the slot in which I clicked on , but as soon as you scroll your 6 slotted inventory left or right you would have difficulty...as it would no longer give you the index of your item you wanted.
Title: Re:CJ - Inv Position of selected Item
Post by: Pumaman on Sat 26/07/2003 16:55:07
Well, what do you hope to achieve by knowing the index number? It means nothing, because the items could have been added in any order.

The  game.inv_activated  variable is what you should be using.