Thread: Differences between these deleteItem methods?

Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1 Differences between these deleteItem methods? 
    Registered Member Rememberm3's Avatar
    Join Date
    Aug 2013
    Posts
    1,716
    Thanks given
    56
    Thanks received
    108
    Rep Power
    129
    I have 5 different delete item methods,
    can you maybe explain to me what the differences are and which one you should use in what situation?
    These are the methods:
    Code:
    public void deleteItem(int id, int amount) {
    		deleteItem(id, getItemSlot(id), amount);
    	}
    
    	public void deleteItem(int id, int slot, int amount) {
    		if(id <= 0) {
    			return;
    		}
    		for (int j = 0; j < c.playerItems.length; j++) {
    			if (amount <= 0)
    				break;
    			if (c.playerItems[j] == id + 1) {
    				c.playerItems[j] = 0;
    				c.playerItemsN[j] = 0;
    				amount--;
    			}
    		}
    		resetItems(3214);
    	}
    	
    	public void deleteItem2(int id, int amount)	{
    		for (int i = 0; i < c.playerItems.length; i++) {
    			if (amount == 0) {
    				break;
    			}
    			if (c.playerItems[i] == (id+1))	{
    				if (c.playerItemsN[i] > amount)	{
    					c.playerItemsN[i] -= amount;
    					break;
    				}
    				else {
    					c.playerItems[i] = 0;
    					c.playerItemsN[i] = 0;
    					amount--;
    				}
    			}
    		}
    		resetItems(3214);
    	}
    
    	public void specialDeleteItem(int id, int amount) {
    		int slot = getItemSlot(id);
    		if(id <= 0 || slot < 0) {
    			return;
    		}
    		if (c.playerItems[slot] == (id+1)) {
    			if (c.playerItemsN[slot] > amount) {
    				c.playerItemsN[slot] -= amount;
    			} else {
    				c.playerItemsN[slot] = 0;
    				c.playerItems[slot] = 0;
    			}
    		}
    	}
    
    	public void specialDeleteItem(int id, int slot, int amount) {
    		if(id <= 0 || slot < 0) {
    			return;
    		}
    		if (c.playerItems[slot] == (id+1)) {
    			if (c.playerItemsN[slot] > amount) {
    				c.playerItemsN[slot] -= amount;
    			} else {
    				c.playerItemsN[slot] = 0;
    				c.playerItems[slot] = 0;
    			}
    		}
    	}
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered MrClassic
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    15
    Posts
    2,063
    Thanks given
    24,154
    Thanks received
    551
    Rep Power
    5000
    deleteItem method is removing the item + all of its amount.

    deleteItem2 method is removing the items + amount GIVEN to remove.

    specialDeleteItem(int, int) and specialDeleteItem(int, int, int) -> no differences... the specialDeleteItem(int, int, int) method would be more efficient though.

    Reply With Quote  
     

  3. #3  
    Donator


    Join Date
    Jul 2011
    Posts
    570
    Thanks given
    135
    Thanks received
    142
    Rep Power
    291
    nvm above has it correct
    Reply With Quote  
     

  4. #4  
    Registered Member Rememberm3's Avatar
    Join Date
    Aug 2013
    Posts
    1,716
    Thanks given
    56
    Thanks received
    108
    Rep Power
    129
    Quote Originally Posted by IBAN. View Post
    deleteItem method is removing the item + all of its amount.

    deleteItem2 method is removing the items + amount GIVEN to remove.

    specialDeleteItem(int, int) and specialDeleteItem(int, int, int) -> no differences... the specialDeleteItem(int, int, int) method would be more efficient though.

    Ah okay, I can just put these methods into one I guess?

    Quote Originally Posted by Empathy View Post
    nvm above has it correct
    Thanks for the explanation, though. I'll try to make it cleaner


    Btw, what would you two suggest. Doing with the slot int or make it loop through all the items in the inventory?
    Attached image
    Reply With Quote  
     

  5. #5  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    public void deleteItem(int id, int amount) --> Deletes a certain ID item of the given amount, however will automatically pick the slots starting from the top.

    public void deleteItem(int id, int slot, int amount) --> Apparently it loops through all inventory slots checking for the given item. If the ID of the item equals the item the player's attempting to delete (I'm guessing, not quite fully understanding the +1 addition there, as to why it's necessary), it will set the item's id and amount to zero and decrement the variable 'amount' by one (Also not sure as to why this is necessary as the variable is no longer used afterwards), after which it will reset the items in the inventory (I'm guessing resetItems(3214) refers to refreshing the inventory container items, don't quote me on this though). NOTE: The 'slot' variable is NOT used within the method, completely and utterly useless variable.

    public void deleteItem2(int id, int amount) --> Loops through inventory slots, same shit as before basically, however this time it will decrement the amount of the item only UNLESS the item's amount is lower than the variable amount (AKA player has less of the item than it's attempting to remove), in which case it will set the item's ID and amount to zero and decrement the amount variable once again for no apparent reason. After which it resets the container again (Once again just guessing).

    public void specialDeleteItem(int id, int amount) --> Starts off by getting the item's slot in player's inventory (Returning the method if the ID equals or is below 0 or if the slot is zero), after which it will check if the item still is the item they're trying to modify (Honestly, a quite useless check), after which it will check if the player has more of the item than attempting to delete, in which case it will just decrement the item's amount, otherwise it will set the item's ID and amount to zero once again. Interestingly enough, the container isn't being 'refreshed' this time.

    public void specialDeleteItem(int id, int slot, int amount) --> Will immidiately check if the item in the given slot actually is the very same item, after which it'll decrement the amount of possible, otherwise it will just set the amount and ID to zero once again (Just as with others).

    Note I didn't include the descriptions of the returning parts in here (Except for one), although I must say.. These methods are poorly coded and could all be combined into just one simple method, or two if you're into simplicity and wish not to constantly include the slot variable (Although I don't really even need the need to get the slot ID.. This is pretty much a dynamic variable that changes all the time, why'd anyone even wish to define it by hand when you can just check the inventory for slot?).


    ANOTHER NOTE: I thought this thread had no replies, smh. How did I not see this had already been answered lmao.
    Reply With Quote  
     

  6. #6  
    Registered Member Rememberm3's Avatar
    Join Date
    Aug 2013
    Posts
    1,716
    Thanks given
    56
    Thanks received
    108
    Rep Power
    129
    Quote Originally Posted by Eldritch View Post
    public void deleteItem(int id, int amount) --> Deletes a certain ID item of the given amount, however will automatically pick the slots starting from the top.

    public void deleteItem(int id, int slot, int amount) --> Apparently it loops through all inventory slots checking for the given item. If the ID of the item equals the item the player's attempting to delete (I'm guessing, not quite fully understanding the +1 addition there, as to why it's necessary), it will set the item's id and amount to zero and decrement the variable 'amount' by one (Also not sure as to why this is necessary as the variable is no longer used afterwards), after which it will reset the items in the inventory (I'm guessing resetItems(3214) refers to refreshing the inventory container items, don't quote me on this though). NOTE: The 'slot' variable is NOT used within the method, completely and utterly useless variable.

    public void deleteItem2(int id, int amount) --> Loops through inventory slots, same shit as before basically, however this time it will decrement the amount of the item only UNLESS the item's amount is lower than the variable amount (AKA player has less of the item than it's attempting to remove), in which case it will set the item's ID and amount to zero and decrement the amount variable once again for no apparent reason. After which it resets the container again (Once again just guessing).

    public void specialDeleteItem(int id, int amount) --> Starts off by getting the item's slot in player's inventory (Returning the method if the ID equals or is below 0 or if the slot is zero), after which it will check if the item still is the item they're trying to modify (Honestly, a quite useless check), after which it will check if the player has more of the item than attempting to delete, in which case it will just decrement the item's amount, otherwise it will set the item's ID and amount to zero once again. Interestingly enough, the container isn't being 'refreshed' this time.

    public void specialDeleteItem(int id, int slot, int amount) --> Will immidiately check if the item in the given slot actually is the very same item, after which it'll decrement the amount of possible, otherwise it will just set the amount and ID to zero once again (Just as with others).

    Note I didn't include the descriptions of the returning parts in here (Except for one), although I must say.. These methods are poorly coded and could all be combined into just one simple method, or two if you're into simplicity and wish not to constantly include the slot variable (Although I don't really even need the need to get the slot ID.. This is pretty much a dynamic variable that changes all the time, why'd anyone even wish to define it by hand when you can just check the inventory for slot?).


    ANOTHER NOTE: I thought this thread had no replies, smh. How did I not see this had already been answered lmao.
    hahaha, but you explained it very well, thanks!
    I tried to combine the methods, what do you think of this?
    Code:
    public void deleteItem(int id) {
    		deleteItem(id, c.getItems().itemAmount(c.playerItems[getItemSlot(id)]));
    	}
    	
    	public void deleteItem(int id, int amount) {
    		if (id <= 0 || amount <= 0)
    			return;
    		if (c.playerItems[getItemSlot(id)] == (id+1)) {
    			if (c.playerItemsN[getItemSlot(id)] > amount) {
    				c.playerItemsN[getItemSlot(id)] -= amount;
    			} else {
    				c.playerItemsN[getItemSlot(id)] = 0;
    				c.playerItems[getItemSlot(id)] = 0;
    			}
    		}
    	}
    Attached image
    Reply With Quote  
     

  7. #7  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by RememberM3 View Post
    hahaha, but you explained it very well, thanks!
    I tried to combine the methods, what do you think of this?
    Code:
    public void deleteItem(int id) {
    		deleteItem(id, c.getItems().itemAmount(c.playerItems[getItemSlot(id)]));
    	}
    	
    	public void deleteItem(int id, int amount) {
    		if (id <= 0 || amount <= 0)
    			return;
    		if (c.playerItems[getItemSlot(id)] == (id+1)) {
    			if (c.playerItemsN[getItemSlot(id)] > amount) {
    				c.playerItemsN[getItemSlot(id)] -= amount;
    			} else {
    				c.playerItemsN[getItemSlot(id)] = 0;
    				c.playerItems[getItemSlot(id)] = 0;
    			}
    		}
    	}
    Seems fine to me, although you are missing what I presume is the "inventory refreshing" part (resetItems(3214)).

    & In case you're wondering, the getItemSlot(id) method actually still loops through your inventory, however it will return when it finds a match immidiately, leaving the rest be as they are. So I believe you should still loop through every item in inventory, because not all items are stackable so regardless of the amount, only one item would be removed from the inventory(if not stackable).. I'm guessing? Not quite sure as I'm seeing this very flaw in all methods of this type.
    Looking at the loops above, I don't understand the reason why someone's using a break there? Break ends the loop at the given spot.

    So say, if someones inventory consisted of these items:
    1255, 1255, 1201, 1209 --> All item IDs.

    If they were to use the deleteItem method on item ID 1255 on amount 2 or bigger, they'd still logically wind up deleting just the very first item. Instead of the breaks the person should've written continue; as it will just skip the given entry and go on to the next.
    Reply With Quote  
     

  8. #8  
    Registered Member
    bracket's Avatar
    Join Date
    Aug 2009
    Posts
    5,278
    Thanks given
    1,059
    Thanks received
    1,465
    Rep Power
    5000
    Quote Originally Posted by RememberM3 View Post
    hahaha, but you explained it very well, thanks!
    I tried to combine the methods, what do you think of this?
    Code:
    public void deleteItem(int id) {
    		deleteItem(id, c.getItems().itemAmount(c.playerItems[getItemSlot(id)]));
    	}
    	
    	public void deleteItem(int id, int amount) {
    		if (id <= 0 || amount <= 0)
    			return;
    		if (c.playerItems[getItemSlot(id)] == (id+1)) {
    			if (c.playerItemsN[getItemSlot(id)] > amount) {
    				c.playerItemsN[getItemSlot(id)] -= amount;
    			} else {
    				c.playerItemsN[getItemSlot(id)] = 0;
    				c.playerItems[getItemSlot(id)] = 0;
    			}
    		}
    	}
    It'd be wiser to set the item to -1 since java starts counting from 0. (i believe 0 is dwarf remains item thingy)
    Reply With Quote  
     

  9. #9  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Bracket View Post
    It'd be wiser to set the item to -1 since java starts counting from 0. (i believe 0 is dwarf remains item thingy)
    From what I understood on thorough examination of the methods, I believe the "resetItems(containerId)" method will 'clear' all of the items which have ID of 0(and maybe below, too). This is strictly based off of the fact that all of the methods used to set the id to zero and I don't see a help thread anywhere requesting assistance on why all items deleted are being turned into dwarf remains.

    But yeah I see your confusion, the PI code is one hell of an ugly piece to process, still trying to process myself as to why this base got so popular lol.
    Reply With Quote  
     

  10. #10  
    Registered Member Rememberm3's Avatar
    Join Date
    Aug 2013
    Posts
    1,716
    Thanks given
    56
    Thanks received
    108
    Rep Power
    129
    Quote Originally Posted by Eldritch View Post
    From what I understood on thorough examination of the methods, I believe the "resetItems(containerId)" method will 'clear' all of the items which have ID of 0(and maybe below, too). This is strictly based off of the fact that all of the methods used to set the id to zero and I don't see a help thread anywhere requesting assistance on why all items deleted are being turned into dwarf remains.

    But yeah I see your confusion, the PI code is one hell of an ugly piece to process, still trying to process myself as to why this base got so popular lol.
    hahaha, the codes are horrible indeed.
    The problem I am having with the method atm is:
    when i have like 5 whips in my inventory and I try to delete 2 of them, it deletes them all,
    however if I try to do it with money, which is stackable, it just deletes 2 coins.
    Code:
    public void deleteItem(int id, int amount) {
    		if (id <= 0 || amount <= 0)
    			return;
    		for (int j = 0; j < c.playerItems.length; j++) {
    			if (c.playerItems[j] == (id+1)) {
    				if (c.playerItemsN[j] > amount) {
    					c.playerItemsN[j] -= amount;
    				} else {
    					c.playerItemsN[j] = 0;
    					c.playerItems[j] = 0;
    				}
    			}
    		}
    		resetItems(3214);
    	}
    Attached image
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. What's the difference between these TV's?
    By Snow Cat123 in forum Chat
    Replies: 0
    Last Post: 06-25-2013, 04:39 PM
  2. Replies: 23
    Last Post: 01-04-2013, 12:20 AM
  3. Spot the difference between these two:
    By Teemuzz in forum Requests
    Replies: 3
    Last Post: 06-27-2012, 09:36 AM
  4. whats the difference between these.
    By digistr in forum Application Development
    Replies: 2
    Last Post: 07-15-2010, 09:22 PM
  5. The difference between these?
    By mige5 in forum Help
    Replies: 8
    Last Post: 06-21-2009, 10:26 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •