CJ - Inv Position of selected Item

Started by Necro, Wed 23/07/2003 22:37:26

Previous topic - Next topic

Necro

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.

Proskrito

#1
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.

Necro

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


Ishmael

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

the game.inv_activated global variable
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

MrColossal

i thought i told you on #ags?

eric
"This must be a good time to live in, since Eric bothers to stay here at all"-CJ also: ACHTUNG FRANZ!

Necro

no you didnt tell me on #AGS.

game.item_activated returns the item number, NOT the item position (index) which is what I need

MrColossal

woopsie my bad, i misunderstood you
"This must be a good time to live in, since Eric bothers to stay here at all"-CJ also: ACHTUNG FRANZ!

Necro

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

RickJ

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.




Necro

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.

Pumaman

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)

Necro

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.

Pumaman

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.

SMF spam blocked by CleanTalk