-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent.lua
More file actions
77 lines (67 loc) · 1.72 KB
/
current.lua
File metadata and controls
77 lines (67 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
current = {
inventory = Object:new{
pronoun="your";
short="inventory";
name={"inventory"};
contains={};
container=true};
living = true;
running = true;
prompt = function()
io.write("\n");
if(current.room and current.room.short) then io.write("~", capitalize(current.room.short), "~\n"); end
if(current.score) then
io.write("[", current.score, " ");
if(current.maxScore) then io.write("/ ", current.maxScore, " "); end
io.write("pts.] ");
end
io.write("}>");
end;
eachTurn = function() end;
};
function RecursiveItterator(x, visible, first)
local vis = false;
if(visible == nil or first == nil) then
vis = true;
else
vis = x.open or x.transparent or false;
if(visible == false) then vis = not vis; end
end
if(vis and (x.contains ~= nil)) then
for i,v in ipairs(x.contains) do
coroutine.yield(v);
RecursiveItterator(v, visible, true);
end
end
if(x.supports ~= nil) then
for i,v in ipairs(x.supports) do
coroutine.yield(v);
RecursiveItterator(v, visible, true);
end
end
end
function visible(object)
local co;
if(object == nil) then
co = coroutine.create(function()
RecursiveItterator(current.room, true);
RecursiveItterator(current.inventory, true);
end);
else
co = coroutine.create(function() RecursiveItterator(object, true) end);
end
return function()
local res, val = coroutine.resume(co);
if(res == true) then
return val;
else
return nil;
end
end
end
function lookFor(tokens, object)
for x in visible(object) do
if(x:match(tokens)) then return x; end
end
return nil;
end