Last Modified: 2023-07-09

Commands & Events

For an event for a page in a book

commands/myAction.lua are triggeded with a dispatchEvent fucntion

  UI:dispatchEvent({
    name = "myAction",
    UI = UI
  })

this myAction is defined in commands table in components/pageX/index.lua

For a button, you see in components/pageX/index.lua, buttonOne layer has two events. they are tap and drag. These tap and drag events are handleld with commands/buttonOne/tap.lua and commands/buttonOne/drag.lua

commands are called as Action in Kwik. You can dispatchEvent with params to myAction.lua, myEvents.testHandler.lua

{
    name = "kwik4_1280x1920",
    layers = {
          {  bg={} },
          {  buttonOne={ events = {tap, drag}} },

    },
    components = {
      audios = { },
      groups = {  },
      timers = {  },
      variables = {  },
      others = { }
     },
    commands = { "myAction", "myEvents.testHandler" },
    onInit = function(scene) print("onInit") end
}

The assicated lua files are located in the commands folder


For a common action for a book

create a command lua in commands/common directory, for example

And let it pass in arguments of bootstrap function in main.lua

local common = {commands = {"myEvent"}, components = {myComponent={}}}

require("controller.index").bootstrap({
  name="book", sceneIndex = 1, position = {x=0, y=0},
  common =common
})

context:init function of controller/ApplicationContext.lua automtaically adds it

this context init is called everytime when a scene is loaded. You can dispatch an event to executre myEvent.lua like this

UI:dispatchEvent({
  name = "common.myEvent",
  UI = UI
})