Skip to content

Instantly share code, notes, and snippets.

@dyerrington
Last active December 21, 2015 03:38
Show Gist options
  • Save dyerrington/6243276 to your computer and use it in GitHub Desktop.
Save dyerrington/6243276 to your computer and use it in GitHub Desktop.
Dealing with dialog actions in LUA
local ActionKey = display.newRect(controlGroup, DpadBack.x + 750, DpadBack.y - 37, 100, 100)
local function move( event )
if event.phase == "ended" or event.phase == "cancelled" then
movement = nil
elseif player.talking then
return false;
elseif event.target.id then
movement = event.target.id
player.lastMovement = event.target.id
end
return true
end
local function actionkey( event )
if event.phase == "ended" then
if player.talking then
print('shutting player up')
activeDialog.alpha = 0
activeDialog.isVisibile = false
player.talking = false
return true
end
local offsets = {}
offsets.up = { x = 0, y = -1}
offsets.down = { x = 0, y = 1}
offsets.right = { x = 1, y = 0}
offsets.left = { x = -1, y = 0}
-- Check the block ahead of what our target is looking at (lastMovement)
local tile_desciption = {
level = player.level,
locX = player.locX + offsets[player.lastMovement].x,
locY = player.locY + offsets[player.lastMovement].y
}
local objects = mte.getObject(tile_desciption)
if objects then
for key,value in pairs(objects[1].properties) do
print('current')
if key == "dialog" and not player.talking then
print(serpent.block(value))
activeDialog = display.newText(value, 200, 200, native.systemFont, 24)
activeDialog.alpha = 1
player.talking = true
end
if key == "rand_dialog" then
local dialogs = json.decode(value)
local randomIndex = math.random(1, #dialogs)
activeDialog = display.newText(dialogs[randomIndex], 200, 200, native.systemFont, 24)
activeDialog.alpha = 1
player.talking = true
print(serpent.block(value))
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment