world
proc
BuildDatabase()
//This sets up the database for the entire world
BuffDatabase = new
world << "Building database..."
var/Buff/b
b = new
b.name = "Blessing of Cuddles"
b.hp_value = 30
b.duration = 100
b.icon = 'buffs.dmi'
b.icon_state = "buff template"
b.index = 1
BuffDatabase.entries[b.index] = b
----------My test "Database"-------
Database
var/list/entries[100]
/var/global/Database/Items/ItemDatabase
/var/global/Database/Buffs/BuffDatabase
Buffs
proc
GetBuff(index)
return entries[index]
---------Code that accesses the database and pulls the buff from the list via its index number. Yes, it works, except for one small thing...---
//Creates a buff based on the index number specified in the var named buff.
if (buff)
var/Buff/b = new //New buff
b = BuffDatabase.GetBuff(buff) //Pulls a buff from the database
b.source = m
b.loc = t
spawn() b.Apply_Buff(t) //Applies the buff
Problem description:
When I try to create another instance of the Buff object, it refers to the object in the list... but I thought it creates an entirely new copy! It didn't, so I wonder if there is a way to create a brand new copy of an instance.
Then you're setting b to a /Buff in the "entries" list.
The /Buff you created first is gone, since you don't have any references to it. I'm not sure why you're expecting your code to not do what it plainly says it does.
Object instances are created from type paths. There's currently no easy way to clone an existing instance, if that's what you're trying to do.