Skip to content

Instantly share code, notes, and snippets.

@AmandaCameron
Created January 21, 2015 21:10
Show Gist options
  • Save AmandaCameron/64f5dfe7092f841f9fdb to your computer and use it in GitHub Desktop.
Save AmandaCameron/64f5dfe7092f841f9fdb to your computer and use it in GitHub Desktop.
function read_articles()
return game.data:load("recall:bulleten-board")
end
function send_article(player, article)
player:send("{yellow}" .. article.title .. "{normal}")
player:send("{cyan}" .. article.body .. "{normal}")
end
function list_articles(player)
local articles = read_articles()
player:send("{bright-yellow}Articles on the bulletin board:{normal}")
for id, article in ipairs(articles) do
player:send(("{green}[{yellow}%3d{green}] {cyan}%s{normal}"):format(id, article.title))
end
end
function find_article(input)
local articles = read_articles()
if articles[input] then
return articles[input]
end
for id, article in ipairs(articles) do
if article.title:sub(input) then
return article
end
end
return nil
end
object.commands:add("read", function(player, arg)
if arg == "" then
list_articles(player)
else
local art = find_article(arg)
if art then
send_article(player, art)
else
player:send("No such article.")
end
end
return true
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment