So I'm trying to add Lua for scripting and I have a rough idea of what I want do do, but trying to actually execute it has been rather challenging. I know that I probably want to access and mutate components through scripts and there's two solutions I thought of. The first solution is to have a ScriptComponent that has the path to the script to be executed this script would be able to access and mutate components of the entity it's attached to. The second solution is to allow scripts to access any entity and their components which I don't think is that bad of an idea.
The challenge/confusion is actually running the scripts I don't think I want to just reexecute the script each frame so would I just run the script once and then use callbacks?
Here's an example of how I'd like to write the lua code I've spent a lot of time with Roblox and LOVE2D so it's kind of based off of that.
local playerEntity = scene.GetEntity("Player")
local playerMoveComponent = playerEntity.GetCommponent("MoveComponent")
function Update(deltaTime)
if input.isKeyDown("w") then
playerMoveComponent:SetDirection()
end
end
-- another option
function keypressed(key)
end
This is probably a generic question so there's probably a plethora of angles to approach this, but any tips and suggestions to get me on the right track would be appreciated.