ID:156820
 
Hi, I was wondering if I could get some help with Lummox's datum guide. It seems that is code has errors(It also had some inconsistent indentation I had to fix). I want to learn how to best use Datums, but how can I go about that if I can't properly learn from the guide? Here is the code:

popupbox
var/client/client // who can see this box right now?
var/mob/M // the mob that goes with client
var/list/items // items to be shown on screen
var/list/screenitems
var/list/backdrop // the background
var/x, y
var/width, height

New(mob/_M, list/_items, _x, _y)
if(!_M || !_M.client) del(src)
M = _M
client = _M.client
items = _items
var/viewx, viewy
if(isnum(client.view))
viewx = client.view * 2 + 1
viewy = viewx
else
var/index = findtext(client.view, "x")
viewx = text2num(copytext(client.view, 1, index))
viewy = text2num(copytext(client.view, index+1))
x = _x; y = _y
if(x < 0) x += viewx+1 // x==-1 means right edge
if(y < 0) y += viewy+1 // y==-1 means top edge
// round up from items.len/viewx
height = round((items.len + viewx - 1) / viewx)
// round up from items.len/width
width = round((items.len + height - 1) / height)
if(x + width - 1 > viewx) x = max(viewx - width + 1, 1)
if(y + height - 1 > viewy) y = max(viewy - height + 1, 1)
backdrop = list(new/obj/backdrop(src))
screenitems = new
var/n = 0
for(_y in y+height-1 to y step -1) // fill from the top down
for(_x in x to (x+width-1))
if(++n > items.len) break
screenitems += new/obj/popupitem(src, "[_x],[_y]", items[n])
//M.pbox = src

Del()
// if(M /*&& M.pbox == src*/) //M.pbox = null
if(backdrop)
if(client) client.screen -= backdrop
for(var/O in backdrop)
del(O)
if(screenitems)
if(client) client.screen -= screenitems
for(var/O in screenitems)
del(O)
..()

proc/Select(atom/item)
del(src)

obj/backdrop
var/popupbox/box
var/client/client
icon = 'popup.dmi'
icon_state = "backdrop"
layer = 20

New(popupbox/_box)
box = _box
client = box.client
screen_loc = "[box.x],[box.y] to \
[box.x+box.width-1],[box.y+box.height-1]"
if(client) client.screen += src

Del()
if(client) client.screen -= src
..()

Click()
box.Select(null)

obj/popupitem
var/popupbox/box
var/client/client
var/atom/item
layer = 21

New(popupbox/_box, newloc, atom/_item)
box = _box
client = box.client
screen_loc = newloc
item = _item
icon = item.icon
icon_state = item.icon_state
dir = item.dir
if(client) client.screen += src

Del()
if(client) client.screen -= src
..()

Click()
box.Select(item)
obj/item/weapon
Drop()
..()
if(usr.weapon == src) usr.weapon = null
Use()
..()
if(usr.weapon == src)
usr.weapon = null
usr << "You put away [src]."
else
usr.weapon = src
usr << "You arm yourself with [src]."

mob
var/obj/item/weapon/weapon

verb/Weapon() // choose a weapon
set src = usr
if(pbox) del(pbox)
var/list/L = list()
if(weapon) L += weapon // put the current weapon first
for(var/obj/item/weapon/w in contents)
if(w != weapon) L += w
if(L.len)
pbox=new/popupbox/inventory(usr, L, -1, 1)
else usr << "You are unarmed."


Errors:
Datum Testing.dm:117:error: pbox: undefined var
Datum Testing.dm:117:error: pbox: undefined var
Datum Testing.dm:123:error: pbox: undefined var
Datum Testing.dm:123:error: /popupbox/inventory: undefined type path
Datum Testing.dm:39:error: M.pbox: undefined var
Datum Testing.dm:42:error: M.pbox: undefined var
Datum Testing.dm:42:error: M.pbox: undefined var
Datum Testing.dm:100:error: Drop: undefined proc
Datum Testing.dm:103:error: Use: undefined proc

Datum Testing.dmb - 9 errors




I am not sure how I should define the pbox variable, how I should set up having a datum under a datum called inventory, and how I should go about defining the Drop and Use procs. Any help is appreciated, and thank-you!

The inconsistent indentation errors are the result of the way you pasted this into your own code. The code in question was tested before it was posted. The missing vars and procs are in another code section later in that same article.

Lummox JR
You should #include the file into the dme references instead of just copying and pasting the code.

This section of the DM guide explains how to include library content into your code neatly. If it's not a library you'll have to manually recreate the demo instead of mindlessly copy/pasting.
In response to Lummox JR
Ah, I am really sorry, I missed a large block of code. Thank-you.


popupbox/inventory
Select(obj/item/item)
if(istype(item)) item.Use()
del(src) // close the box

obj/item
verb/Get()
set src in oview(1)
if(usr.pbox) del(usr.pbox)
loc = usr
usr << "You pick up \a [src]."
verb/Drop()
set src in usr
if(usr.pbox) del(usr.pbox)
loc = usr.loc
usr << "You drop \a [src]."
verb/Use() // a user can Use any object they're carrying.
set src in usr
if(usr.pbox) del(usr.pbox)

mob
var/popupbox/pbox

Move()
if(pbox) del(pbox)
return ..()

verb/Inventory()
set src = usr
if(pbox) del(pbox)
if(contents.len)
pbox = new/popupbox/inventory(usr, contents, -1, 1)
else usr << "You aren't carrying anything."


Also Duelmasterz, I had accidentally missed a portion of code from the article while testing it, thanks though.