ID:875122
 
(See the best response by Solomn Architect.)
Code:
obj/item/var
item_inHand = 0
item_Slot = "None"
item_slotInhabited="None"

//obj/item/clothing/var
//item_Slot = "None"

obj/item/clothing/shirt/
icon = 'clothing.dmi'
icon_state = "shirt"
item_Slot = "equip_Shirt"

obj/item/clothing/shirt2/
icon = 'clothing.dmi'
icon_state = "shirt2"
item_Slot = "equip_Shirt"

///Picking up///

obj/item/Click()
var/mob/human/player/M=usr
if (M.vars[M.hand_Selected]=="Nothing")
if(usr in view(src,1))
//Pick up item
if(!(src in M))
M.vars[M.hand_Selected]=src
src.item_slotInhabited=M.hand_Selected
src.Move(M)
//Swap item between hands
if(src in M)
if (src.item_slotInhabited == "hand_Left" || "hand_Right")
M.vars[M.hand_notSelected]="Nothing"
M.vars[M.hand_Selected]=src
src.item_slotInhabited=M.hand_Selected
world << "[src] is in, \"[src.item_slotInhabited]\""
//Move item from inventory to hands
//else
//M.vars[src.item_Slot] = "Nothing"


obj/item/clothing/verb/Wear()
var/mob/human/player/M=usr
if(src.item_slotInhabited == "hand_Left" || "hand_Right")
if (M.vars[src.item_Slot] == "Nothing")
M.vars[src.item_slotInhabited] = "Nothing"
M.vars[src.item_Slot] = src
src.item_slotInhabited = src.item_Slot
world << "[src] is in, \"[src.item_slotInhabited]\""


Problem description:
First off, sorry about the length of this post. I just wanted to describe what I'm trying to do as thoroughly as possible.

item_Slot tells the item where it should go when it's equipped.

item_slotInhabited returns the current slot (variable in string form) the item inhabits.

hand_Selected and hand_notSelected returns the current selected hand (variable in string form) and the current unselected hand, respectively.

Basically, when the player clicks on an item while it's on the ground, it moves it the their currently selected hand and updates. If the player switches hands and clicks the item, it moves it to their currently selected hand. If the player uses the Wear() verb while the item is in either of the player's hands, it moves it to the slot designated by the variable item_Slot. With each of these actions, item_slotInhabited is updated to reflect the items current slot.

At the moment, if the player clicks on an item which isn't on the ground or in either of their hands, nothing should happen, because the variable item_slotInhabited doesn't meet the condition if (src.item_slotInhabited == "hand_Left" || "hand_Right"). But, for some inexplicable (for me, at least) reason, it does: the item is "moved" to the currently selected hand, while a duplicate item remains. My first impression was that item_slotInhabited wasn't being updated correctly, but after throwing in a piece of debug text (world << "[src] is in, \"[src.item_slotInhabited]\"") I knew that this wasn't the case

I'm guessing that I've made some sort of syntax error, but I have no idea what. I've tinkered around with it for a while now and haven't really gotten any closer to a solution. Any help would be appreciated.
Best response
Your code is covered in redundancies that not only make the code much harder to read, but most likely are the contributors for your problem. I believe the source of your issues lies in the Wear() verb. You're trying to find and change "src.vars" while looking in the "M.vars."

It's like you have two boxes of balls in front of you, one labeled blue, the other red. Right now, you're trying to dig through the red box to find a blue ball, when you could just look two feet over and check the other one.

Try removing the M.vars[] from your code entirely. I see no real purpose of them and they're just causing more problems than they're solving. Right now, since the game is trying to change variables that don't exist in a certain box, nothing get changed, therefor the variables remain the same and can pass your if() statements without any problems.
Thank you for your speedy reply! I took a short break and thought about the problem, and I figured out what I did wrong: I used the || operator incorrectly.

I had written it out as:
(src.item_slotInhabited == "hand_Left" || "hand_Right")


When the correct format was:
(src.item_slotInhabited == "hand_Left" || src.item_slotInhabited =="hand_Right")


After realizing my mistake, my expression resembled Picard's in your avatar.

However, your analysis of my code is actually really helpful, since I'm pretty new to this and am still laboring under the illusion that "complex = better" when it in fact the opposite is true. Looking back on it, I'm not really sure why I decided to use vars[] so much, I guess I had the idea that it was necessary to pass strings off as variables. I'll try to trim my code down a bit and remove some of the more flagrant redundancies.

Amusingly, my original attempt at making this work used switch statements to determine which hand was currently selected and was far more cumbersome than my current iteration.

Again, thank you for your critique, it's really helped me to identify the flaws in my methods.
Programmers are miraculously lazy individuals and that's what we're best at. It takes someone lazy enough to say, "There has to be an easier way." in order to condense things down and make it more efficient. Oddly enough, programing is a bit counter intuitive. The less work you do, the more efficient and bug free your system becomes, generally.
In response to Solomn Architect
As you'll learn early into programming, rushing into things and speeding through is a horrible way to do things.

Once you realise that, the challenge is continuing on without going too slow.

Biggest challenge I face in programming was slowing down and taking my time. There's always so much to do- so much that needs done. And not doign those things as quickly as posible is against my personality; I am a 'if it needs done, do it' kinda guy.

But programming is worse than everything else when it comes to that 'never perfect' aspect. And as humans we CANNOT know everything about anything. This is 2x the case with programming.

Enough getting off-topic though. My badz.