Thread: Java array (fishing)

Results 1 to 10 of 10
  1. #1 Java array (fishing) 
    Banned

    Join Date
    Sep 2009
    Posts
    3,245
    Thanks given
    195
    Thanks received
    255
    Rep Power
    0
    I've just been touching up my fishing on a pi base and thanks to akeid I figured out how to loop the emote I'm trying to get different emotes working for different fish I've never added my own array ( I think this is an array or possibly a string my java's evidently not so great)

    Code:
    	public void setupFishing(int fishType) {
    		if (c.getItems().playerHasItem(getEquipment(fishType))) {
    			if (c.playerLevel[c.playerFishing] >= req) {
    				int slot = getSlot(fishType);
    					if (slot > -1) {
    						this.req = REQS[slot];
    						this.fishType = FISH_TYPES[slot];
    						this.equipmentType = getEquipment(fishType);
    						this.exp = EXP[slot];
    						c.fishing = true;
    						c.fishTimer = 3 + Misc.random(2);
    						if (c.npcType == 7944) {
    						c.cagelob();
    							}
    
    						if (c.npcType == 334) {
    						c.harpoon();
    						}
    
    					}
    			} else {
    				c.sendMessage("You need a fishing level of " + req + " to fish here.");
    				resetFishing();
    			}
    		} else {
    			c.sendMessage("You do not have the correct equipment to use this fishing spot.");
    			resetFishing();
    		}
    	}
    Can i add an array like this
    Code:
    	private final int[] CAGELOB = {7944,316,334,324};
    	private final int[] HARPOON = {334,324};
    how could I change if (c.npctype == 334) { to something like if (cagelob) {

    Thxx rep++ ( Don't hate i'm trying to learn..)
    Reply With Quote  
     

  2. #2  
    Registered Member Ikki's Avatar
    Join Date
    Dec 2007
    Posts
    218
    Thanks given
    5
    Thanks received
    6
    Rep Power
    38
    Code:
    for(int i : cagelob) {
    	if(i == c.npcType) {
    		c.cagelob();
    	}
    }
    Simple, I hope understood.
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Sep 2009
    Posts
    3,245
    Thanks given
    195
    Thanks received
    255
    Rep Power
    0
    So changed this..

    Code:
    if (c.npcType == 7944) {
    						c.cagelob();
    							}
    
    						if (c.npcType == 334) {
    						c.harpoon();
    						}
    to this..

    Code:
    					for(int i : CAGELOB) {
    					if(i == c.npcType) {
    						c.cagelob();
    						}
    					}
    Code:
    private final int[] CAGELOB = {7944,316,334,324};
    and added this, all in fishing.java, but when I click a cagelob npc there's no animation so it's not working for some reason mind explaining some more?
    Reply With Quote  
     

  4. #4  
    Registered Member Ikki's Avatar
    Join Date
    Dec 2007
    Posts
    218
    Thanks given
    5
    Thanks received
    6
    Rep Power
    38
    Code:
    	private final int[] CAGELOB = {7944,316,334,324};
    	private final int[] HARPOON = {334,324};
    	public void setupFishing(int fishType) {
    		if (c.getItems().playerHasItem(getEquipment(fishType))) {
    			if (c.playerLevel[c.playerFishing] >= req) {
    				int slot = getSlot(fishType);
    					if (slot > -1) {
    						this.req = REQS[slot];
    						this.fishType = FISH_TYPES[slot];
    						this.equipmentType = getEquipment(fishType);
    						this.exp = EXP[slot];
    						c.fishing = true;
    						c.fishTimer = 3 + Misc.random(2);
    						for(int i : CAGELOB) {
    							if(i == c.npcType) {
    								c.cagelob();
    							}
    						}
    						for(int i : HARPOON) {
    							if(i == c.npcType) {
    								c.harpoon();
    							}
    						}
    					}
    			} else {
    				c.sendMessage("You need a fishing level of " + req + " to fish here.");
    				resetFishing();
    			}
    		} else {
    			c.sendMessage("You do not have the correct equipment to use this fishing spot.");
    			resetFishing();
    		}
    	}
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Sep 2009
    Posts
    3,245
    Thanks given
    195
    Thanks received
    255
    Rep Power
    0
    How come that worked and the other didn't what did I do wrong?

    do you mind explainign arrays a little?

    I noticed once that int i had to be declared before and i = a certain variable, am I wrong?
    Reply With Quote  
     

  6. #6  
    Registered Member Ikki's Avatar
    Join Date
    Dec 2007
    Posts
    218
    Thanks given
    5
    Thanks received
    6
    Rep Power
    38
    Quote Originally Posted by Skepta View Post
    How come that worked and the other didn't what did I do wrong?

    do you mind explainign arrays a little?

    I noticed once that int i had to be declared before and i = a certain variable, am I wrong?
    Ok, let's teach you a bit.
    What is array? Array is variable which holds more than 1 value, each value has their own index number.

    Example:
    Code:
    String[] names = { "Bob", "Peter", "Joe" };
    names[0] - is Bob.
    names[1] - is Peter.
    names[2] - is Joe.

    That's the basics. What we did in your fishing method? We used FOR-EACH loop.

    Example how it works:
    Code:
    for(String i : names) {
        if(i == "Bob") {
            sendMessage("Bob is in array.");
        }
    }
    So what basicly FOR-EACH loop does, it takes value from array one by one (from index one - names[0] - to the last one - names[2]) and assign it's to variable (to String i - in example).

    So what we did in your fishing method? We checked if npc id was in array. And if it was, we started to fish. Get it?
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Sep 2009
    Posts
    3,245
    Thanks given
    195
    Thanks received
    255
    Rep Power
    0
    for(int i : CAGELOB) { //so this is making it check for the array saying it wants to use an array will look for it?
    if(i == c.npcType) { //this asks if the npctype is in the array?
    c.cagelob();//and this is the method
    }
    }

    I understand the way it holds more than 1 value kinda grouping a bunch of thngs, your description was usfull ty, but I'm still unsure what this code here actually means,


    Code:
    for(int i : CAGELOB) {
    Becasue with my limited java knowlade it asks if something { < open method, but this uses

    for(int i, what's the I mean also, why the letter I does it stand for anything specific? thx appriciate this alot (:
    Reply With Quote  
     

  8. #8  
    Registered Member Ikki's Avatar
    Join Date
    Dec 2007
    Posts
    218
    Thanks given
    5
    Thanks received
    6
    Rep Power
    38
    Code:
    for(int i : CAGELOB)
    It creates new integer i which will take all values from CAGELOB one by one. Once it has any value it starts to execute what is in brackets and than assigns other value and repeats it and that happens until there will be no values to assign.
    Reply With Quote  
     

  9. #9  
    Banned
    Join Date
    Nov 2006
    Posts
    1,132
    Thanks given
    5
    Thanks received
    17
    Rep Power
    0
    Quote Originally Posted by Skepta View Post
    So changed this..

    Code:
    if (c.npcType == 7944) {
    						c.cagelob();
    							}
    
    						if (c.npcType == 334) {
    						c.harpoon();
    						}
    to this..

    Code:
    					for(int i : CAGELOB) {
    					if(i == c.npcType) {
    						c.cagelob();
    						}
    					}
    Code:
    private final int[] CAGELOB = {7944,316,334,324};
    and added this, all in fishing.java, but when I click a cagelob npc there's no animation so it's not working for some reason mind explaining some more?
    Yes, except his coding conventions shouldn't resemble those of a retarded fishmonger.

    Code:
    for(int i; i < CAGELOB.length; i++) {
         if(CAGELOB[i] == c.npcType)
              c.cageLob();
    }
    Reply With Quote  
     

  10. #10  
    Registered Member Ikki's Avatar
    Join Date
    Dec 2007
    Posts
    218
    Thanks given
    5
    Thanks received
    6
    Rep Power
    38
    Quote Originally Posted by Webber View Post
    Yes, except his coding conventions shouldn't resemble those of a retarded fishmonger.

    Code:
    for(int i; i < CAGELOB.length; i++) {
         if(i == c.npcType)
              c.cageLob();
    }
    You are talking about me? And your code needs to be fixed.

    Code:
    for(int i; i < CAGELOB.length; i++) {
         if(CAGELOB[i] == c.npcType)
              c.cageLob();
    }
    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
  •