tracy08172002
Member
Looking for tips on how to keep code clean, legible, and tidy. Particularly with nested If statements. I try my best to remember basic coding etiquette and I understand how everything works as I see it. Currently, I am the only one who needs to understand it as well so I'm not worried about if others can understand it as I do. I just find everything to be so cluttered when things get really in depth. I've made loops and switches to clean up some things that could help simplify things at a glance but I feel they can get just as convoluted as the trillion IF statements they handle.
I'm attaching an example of my style of coding if you care to look or if you'd like to attach some of your own I'd be happy to see them along with your reply. I'm not really looking for critiques on the logistics of how my code works since for my purposes it works for what I need it to do. More so just looking for ideas of how to be more visually structured and organized. I would love to hear from you and get any examples you may have to show.
I'm attaching an example of my style of coding if you care to look or if you'd like to attach some of your own I'd be happy to see them along with your reply. I'm not really looking for critiques on the logistics of how my code works since for my purposes it works for what I need it to do. More so just looking for ideas of how to be more visually structured and organized. I would love to hear from you and get any examples you may have to show.
Code:
//Adding Inventory
for(i = 0; i<MaxSlots; i++)
{
if(AddInv = true)//if obj_Player passes action to add inv (stores ItemID which is crop's image index +1)
{
switch(InvSlot[i])//cycle through InvSlots and check values
{
case ItemID: ItemStack[ItemID-1] ++;AddInv = false; break; //If Item already exists in any inventory slot simply add to the stack count
case 0: //If current slot has no value
switch(ItemStack[ItemID-1]) //Check stacks of the ItemID
{
case 0: InvSlot[i] = ItemID; ItemStack[ItemID-1] ++; AddInv = false; break //If Item has no stack value add Item to slot and add to stack count
case !0: InvSlot[i] = 0; ItemStack[ItemID-1] ++; AddInv = false; break //If Item does have stack value add nothing to the slot and add to stack count
}
;break
}
if(InvSlot[(MaxSlots-1)] != 0)//prevents adding items when current maxslots are full
{
AddInv = false;
}
}//end of if AddInv = true
}//end of Adding Inventory for loop