Skip to content

Instantly share code, notes, and snippets.

@vermut
Created October 10, 2016 22:03
Show Gist options
  • Save vermut/6c71113aa82ec594870775c86819e2a1 to your computer and use it in GitHub Desktop.
Save vermut/6c71113aa82ec594870775c86819e2a1 to your computer and use it in GitHub Desktop.
local machine = require('lua/statemachine')
local rs485_node = require('lua/rs485_node')
--noinspection UnusedDef
quest = machine.create({
events = {
{ name = 'start', from = 'preparation', to = 'room1' },
{ name = 'solved_alien_arm', from = 'room1', to = 'game_won' },
{ name = 'restart', from = '*', to = 'preparation' },
},
callbacks = {
on_preparation = function(self)
print('Resetting everything to inital states')
alien_arm:reset()
end,
on_start = function(self)
print('Game is OOOON! ')
alien_arm:activate()
end,
on_solved_alien_arm = function(self)
print('Arm solved, thanks')
alien_arm:deactivate()
end,
}
})
REGISTER_STATES("main_quest", quest)
alien_arm = rs485_node.create({
name = 'alien_arm',
slave_id = 1,
initial = 'active',
events = {
{ name = 'activate', action_id = 1, from = 'inactive', to = 'active' },
{ name = 'deactivate', action_id = 2, from = { 'active', 'completed' }, to = 'inactive' },
{ name = 'complete', triggered_by_register = 1, from = 'active', to = 'completed' },
{ name = 'reset', action_id = 4, from = '*', to = 'active' },
},
callbacks = {
on_complete = function() quest:solved_alien_arm() end
}
})
--Fire off main initialization machine
quest:restart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment