hai
i need some love2d helpz
since everything is coded in lua, i'm struggling with tryin' to make a dialogue system
dialogue = {
messages = {}
}
dialogue.active = false --Currently a dialogue?
dialogue.overlay = love.graphics.newImage("img/ui/dialogue_overlay.png") --Overlay background for dialogue text
dialogue.font = love.graphics.setNewFont("fnt/dialogue.ttf", 12) --Dialogue font
dialogue.currentMessage = "" --Current full message to be displayed
function dialogue:update(dt)
if not dialogue.messages[1].msg == nil then
dialogue.currentMessage = dialogue.messages[1].msg
end
end
function dialogue:addMessage(name, message)
local msgg = {}
if name == "" then
msgg.name = "???"
else
msgg.name = name
end
if message == "" then
return 0
else
msgg.msg = message
end
table.insert(dialogue.messages,msgg)
return 1
end
function dialogue:draw()
--Draw overlay
if self.active then
love.graphics.draw(self.overlay,0,0)
end
--Draw message
if self.active then
if not self.currentMessage == "" then
love.graphics.print(self.currentMessage, 30,30)
end
end
love.graphics.print(self.currentMessage, 30,90)
end
not completely done yet, i'm just testing out the trees. you are supposed to call forth dialogue:addMessage() first to add a dialogue table, which stores it in dialogue.messages, and then in the dialogue:update(dt) function, which updates every game tick; it'll check to see if the first index in dialogue.messages exists, and if it does, it sets the message in it to dialogue.currentMessage, and dialogue:draw() draws it onto the screen
something = dialogue:addMessage("","Hello there")
dialogue.active = true
here is where i am calling forth dialogue:addMessage
i also set it to active too beneath it so it draws the overlay