ID:2615319
 
(See the best response by Magicsofa.)
If someone wanted to make a grid that creates a new row, every 4 items in it four being the cap of columns how would they go about it?

It keeps expanding columns to like 8 stretching the grid and then making a new row
You'd need to keep track of how many items you outputted and move to the next row.

var/row = 1, col = 0, max_col = 4
while(--stuff)
col++
if(col > max_col)
row++
col = 1
src << output(items[stuff],"window.grid:[col],[row]")
I'm learning a bit but I'm lost with ( --stuff ) and items[stuff]

mob
proc
refresh_item()
if(src.client)
var/row = 1, col = 0, max_col = 4
for(var/gui/item/X in src.contents )
if( !X.passive )
col ++
if ( col > max_col )
row ++
col = 1
src << output( X ,"main.item:[col],[row]")


for some reason its acting buggy
In response to Kayla May
Kayla May wrote:
I'm learning a bit but I'm lost with ( --stuff ) and items[stuff]

--stuff is just subtracting 1 from stuff each time. Look up the -- operator when you forget the difference between --x and x-- (I can never keep it straight in my head for some reason). items[stuff] would just be accessing a list called items using a numerical index.

if( !X.passive )


On this line, the ! is acting on X, not X.passive. You want this instead:

if( !(X.passive) )
mob
proc
refresh_items()
if( src.client )
var/row = 1, col = 0, max_col = 4
var/stuff = 0
var/itemlist = list()
for(var/gui/item/X in src.contents )
if ( !X.passive )
stuff++
itemlist += X
while ( --stuff )
col++
if( col > max_col )
row++
col = 1
src << output ( itemlist[stuff] , "main.item:[col],[row]" )


I suck... It keeps seeing out of index or something like that!
Best response
Hey now, nothing wrong with being a noob, we all started there.

Could be a copying mistake, but the last line is supposed to be indented one more time so that it's inside the while() loop. Also fix this line:

if( !X.passive )
//should be this:
if( !(X.passive) )
It worked out! Thank you all that helped! ;-;