ID:1510688
 
(See the best response by Stephen001.)
Problem description:
Alright, so following up on my previous post, I have investigated a few demos and libraries for equipment, and looked up mouse dragging and dropping. Using some snipets of code, I wound up with this for an inventory and equipment system.


objects.dm
obj/items
Stone
icon='basic resources.dmi'
icon_state="stone"
verb
Drop()
src.loc = usr.loc





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"



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) //When we drop it...
if(over_control =="Inventory.Inv") //If its inside the inventory window.
var/obj/O = over_object
src.screen_loc = O.screen_loc //Move the object on the new slot.
if(over_control =="Inventory.eqp")
if(G.screen_loc = "eqp:1,1")
usr << "Head"

var/obj/O = over_object
src.screen_loc = O.screen_loc

The other Code file being
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





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


Keep in mind, I am using codes not belonging to me, some at least. I am using this project as a learning experience to myself. Now, the issue at hand is that when I put the
    MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params) //When we drop it...
if(over_control =="Inventory.Inv") //If its inside the inventory window.
var/obj/O = over_object
src.screen_loc = O.screen_loc //Move the object on the new slot.
if(over_control =="Inventory.eqp")
if(G.screen_loc = "eqp:1,1")
usr << "Head"

var/obj/O = over_object
src.screen_loc = O.screen_loc


The issue is that when I added
if(G.screen_loc = "eqp:1,1")
to the screen dropping, two errors popped up.
Objects.dm:68:error: G.screen_loc: undefined var
Objects.dm:68:error: : missing expression


It doesn't seem to me like you define G in MouseDrop().
Btw just shouting out some stuff I noticed:
if (usr.numberof <= 35)

I'm assuming this should actually be
if (usr.numberof < 35)

The way you have it right now means there's 36 total slots, not 35.

Also:
                else   // If not...

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

The:
if(src in view())


is redundant, as it'll always be true, because if it wasn't that would mean the operation would not be able to start.

Just 2 things I noticed, busy atm. Anyway, will probably edit later if I notice more stuff.

Best response
The error tells you what is wrong. G(.screen_loc) is undefined in that procedure.

Reading through the bit you've copied from:

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)
if(over_control =="Inventory.Inv")
var/obj/O = over_object // <--- O is defined here.
src.screen_loc = O.screen_loc // <--- O is used here.


You see we need to create a local variable, O, and set over_object to it, before we can access it's screen_loc variable.

In the bit you've added:

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)
if(over_control =="Inventory.eqp")
if(G.screen_loc = "eqp:1,1") // <--- G is used. Where is it defined??
usr << "Head"

var/obj/O = over_object
src.screen_loc = O.screen_loc


There's no local variable 'G' defined, so this code cannot possibly compile. The naive solution, would be to define G, the same way you've defined O:

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)
if(over_control =="Inventory.Inv")
var/obj/O = over_object
src.screen_loc = O.screen_loc
if(over_control =="Inventory.eqp")
var/obj/G = over_object // <--- Now G is defined.
if(G.screen_loc = "eqp:1,1") // <--- And G is then used.
usr << "Head"

var/obj/O = over_object
src.screen_loc = O.screen_loc


However, I can see a bit of a pattern. For both inventory items, and equipment, we need to define some object variable, so we can access the screen_loc variable of the over_object. You see those duplicated lines?

Well, given that we need to do this, regardless of whether or not it's an inventory item, or equipment, lets move those lines up:

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)
var/obj/O = over_object // <--- O is defined here.
if(over_control == "Inventory.Inv")
src.screen_loc = O.screen_loc // <--- Then used here.
if(over_control == "Inventory.eqp")
if(O.screen_loc = "eqp:1,1") // <--- Or here.
usr << "Head"
src.screen_loc = O.screen_loc


There, got rid of the G variable entirely, and removed a bit of logical duplication. But we can take things one step further, and it's quite simple.

Presumably, you can't drop an object onto the inventory window, AND the equipment window at the same time. I mean, they can't really overlap. So, if the control we're dropping the object onto is the inventory window, it therefore must NOT be the equipment window.

We can express that, as an if ... else statement:

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
else if(over_control == "Inventory.eqp")
if(O.screen_loc = "eqp:1,1")
usr << "Head"
src.screen_loc = O.screen_loc

Thanks everyone. I appreciate the helpful community that the forums offer.