Here comes a wall.
After walking away last night and coming back today. Some of the advice make more sense(i think). And after looking I realise that I am mixing structures and the way that I do things…My problem is that my code gets heavy so I try to shorten things up. We didnt start here but we are here so here we go.
I probably should have said these things when we went here. I had a problem using “names” because when I click and move an item in my inventory from my “bag” to my equipped stuff, it just sticks the tile to the cursor so I can move it, click again to equip it or put it away. I cant use names because I ran accross a situation where my monsters dropped 2 novice_swords after I killed them, I had 2 Novice_swords in my bag. So when I try to manipulate or move a sword based on the name “Novice_Sword”, if I have more than 1 novice sword in my bag, they all stick to the cursor, they all add their values, and everything happens to all of them. The only way I could fix this was to assign an ID, which is one of my variables, to each novice sword item. So one of my variables is a ID.
main_dic= {“slot1”: [0, “Novice_Sword”, False, 1, True, “item”, 4, 0, whatever_the_ID_of_the_object_is],
“slot2”: [0, “Novice_Sword”, False, 1, True, “item”, 4, 0, whatever_the_ID_of_the_object_is],
“slot3”: [0, “empty”, False, 1, True, “item”, 4, 0, 0],
“weapon_slot”: [2, “Novice_Sword”, False, 1, True, “item”, 4, 0, whatever_the_ID_of_the_object_is]}
See I do feel that I have to mix numbers and names because there is a name, and an ID. I cant manipulate Items based on names because I may have more than 1. And If I do that, It happens to all of them.
but youll notice withing my inventory dict I have slot1, slot 2, etc, but I also have slots named, weapon_slot, helmet_slot, whatever…So the way Ive been handing it, is that if an item gets dropped into a slot with “equip” in the name(or as a property of that object), the first value gets changed to a 2, So that I know its equipped. So when I figure my attack power. Ill get my base stats, and add everything from the Dictionary that has a 2 as the 1st value which, means it is equipped. But I still get lines like this:
if own[“moving_item”] !=0 and mouse_over_any.hitObject != None and “equipslot” in mouse_over_any.hitObject and logic.globalDict[“inv_dict”][mouse_over_any.hitObject[“equipslot”]][1] == “none” and mouse_over_any.hitObject[“equipslot”] == logic.globalDict[“item_description_dict”][logic.globalDict[“inv_dict”][n[0]][1]][8] and logic.globalDict[“item_description_dict”][logic.globalDict[“inv_dict”][n[0]][1]][0] == “equipment” and logic.globalDict[“player_dict”][“level”] >= logic.globalDict[“item_description_dict”][logic.globalDict[“inv_dict”][n[0]][1]][9]:
Hows that for a condition check?
The condition breaks down like this, n is looked up earlier as im moving stuff around and just compares the items visual id to the visual id that I stored and gave the item when it was loaded(I do think I can clean that up a bit)…The rest of the condition is like this:
1.Am I moving an item(I dont want it to do anything if im not moving an item. This turns to the items ID if im moving an item and the item sticks to the cursor. If I dont have this and just stick an item to the cursor when I click on it guess what happens if I click more than 1 item, Yes They all stick, they all get manipulated. So it needs to see if Im moving an Item currently…Eg. If Im already moving an Item, I cant pick up another item, If I do something with the item Im moving, do something to the dictionary representation of that item)
2. If Im over something (or I get a Nonetype error if I click in empty space)
3. If “equip_slot” is in what Im clicking(Ill change the 1st value to 2 to know its equipped else im just droppping it in another bag slot.)(And theres more to it…potions to action bar only, and dont put weapons on the action bar, dont put potions in weapon slots…it goes deep)
4. If the slot doesnt equal “None”(If something was in the slot, that items name would be here, when I take an item out we change the old slots value to “None”, so we know what the slot is empty again)
5. if the 8th value is the same(the 8th value looks into another dictionary that has each items attributes and looks into by name only. This dictionary contains what slot an item can go into as its eight entry. So I cant put a shield on my head where a helmet goes EX. Is this slot your over a helmet_slot and is what your moving a helmet)
6. Is what your are moving equipment?(checks the same above dictionary where “equipment” is the [1] value of sword, so that I cant put a potion or key in my hand or on my head because they are “key” or “potion”, not “equipment”
7. Check your level against the items required level(Is your level greater then the required level of the item also pulled from the same dictionary, theres a whole other dictionary whats starts with “Novice sword”, its used to check attributes of itemssuch as “novice_sword” )and every item
And If all the conditions are true. Is puts the visual object there, snaps it to its slot, and copies everything in the dictionary from bag_slot[whichever] to helmet_slot, changes the first value to a 2 so I know its equipped. Adds all entries together with a 2 in front(equippeditems), and that have phys_def as its attribute(another long statement) and tell me my physical defense. Else it snaps the object back where it was and changes nothing in the dictionary.
See I have 3 or 4 dictionaries going on at one time. One for slots, one that contains an items attributes, one that contains base stats. and the value positions line up(that my way of making it easier)
My saver has been in my else…if all the conditions arent true…it doesnt move the item. But as you can see it gets deep quick.
My problem with not mixing integers and strings, Is that I cant manipulate an item on screen based on name. If I have more than 1 item with the same name they all do it. and, I cant look up an items attributes by integer, items attributes are looked up from the dictionary by name. This would require me to give each item an integer value which would make even more confusion.
I do appreciate all of the advice and like i said after coming back and looking at some of you alls suggestions, I think I can clean some stuff up and ill have it a try. But as I wrote and certain things happened (Oh my that potion went into a shield slot, Ive alrady got an item Im moving but instead of clicking the empty slot, I accidently clicked the other sword. It picks that up to). I have to check lots of certain conditions to keep bad things from happening. And when your checking to make sure(Im over something, this is an equipment slot not an empty inventory slot, im holding equipment, my levels high enough, theres not already something in that slot, that type of item goes in that type of slot)OK all good, do it and go ahead and save to the file that you just put that item in that slot, so if your game crashes, when you come back, that Item will be in that slot. The stuff becomes a mess.
I see where I can clean up a few things and make it more legible, So Ill start there…(such as referring to values by names instead of numbers). Ill see how far I can get with that. Thanks for your helps guys.
yar, it be mangling me words it does.
yes, yes it does