View Single Post
Old 29/05/2020, 12:35 PM   #2
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Posts: 828
Reputation: 200
Default Re: What's wrong with the loop?

If I get it correctly, you want items to be added up to the same slot in case they are the same type, but instead they are added to other slots instead of being added to the same slot?

If so, you need to loop through inventory slots to check if the slot is used and the type of item you're adding is matching the one in the slot.

Don't return zero if the condition is not met because it will just stop the loop and the rest of code from working. And just a tip, whenever your condition is met, you can break the loop using 'break' instead of returning a value.

Back to the topic, if the item wasn't added to an existing slot, you can continue to make another loop so that it is added to a free slot, then you can break the loop if it is added to one slot, like use "break" after you add the item to a slot, so that it doesn't continue through all the other slots.

And finally, you can update the inventory independently without being added to the loop(s) at all.
__________________
Need a game server? Contact me for information.
Variable™ is offline   Reply With Quote