ID:1480681
 
(See the best response by Kaiochao.)
Problem description:
Hello guys, I just checked out KidPaddle45's Inventory library and I decided to use the knowledge gained from it and create my own Inventory system. Anyway, I have it somewhat working properly, and by that I mean it displays what its supposed to display and whatnot.

Now, on to the real problem:

I can't figure out how to arrange the items to appear in the proper order, I want it to display starting from the Top-Left of the screen, going horizontally from there on and continue its way all the way to the Bottom-Right.

The way I have it now it displays from the Bottom Left , going up towards the Top Left.

This is the code I'm currently using:

Code:
Inventory

parent_type = /obj
icon = 'Inventory.dmi'
icon_state = "Slot"

var x_Slots = 5
var y_Slots = 5
var Visibility
var isUsed = FALSE

New(visible)

Visibility = visible

if(Visibility == "Show")

winshow(usr,"Inventory",1)
usr.client.screen = null
Show_Inventory()

else if(Visibility == "Hide")

winshow(usr,"Inventory",0)
proc

Show_Inventory()

for(var/X = 1 to x_Slots) for(var/Y = 1 to y_Slots)

var/Inventory/Slots = new

Slots.screen_loc = "Slots:[X],[Y]"

usr.client.screen+=Slots

for(var/obj/Items/Stuff in usr.contents)

src.Add_Items(Stuff)

proc

Add_Items(obj/Items/Stuff)

for(var/Inventory/Slots in usr.client.screen)

if(Slots.isUsed) continue

Stuff.screen_loc = Slots.screen_loc

usr.client.screen += Stuff

Slots.isUsed = TRUE ; return


And this is a screen shot of what's currently happening:



Obviously point out anything that looks wrong or could use improvement.

-Thanks
Best response
You need to switch the order of your for() display loops, as well as loop the y from max to min.
Now I get them like this:


EDIT: Oops, nvm, for some reason I only read the first half of your post o.o . Going to make the loop now
Had a lot of difficulties with this, kept having them line up in unwanted positions, luckily I got D-Cire's assistance and managed to fix it and do it from the top right to bottom left :P

Didn't even know of "to" or "step" in for loops

Code:
Inventory

parent_type = /obj
icon = 'Inventory.dmi'
icon_state = "Slot"

var x_Slots = 5
var y_Slots = 5
var Visibility
var isUsed = FALSE

New(visible)

Visibility = visible

if(Visibility == "Show")

winshow(usr,"Inventory",1)
usr.client.screen = null
Show_Inventory()

else if(Visibility == "Hide")

winshow(usr,"Inventory",0)
proc

Show_Inventory()

for(var/obj/Items/Stuff in usr.contents)

src.Add_Items(Stuff)

for(var/Y in y_Slots to 1 step -1) for(var/X in 1 to x_Slots)

var/Inventory/Slots = new

Slots.screen_loc = "Slots:[X],[Y]"

usr.client.screen+=Slots



proc

Add_Items(obj/Items/Stuff)

for(var/Inventory/Slots in usr.client.screen)

if(Slots.isUsed) continue

Stuff.screen_loc = Slots.screen_loc

usr.client.screen += Stuff

Slots.isUsed = TRUE ; return


Your help is much appreciated, thanks