Thread: would this be a good way get index of somthing for multiple things.

Results 1 to 3 of 3
  1. #1 would this be a good way get index of somthing for multiple things. 
    Banned

    Join Date
    Jan 2009
    Age
    31
    Posts
    2,661
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    Code:
    		public void clickedFood(Client c, int id, int slot)
    		{
    			Food nF = getIndex(FOODS,id);
    			if(nF != null) {
    				eat(c,id,nF,slot);
    				return;
    			}
    			nF = getIndex(POTIONS,id);
    			if(nF != null) {
    				potion(c,id,nF,slot);
    				return;
    			}
    			nF = getIndex(DRINKS,id);
    			if(nF != null) {
    				drink(c,id,nF,slot);
    				return;
    			}
    			nF = getIndex(SPECIAL_FOODS,id);
    			if(nF != null) {
    				specialEat(c,id,nF,slot);
    				return;
    			}
    			nF = getIndex(SPECIAL_POTIONS,id);
    			if(nF != null) {
    				specialPotion(c,id,nF,slot);
    				return;
    			}
    			nF = getIndex(SPECIAL_DRINKS,id);
    			if(nF != null) {
    				specialDrink(c,id,nF,slot);
    				return;
    			}
    			c.sendMessage("unable to locate food: "+id);
    		}
    Reply With Quote  
     

  2. #2  
    Member would this be a good way get index of somthing for multiple things. Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    If you program correctly, then "nF" should never be null.

    Attached imageAttached image
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jan 2009
    Age
    31
    Posts
    2,661
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    well yeah i know it should never be null but in this situation it will to determine which of the 6 options it is.

    i thought maybe a while would do fine like

    Code:
    while(nF == null)
    {
    nF = getIndex(FOODS,id);
    nF = getIndex(DRINKS,id);
    nF = getIndex(POTIONS,id);
    }
    but then that came as a problem aswell.


    and i could use else if but i dont see a point since returns do the same thing.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •