ID:142179
 
Ok so Im using a grid to control my inventory instead of teh stat panel because i want it in a different spot then the rest of the stat, my current code works fine except sometimes when your contents is empty and you add an item it doesnt update right and doesnt show the item until you get a second one. Im not sure what is wrong with it.
Code:
mob/proc/UpdateContents()
var/items = 0
for(var/obj/O in src.contents)
winset(src, "Inventory", "current-cell=1,[++items]")
src << output(O, "Inventory")
winset(src, "Inventory", "current-cell=2,[items]")
src << output(O.suffix, "Inventory")
winset(src, "Inventory", "cells=2x[items]")


Problem description:

This is a small inconvenience with grids. If you output to a cell which does not exist, it will not show up when you change the 'cells' control setting. I've managed to get around this small problem by having the game calculate how many things its supposed to add and set the cells accordingly, like so:

mob/proc/UpdateContents()
var/items = 0
for(var/obj/O in src.contents) items++
winset(src, "Inventory", "cells=2x[items]")
items=0
for(var/obj/O in src.contents)
winset(src, "Inventory", "current-cell=1,[++items]")
src << output(O, "Inventory")
winset(src, "Inventory", "current-cell=2,[items]")
src << output(O.suffix, "Inventory")
In response to Devourer Of Souls
Thanks ill try that
In response to NightJumper88
One other thing; I know you were probably using Lummox JR's Skin Tutorial, and you got to the grid section. That tutorial, the last time I read it, neglects some very useful shorthand for dealing with grids.

mob/proc/UpdateContents()
var/items = 0
for(var/obj/O in src.contents) items++
winset(src, "Inventory", "cells=2x[items]")
items=0
for(var/obj/O in src.contents)
src << output(O, "Inventory:1,[++items]")
src << output(O.suffix, "Inventory:2,[items]")


That being, you can direct the output to a specific cell by typing ':Column,Row' after the ID of the grid control.
In response to Devourer Of Souls
Thanks thats a little neater in appearance and also will make it a lot more understandable for my other grid.
In response to Devourer Of Souls
Devourer Of Souls wrote:
One other thing; I know you were probably using Lummox JR's Skin Tutorial, and you got to the grid section. That tutorial, the last time I read it, neglects some very useful shorthand for dealing with grids.

The reason is that shorthand didn't exist at the time the tutorial was written--it was a later addition.

Lummox JR