obj/books
name="Book
notebooks
icon_state="notebook"
name="Notebook"
var/entries[]
var/entrynum=1
verb/Name_Book()
var/bookname=input(usr, "What do you want to title this notebook?", "Name Book", src.name) as text
src.name=bookname
usr<<"You Title this notebook, '[src.name]'."
verb/Write_in_Book()
//Ask if they want to add a new Entry first
var/newentry=input(usr, "Add a new entry.","Write in [src.name]") as text
entries[entrynum] = "Entry #[entrynum]: [newentry]"
++entrynum
verb/Read_Book()
usr<<"[entries]"
Problem description:
I'm making books that people can add entries to, basically just lists. Any idea why the above code won't work? I was reading about Lists and this seems ok
Since you haven't said what the problem is, I'll make a few educated guesses...
Firstly, your list variable is defined but not initialised. In other words, you've indicated that it's meant to hold a list (using the [square brackets]), but you haven't set it to anything, so it has the value null.
The two best ways of defining lists are:
Those two lines are equivalent. I prefer the latter, as it's more explicit; but either one works. Pick your poison.
Secondly, you're trying to set an index that hasn't been set before... IIRC, that doesn't work for non-associative lists. Instead, try this:
Then you don't need the entrynum var; you can use it if you really want, but it's more robust to simply check the length of the list directly, like this: length(entries)
Thirdly, about Read_Book(); outputting a list just results in "/list", which is slightly annoying. =\ To fix that, loop through the list and display each item in it: