ID:1512180
 
(See the best response by Pirion.)
Problem description:
Alright, so, thus-far, the forums have been more helpful than I had first imagined. And as much as I dislike having to come here for help(I'd rather be able to understand things through my own effort), I have run into yet another snag. In my previous "Help wanted" post ( http://www.byond.com/forum/?post=1510688 ) I had great assistance with my inventory/equipment system. However, I ran into a snag to where the position of the item in the equipment/inventory grid was not saved, and when placed in the equipment grid, it just did not stay. Blow, are some pictures, and some of the code demonstrating the issue. Please keep in mind, I am using snippets, and information from other bits of code, and although I have edited, and added my own content overall, I claim no ownership or rights to the information, but rather I am using it to learn DM.


Inventory.dm
mob/verb/CloseInventory()
winshow(src,"Inventory",0) //Hide the inventory window!

mob/verb/Inventory()
winshow(src,"Inventory",1) //Show the inventory window!
var/Position = winget(src, "default", "pos") // Get the position of the "default" window and assign it to a var called "Position"
winset(src,"Inventory","pos='[Position]'") // Set the position of the "Inventory" window to the same position as our main window.
src.client.screen = null //Clear the inventory before generating everything inside.
for(var/Column = 1 to 5) for(var/Row = 1 to 7) //Create a grid composed of 5 columns and 5 rows.
var/Grid/G = new
G.screen_loc = "Inv:[Row],[Column]"
src.client.screen += G
for(var/obj/I in src.contents) src.AddItems(I) //Generate the items on slots.
for(var/Column = 1 to 3) for(var/Row = 1 to 3) //Create a grid composed of 5 columns and 5 rows.
var/Grid/G = new
G.screen_loc = "eqp:[Row],[Column]"
src.client.screen += G



mob/proc/AddItems(obj/I)
for(var/Grid/G in src.client.screen)
if(G.used) continue
I.screen_loc = G.screen_loc ; src.client.screen+=I
G.used =1 ; return

mob/proc/SaveItems(obj/I)
for(var/Grid/O in src.client.screen)
if(O.used) continue
I.screen_loc = O.screen_loc ; src.client.screen+=I
O.used =1 ; return


obj/items
MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...

var/icon/I = new(src.icon,src.icon_state)//this is so the cursor icon transforms into the item itself...cool little effect.
mouse_drag_pointer = I // now lets set the mouse cursor to that.

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)
var/obj/O = over_object
if(over_control == "Inventory.Inv")
src.screen_loc = O.screen_loc
if(over_control == "Inventory.eqp")

usr.numberof -= 1
usr.numbereqp += 1
src.screen_loc = O.screen_loc

Grid
parent_type = /obj
icon = 'Inventory.dmi'
icon_state = "Grid"
var/used = 0





Objects.dm
obj/items
Stone
icon='basic resources.dmi'
icon_state="stone"
density = 0
matqual= 5
matdur= 20
var
matqual= 1
matdur= 1


Plank
icon='basic resources.dmi'
icon_state="plank"
density = 0
matqual= 1
matdur= 10




verb
Drop()
src.loc = usr.loc
usr.numberof -= 1




DblClick() //When you double click
if(src in oview(1))
if (usr.numberof <= 35)

usr << "[usr.numberof]"
usr.numberof += 1
if(src in usr.contents) //If the item is inside my inventory
usr.Description(src) //Give the USER, the description of the item -> src (GO TO "Item Description.dm" for more info)
return
else // If not...

if(src in view())
usr.contents.Add(src)





return
else
usr << "Too far"
else
usr << "Inventory is full"





Variables
mob
var

gen='Male.dmi'
rpname= ""
pota= 0
wepdmg= 1
heal=0
invt=0
hitchance= 0
invtr= 0
numbereqp = 0





Pictures of the window


This is the first step, by double clicking the user adds items to their inventory. Opening the inventory, displays the items in the bottom left of the inventory "inv" window.

Step 1
Image and video hosting by TinyPic



This demonstrates the user taking the second step, moving the item to the desired location.

Step 2
Image and video hosting by TinyPic


Keep in mind, the inventory and equipment menu share a window. Upon re-loading the inventory/equipment window, it is all reset back into the starting location.


Step 3 (The situation in which the items reset to their original area)
Image and video hosting by TinyPic

(Credit for the used parts of code, go to; Kidpaddle45 )
Best response
This:

mob/proc/AddItems(obj/I)
for(var/Grid/G in src.client.screen)
if(G.used) continue
I.screen_loc = G.screen_loc ; src.client.screen+=I
G.used =1 ; return


It says pick the first open grid in the client.src and add the item there. You will need to change it to pass it's previous screen_loc rather than re-setting it. Maybe changing this line as follows:


mob/proc/AddItems(obj/I)
for(var/Grid/G in src.client.screen)
if(G.used) continue
if(!I.screen_loc) //only set if it doesn't have a screen location.
//if picking up a new object, you'll want to set it to null
I.screen_loc = G.screen_loc
src.client.screen+=I
G.used =1
return


Thank you Pirion
You got another problem here. When you use usr.numberof +=1
you have it add +1 even if it's already in your inventory.
maybe moving it would help. Other wise if people repeatedly clicked on the item in to view the description they would be adding more to the list. just sayin =P
    DblClick() //When you double click
if(src in oview(1))
if (usr.numberof <= 35)

usr << "[usr.numberof]"
usr.numberof += 1
if(src in usr.contents) //If the item is inside my inventory
usr.Description(src) //Give the USER, the description of the item -> src (GO TO "Item Description.dm" for more info)
return
else // If not...

if(src in view())
usr.contents.Add(src)