ID:2353045
 
Code:
mob/var/list/HUD = list()
var
HudGroup/HudGroup
object/object


mob/verb
createHUD()
HUD = list("hudgroup" = new/HudGroup(src.client, icon='dmi.dmi', group_x = 1, group_y = 1))
var/HudGroup/hud = HUD && HUD["hudgroup"] //stores the datum in list as a variable
hud.add(/object, icon='dmi.dmi', icon_state="1", screen_loc="1,1") //Here i want to access the add proc inside datum from list.
hud.add(/object, icon='dmi.dmi', icon_state="2", screen_loc="2,1")
hud.add(/object, icon='dmi.dmi', icon_state="3", screen_loc="3,1")
hud.renderObjects() // this is the proc which sends all childs from list/objects to client.screen
//****************************************
HudGroup
parent_type=/obj
var
list/objects = list() //contains child datum in list. added by using add()
client/client //contains client as owner. added by using add()

visible = true

group_x //group screen location, x value
group_y //gropu screen location, y value

New(client/c,icon=null, icon_state=null, group_x=null, group_y = null) //on creating a new HUD group.
if(istype(c, /client)) add(c)
if(icon)
src.icon=icon
world.log << "HudGroup.New(icon=[icon])"
if(icon_state)
src.icon_state = icon_state
world.log << "HudGroup.New(icon_state=[icon_state])"
if(group_x) src.group_x = group_x
else src.group_x = 1
if(group_y) src.group_y = group_y
else src.group_y = 1



proc
add(type, icon=null, icon_state=null, screen_loc)
//arg type: redirects to proc corresponding to type. if(type=/HUD/object) > addObject()
if(istype(type, /client)) //client
client = type
if(istype(type, /object)) //object
if(screen_loc)
src.objects += new/object(parent=src, icon, icon_state, screen_loc)
else throw EXCEPTION("[src].add(type = /object): Expecting screen_loc argument! got null instead!")
/*
/////// Not complete!!!!
_set(var/argument, var/value) //arg variable: changes variable corresponding to arg.
var/A = vars && vars[argument]
world << "_set(): returns: [A]"
// A = value
*/



renderObjects() // renders all childs in objects list, to client in clients list's screen.
var/client/c
if(client) c = client
for(var/object/o in objects)
if(o.visible)
c.screen += o



//****************************************
object
parent_type=/HudGroup

var
HudGroup/parent

New(parent, icon = null, icon_state = null, screen_loc)
if(istype(parent, /HudGroup))
src.parent = parent
if(icon) //if icon = null, give it same value as parent
src.icon = icon
if(icon_state)
src.icon_state = icon_state
if(screen_loc)
src.screen_loc = screen_loc


Problem description:

Introduction: I save a HudGroup datum to mob's list. which is called HUD = list(). I create a new datum /HudGroup to that list. This datum has a proc which creates children into it's own list variable, called objects=list().

I have trouble figuring out why i can't have the object childs in /HudGroup.objects get rendered on screen.
I am no longer sure what could be causing this, other then not proberly accessing the child list in HUD["hudgroup"].objects

This is the code for what i think is causing it:
mob/verb
createHUD()
HUD = list("hudgroup" = new/HudGroup(src.client, icon='dmi.dmi', group_x = 1, group_y = 1))
var/HudGroup/hud = HUD && HUD["hudgroup"]
hud.add(/object, icon='dmi.dmi', icon_state="1", screen_loc="1,1")
hud.add(/object, icon='dmi.dmi', icon_state="2", screen_loc="2,1")
hud.add(/object, icon='dmi.dmi', icon_state="3", screen_loc="3,1")
hud.renderObjects()


That, or the proc itself in the datum is flaud. I need some help here.
mistake 1:
var/HudGroup/hud = HUD && HUD["hudgroup"]
//&& is a logical operator, basicly it means hud = 1 or 0
//I overlooked a very important detail here.

it should be:
var/HudGroup/hud = HUD["hudgroup"]


Edit: It is wrong. Explanation is bellow
Update:

mob/verb
createHUD()
HUD = list("hudgroup" = new/HudGroup(src.client, icon='dmi.dmi', group_x = 1, group_y = 1))
var/HudGroup/hud = HUD["hudgroup"]
hud.objects += new/object(hud, icon='dmi.dmi', icon_state="1", screen_loc="1,1")
hud.objects += new/object(hud, icon='dmi.dmi', icon_state="2", screen_loc="2,1")
hud.objects += new/object(hud, icon='dmi.dmi', icon_state="3", screen_loc="3,1")
hud.renderObjects()


It turned out the type path in HudGroup.add(type) wasn't recognized.
I where able to get this code above to work just fine, but i'm not actually using the add() proc, which is sort of unintended.

hud.add(/object, icon='dmi.dmi', icon_state="1", screen_loc="1,1")

not properly typecasting /object, which resaulted in add() to skip certain type checks. Still not fixed though
Ok,so i have gotten a lot of correction and feedback, which is why i now understand the flaws in this code. And i will be reconstructing it.

My post above about && was also wrong, which is nice: this && that = if(this) that; else this