ID:1612046
 
(See the best response by FKI.)
Code:
mob
proc
UpdateInvGrid()
var/x = 1
src << output ("Items","InvGrid:1,[x]")
for(var/obj/i in contents)
src << output(i,"InvGrid:1,[++x]")
src << output(i.Amount,"InvGrid:2,[++x]")


obj
Click()
if (src in oview(1,usr))
var/obj/Found //Var to tell if object is already in inventory
for(var/obj/O in usr.contents)
if(O.type == src.type)
Found = O
break
if(Found)
Found.Amount ++
del src
else
usr.contents += src
del src
usr << ("You picked up an [src.name]")
usr.UpdateInvGrid()


Problem description:
When I pick up an Item it's not showing into the inventory grid, and also is that the proper way to display amount in a grid? Or would you use a suffix anyways I am new to grids...
I personally split my stack check code from click procs because I sometimes make my clicks conditional, and the code looks like this

obj
proc
Stack(var/mob/M)
var/obj/O = locate(src.type) in M.contents
if(!isnull(O))
O.Stacks += src.Stacks ; src.loc = null
return 1 // Stack success
else
M.contents += src
return 0 // Didn't add stacks

I use return [number] because I like to use procs in conditionals frequently, but it's not necessary.
Conditionals? Outputting the grid itself? You've got me a little confused..
You output to the grid like you output to any other control.

var/obj/Apple/A = new
src << output(A, "grid")


Conditionals are if/else statements.

It looks like you're trying to do a 2xN grid where you output the item and the number of items beside it, but you've got a syntax error logic error, sorry.
Ok so I added
src<< output("Amount","InvGrid:2,[x]")


So now Amount is showing but how is my sytax not correct? If that was the case the compiler wouldn't compile it because the code must match it's syntax.
The compiler won't pick up interface errors because they're all due to strings being case-sensitive.

Be wary of your ++x and x++
I normally do like i++ but it wouldn't work for grids for I used ++i(well x but no difference just a var). Anyways If I take out the item stacking and do it like this
obj
Click()
if (src in oview(1,usr))
usr.contents += src
usr << ("You picked up an [src.name]")
usr.UpdateInvGrid()


It actually gets added to the grid perfectly but of course when I do that I have no item stacking so it has to do with how I do item stacking.
Looking at your item stacking code, it's wrong. Look at it line by line.

obj
Click()
if (src in oview(1,usr))
var/obj/Found //Var to tell if object is already in inventory
for(var/obj/O in usr.contents)
if(O.type == src.type)
Found = O

This is (sorta) fine. The issue comes next.

if(Found)
Found.Amount ++
del src
else
usr.contents += src
del src


Found = null if it wasn't found on the first object. So if you're looking for Y but your inventory is (X, Y), you'll go to the else. THEN, you'll add src to the usr's contents... and promptly delete it.
I figured it out! Well you did I just got to getting your logic in my own style.

                
mob
proc
UpdateInvGrid()
var/x = 1
src << output ("Items","InvGrid:1,[x]")
src<< output("Amount","InvGrid:2,[x]")
for(var/obj/i in contents)
src << output(i,"InvGrid:1,[++x]")
src << output(i.Amount,"InvGrid:2,[++x]")



obj
Click()
if (src in oview(1,usr))
var/obj/O = locate(src.type) in usr.contents
if(!isnull(O))
O.Amount += src.Amount
src.loc = null
return 1 //SUCCESS!
else
usr.contents += src
return 0
usr << ("You picked up an [src]")
usr.UpdateInvGrid()
Best response
It's probably worth noting your Click() proc will never update the clicker's inventory.
Yea it does.
In response to The WardenX
I think he means the last two lines are unreachable, as the procedure returns before them in all cases.