Thank you.
Code:
mob/var
patha // These will be holding the object's path.
pathb
pathc
pathd
obj
var
newloc
hud
slot // the hud slots, i dont think they are in any use, but to be displayed, IMO that is.
icon = 'slot.dmi'
icon_state = "holder"
New(client/c)
c.screen+=src
red
icon = 'slot.dmi'
icon_state = "obj1"
density = 1
layer = 5
Click()
if(src.loc == usr)
usr.overlays += src
verb
Pick()
set src in oview(1)
if(usr.patha == null)
usr.patha = /obj/red
src.loc = usr
src.newloc = "3,3"
else
return
if(usr.pathb == null)
usr.pathb = /obj/red
src.newloc = "3,4"
src.loc = usr
else
return
if(usr.pathc == null)
usr.pathc = /obj/red
src.newloc = "4,3"
src.loc = usr
else
return
if(usr.pathd == null)
usr.pathd = /obj/red
src.newloc = "4,4"
src.loc = usr
else
return
New(client/c)
c.screen += src
src.screen_loc = "[src.newloc]"
mob/Login()
..()
mob/verb
inventorysys()
if(usr.invhud == 0)
var/obj/hud/slot/a = new /obj/hud/slot(usr.client)
a.screen_loc = "3,3"
var/obj/hud/slot/b = new /obj/hud/slot(usr.client)
b.screen_loc = "3,4"
var/obj/hud/slot/c = new /obj/hud/slot(usr.client)
c.screen_loc = "4,3"
var/obj/hud/slot/d = new /obj/hud/slot(usr.client)
d.screen_loc = "4,4"
usr.invhud = 1
updateinv()
else
for(var/obj/hud/slot/a in usr.client.screen)
del(a)
usr.invhud = 0
mob/var
invhud = 0
mob/proc/updateinv()
if(src.patha == null)
return
else
new patha(usr.client)
Problem description:
The '[0]' declares the variable as a list, and the 0 sets the variable to a new, empty list. (if it was a 1 or any other number, it would be a list with x nulls inside)
To fill it with slots, you'd do something like this:
That arranges them in the way you want. The important part is this line:
That, of course, adds the slot to the list of slots. So by the end of it, the 'slots' list should contain all 4 slots.
To update your inventory with, say, the first four items in your contents, you could do this:
min(contents.len, slots.len) allows you to have a variable slots length as well as contents length. It chooses the minimum number so that it doesn't try checking the 5th item in contents when you only have 4, because that would cause a runtime error.
contents[n] got the nth item in your 'contents' (list).
slots[n] got the nth (corresponding) slot in your 'slots' list.
Of course, you may choose to display your items differently, like attach an item to a slot, so you could do something like swap the items between slots. In that case, you'd do this:
If you read through it slowly enough, it should all make sense. There's nothing really complicated here. You could even try adding a swap_item() proc yourself.