taBBall/scripts5

taBBall Scripting Page 5

Contents

  • Page 1 describes how the first script gets executed.
  • Page 2 describes the flow of the initial script execution.
  • Page 3 describes how the game client initialization occurs.
  • Page 4 describes how to create actions.
  • Page 5 is this page and describes how to create the default key mappings and attach them to actions.
  • Page 6? describes how to create the initial scene.

Binding Keys

On Page 3 I showed how the game initialization method calls self:createDefaultMappings().

function GameClient:createDefaultMappings()
    print("=============\nCreate Default Key Mappings...\n============")
    self:getInputMap():mapKeyInput("t", self:getActionMap():getAction("Test"))
end

This gets the default input map and maps the keyboard keystroke "t" to the "Test" Action created by the GameClient:createActions() method.

Effectively, this binds the "t" key to the GameClient:testAction(action). When the "t" key is pressed, the testAction(action) method is called.

function GameClient:testAction(action)
    if action:getKeyState() then
        print("Yay, the T button was pressed!!!")
    else
        print("Yay, the T button was released!!!")
    end

end

In this case, if the key is being pressed, "Yay, the T button was pressed!!!" is printed to the console. If it's being released then "Yay, the T button was released!!!" is printed to the console.

Next, Page 6? describes how to create the initial scene.