where is the code showing what happens when you drag the sword to the active slot?

From the above code, I see that you have the active weapon slot set with what I assume to be just an empty square to represent an inventory space. I think what you need to do via code is set
Code:
inv_slots[0] = item_sword;


For some reason though, I feel like the visual inventory will get messed up by overwriting the inventory to the sword, although the sword should be created.