ID:158803
 
mob
var/tmp/row = 1
var/tmp/col = 1
proc
AddBP(item)
var/obj/O
for(O in winget(src,"backpack.BP","current-cell=[row],[col]"))
if(winget(src,"backpack.BP","current-cell=[row],[col]") == 1)
row++; col++
continue
else
src << output(item,"BP:[row],[col]")


I have this so far, I didn't figure it would work, but I get no errors...any help? Thanks!
You're using winget() wrong - you seem to be confusing its syntax with winset(). You are also treating its results as a list of objects in the line with the for loop, which doesn't make sense since the proc always returns a string.

Instead of attempting to loop through every cell in the grid just to add an item, you should instead retrieve the grid's <code>cells</code> property to find out how many rows and columns are in it, and then add one to each to get the cell that you want to add the item to.

This isn't a great design, however, since there's no good way to figure out which cell an object is in to remove it. To get around this, you could keep track of the objects added to the grid in a list with their location in the grid or give each a var to keep track of its location.
In response to Nickr5
Hmm, well I edited the code to the following:

mob
var/tmp/row = 1
var/tmp/col = 1
var/tmp/itm = 0
proc
AddBP(item)
while(itm == 0)
itm = 0
if(winget(src,"backpack.BP","current-cell=[row],[col]") ==1)
if(row == 10)
if(col == 10)
alert("Not enough room!","Backpack")
else
col++
else
row++
else
src << output("[item]","BP:[row],[col]")
itm=1


It displays the text "/obj/CLOTH/Shirt" instead of the picture of the object...any help there?
In response to Hi1
That problem is because you're converting the object to a string. Get rid of the quotes and brackets so that the line with output() looks like this:
src << output(item,"BP:[row],[col]")


This code still shouldn't work, however, for the reasons I stated in my last post (unless winget has an undocumented format that I'm not aware of). Read the reference entry on winget() and try to figure out what you're doing wrong from that.

Also, there is some usr abuse in the alert() call.
In response to Nickr5
I can't figure it out, I've read over it three times...

I call AddBP(/obj/CLOTH/Shirt and AddBP("Meow") on login as a test, and it only displays (still as text) /obj/CLOTH/Short.

I just can't figure this out...
In response to Hi1
Hi1 wrote:
I can't figure it out, I've read over it three times...

I call AddBP(/obj/CLOTH/Shirt and AddBP("Meow") on login as a test, and it only displays (still as text) /obj/CLOTH/Short.

I just can't figure this out...

You have to add an instance of a type, not just the type path itself. AddBP(new /obj/CLOTH/Shirt()) should work.

As for using winget(), you're using the following:
if(winget(src,"backpack.BP","current-cell=[row],[col]") ==1)


And the reference example is this:
winget(usr, "mainwindow", "is-visible")


You are using the syntax of winset(), which would allow you to assign a value to current-cell, but winget() only allows the names of the properties, since you're retrieving the values.
To check whether or not current-cell is equal to [row],[col], try:
if(winget(src,"backpack.BP","current-cell") == "[row],[col]")
In response to Nickr5
I'm trying to check if anything is in the cell, not if the current cell is set to row and col.
In response to Hi1
BYOND doesn't allow you to get the contents of a grid cell or even check if anything is in it. Instead, you could (among other ways) give each mob a list of items in its backpack along with an 'UpdateBackpack()' proc, which would update the backpack grid according to the list. To add an item to the backpack, you just add it to the mob's backpack list and call UpdateBackpack().
In response to Nickr5
I think I understand, thank you. :)