(Solved) Question concerning pointers/arrays (Solved)

Started by BrightBulb, Sat 04/12/2010 14:01:49

Previous topic - Next topic

BrightBulb

Hi everybody,

I have this piece of code which draws a selection frame around the selected inventory item (lucas style).  Basically I'm running a counter from 0 to 13 checking against 14 buttons and on a match highlight the selected inventory item. It works fine but obviously one could shorten it.

If I could do something like bInvSlot[counter].Visible=true; then it would save 13 lines. But I wasn't able to implement it. I suspect one could do it with pointers/arrays, but I couldn't find anything.

   
Code: ags
  while (counter<MaxItems){
              
              
                if (player.ActiveInventory == InvWin.ItemAtIndex[counter]) {
                if (counter==0) bInvSlot0.Visible=true;
                else if (counter==1)bInvSlot1.Visible=true;
                else if (counter==2)bInvSlot2.Visible=true;
                else if (counter==3)bInvSlot3.Visible=true;
                else if (counter==4)bInvSlot4.Visible=true;
                else if (counter==5)bInvSlot5.Visible=true;
                else if (counter==6)bInvSlot6.Visible=true;
                else if (counter==7)bInvSlot7.Visible=true;
                else if (counter==8)bInvSlot8.Visible=true;
                else if (counter==9)bInvSlot9.Visible=true;
                else if (counter==10)bInvSlot10.Visible=true;
                else if (counter==11)bInvSlot11.Visible=true;
                else if (counter==12)bInvSlot12.Visible=true;
                else if (counter==13)bInvSlot13.Visible=true;
                }              
                
              counter ++;


Thanks.

Dualnames

#1
Code: ags
 
while (counter<MaxItems)  {
     if (player.ActiveInventory == InvWin.ItemAtIndex[counter])     {
        GUINAMEGOESHERE.Controls[counter].AsButton.Visible=true;
     }     
counter ++;
}



Unless I'm mistaken this should work just fine.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

A more straightforward way would be to use just one button and simply move it to the item's position.

Code: ags
  while (counter<MaxItems) {

    if (player.ActiveInventory == null) {
      bInvSlot.Visible = false;
      counter = MaxItems;
    }

    if (player.ActiveInventory == InvWin.ItemAtIndex[counter]) {
      int x = InvWin.X + InvWin.ItemWidth*(counter%InvWin.ItemsPerRow);
      int y = InvWin.Y + InvWin.ItemHeight*(counter/InvWin.ItemsPerRow);
      bInvSlot.Visible = true;
      bInvSlot.SetPosition(x, y);
    }

    counter++;
  }

BrightBulb

@Dualname: Your solution works fine and was the command I was looking for.

@Khris: Why didn't I think of just moving one button? I got a lot to learn. I will implement your solution to further improve my scripting.

Thanks to both of you.

SMF spam blocked by CleanTalk