Simple, I hope understood.Code:for(int i : cagelob) { if(i == c.npcType) { c.cagelob(); } }
|
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)
Can i add an array like thisCode: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(); } }
how could I change if (c.npctype == 334) { to something like if (cagelob) {Code:private final int[] CAGELOB = {7944,316,334,324}; private final int[] HARPOON = {334,324};
Thxx rep++ ( Don't hate i'm trying to learn..)
Simple, I hope understood.Code:for(int i : cagelob) { if(i == c.npcType) { c.cagelob(); } }
So changed this..
to this..Code:if (c.npcType == 7944) { c.cagelob(); } if (c.npcType == 334) { c.harpoon(); }
Code:for(int i : CAGELOB) { if(i == c.npcType) { c.cagelob(); } }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?Code:private final int[] CAGELOB = {7944,316,334,324};
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(); } }
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:
names[0] - is Bob.Code:String[] names = { "Bob", "Peter", "Joe" };
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:
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).Code:for(String i : names) { if(i == "Bob") { sendMessage("Bob is in array."); } }
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?
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,
Becasue with my limited java knowlade it asks if something { < open method, but this usesCode:for(int i : CAGELOB) {
for(int i, what's the I mean also, why the letter I does it stand for anything specific? thx appriciate this alot (:
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.Code:for(int i : CAGELOB)
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |