-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyarn_interpreter_test.lua
45 lines (40 loc) · 1.18 KB
/
yarn_interpreter_test.lua
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
local YarnParser = require("yarn_parser")
local YarnInterpreter = require("yarn_interpreter")
-- Read the script from file
local file = io.open("tests/gold_or_health.yarn", "r")
if not file then
error("Could not open xxx.yarn")
end
local script = file:read("*all")
file:close()
-- Parse your Yarn script
local parsed_nodes = YarnParser:parse(script)
-- Create interpreter instance
local interpreter = YarnInterpreter.new(parsed_nodes)
-- OPTIONAL: Set up callbacks
interpreter:set_callbacks({
on_dialogue = function(text)
-- Custom dialogue display
print("[DIALOGUE] " .. text)
end,
on_choice = function(choices)
-- Custom choice handling
print("[CHOICE]")
for i, choice in ipairs(choices) do
print(i .. ": " .. choice)
end
return tonumber(io.read())
end,
on_variable = function(name, value)
-- Variable change notification
print("[VARIABLE] " .. name .. " = " .. tostring(value))
end,
on_node_enter = function(title)
print("[ENTER NODE] " .. title)
end,
on_node_exit = function(title)
print("[EXIT NODE] " .. title)
end
})
-- Run the interpreter
interpreter:run()