Tuesday, December 16, 2008

Handy code snippet #378

Babar was just asking on Stickam how you'd set a particular inventory item to be first of your inventory window (not rearranging inv item order, but just scrolling the window to the correct point). And here we are:

function settop(this InvWindow *, InventoryItem *thing)
{
int itemi=0;
while (itemi < this.TopItem) {
if (this.ItemAtIndex[itemi]==thing) {
this.TopItem=itemi;
return;
}
itemi++;
}
}

3 comments:

  1. Make that
    if (this.ItemAtIndex[itemi]==thing) {
    and it works even neater ;)

    ReplyDelete
  2. You spotted my deliberate mistake! That one and the other one you didn't spot now fixed. :) I blame blogger's rubbishness at posting code

    ReplyDelete
  3. You should blame that we were running a small competition..to which I lost..

    ReplyDelete

Please keep comments clean: foul language means your comment will not get published. Sorry for the captcha, was getting to much spam.