Created
January 21, 2015 21:10
-
-
Save AmandaCameron/64f5dfe7092f841f9fdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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