Skip to content
Download

Lua or C++

The language is chosen when the project is created and applies to all of it. The API has the same names in both.

Lua C++
Play Instant Compiles before running
Installation Nothing besides Brasa C++ support and Visual Studio Build Tools
Object code objects/Player.lua objects/Player.hpp + .cpp
Error in code Shows in the Output; the game keeps running The game does not open until it compiles
Performance About 30× slower in script math; a thousand scripted objects use about 5% of the frame Native
Exported game Ships the scripts, readable, in data The code becomes the executable
objects/Player.lua
function onSpawn(self)
self.vidas = 3
self:onCollide("Enemy", function(inimigo)
inimigo:destroy()
self.vidas = self.vidas - 1
end)
end
function onUpdate(self)
self.hspeed = axis("esquerda", "direita") * self.velocidade
if pressed("atirar") then
spawn("Bullet", self.x, self.y, "Instancias")
Audio.play("tiro", { volume = 0.4 })
end
end
Lua C++
Instance fields and methods self.x, self:destroy() x, destroy()
Referring to an object By name: count("Enemy") By class: count<Enemy>()
Modules Audio.play, Save.set, Ui.get Audio::play, Save::set, Ui::get
Camera camera.shake(3, 0.2) scene().camera.shake(3, 0.2f)
Inspector variables Fields of self Class fields, with BRASA_VARS
Instance data Any field on self Members declared in the class
Calling a function of another object inimigo:levarDano(1) inimigo.levarDano(1)
  • Sequences with waits: self:run, wait, waitSteps, waitUntil. See Timers.
  • Tables in Save: Save.set("inventario", { "espada", "escudo" }).
  • all(object) returns the list of instances.
  • Code split across files: local jogo = require("src.jogo") loads src/jogo.lua.
  • API autocomplete in the code tab.
  • Vec2, Handle<T> and the engine headers: Advanced.
  • What is language-specific in Brasa: C++ in Brasa.