ID:162485
 
Hello, I am wondering if someone can help me. I want to make something like usr.contents, except it is thier spellbook. When they pick up certain items (scrolls) it would add them to the usr.spellbook.contents.

Would it be as simple as a mob variable like:

var/spellbook = list()

Then for the scroll itself:
obj
spell
icon = 'shopicons.dmi'
icon_state = "scroll"
layer = 1
stackable = FALSE
verb
Get()
set src in view(1)
if(stackable)
var/obj/object = locate(text2path("[src.type]")) in usr.contents
if(object) //could find previous type of object
object.addAmount(src.amount)
del(src)
else //could not find previous type of object
usr.spellbook.Add(src)
else
usr.spellbook.Add(src)


?
Well, how are you going to be using these scrolls once they're in the spellbook? The structure of this is going to depend on that.
In response to Garthor
Basically, they will prepare(equip) the scroll from the spellbook and then be able to cast that spell. Similiar to how I am doing guns, where the items in question give you your verbs.
In response to Zuglilth
In that case, what you have should mostly work, though you're searching through contents instead of spellbook like you should for the item stacking. Also, you should just use locate(src.type), not locate(text2path("[src.type]")). The second is redundant.
In response to Garthor
Hmm, when I try to compile I get this error:

spellsystem.dm:16:error:usr.spellbook.Add:undefined proc
spellsystem.dm:18:error:usr.spellbook.Add:undefined proc

Do you have any idea whats wrong?
Zuglilth wrote:
Hello, I am wondering if someone can help me. I want to make something like usr.contents, except it is thier spellbook. When they pick up certain items (scrolls) it would add them to the usr.spellbook.contents.

Would it be as simple as a mob variable like:

var/spellbook = list()

Then for the scroll itself:
> obj
> spell
> icon = 'shopicons.dmi'
> icon_state = "scroll"
> layer = 1
> stackable = FALSE
> verb
> Get()
> set src in view(1)
> if(stackable)
> var/obj/object = locate(text2path("[src.type]")) in usr.contents
> if(object) //could find previous type of object
> object.addAmount(src.amount)
> del(src)
> else //could not find previous type of object
> usr.spellbook.Add(src)
> else
> usr.spellbook.Add(src)

?

change
mob/var/spellbook

into
mob/var/spellbook = list()


then change
usr.spellbook.Add(src)

into
usr.spellbook += src


i hope that will work
In response to Zuglilth
Oh, right: you have to define the variable as being a list, so mob/var/list/spellbook
In response to Garthor
Right. Add(), Remove(), etc. are list procs. The only with with list types, being "/list". If it's not a list, you could use the "+=" and "-=" operators for them.
In response to Kaiochao2536
If it's not a list then replacing Add() with += isn't going to solve anything. The issue is that you can't use Add() without declaring that it IS a list. Whether or not it actually is a list isn't an issue, until Add() is reached at runtime and will crash the proc if it's not used on a list.