Hi guys,
Sorry for the very late reply to this.
I took on board your advise and started to write the module but then got stuck and the mundane world took over and left me with no time to work on it.
Anyway…
This is what I have so far:
messages.lua
local messageQueue = {} local queue={} messageQueue.queue = queue local centerX = display.actualContentWidth\*0.5 local centerY = display.actualContentHeight\*0.5 local w = display.actualContentWidth local working = false local messageFont = native.systemFont local messageDisplay = display.newText ( " ", centerX, centerY, messageFont, 64 ) messageDisplay:setFillColor(1) messageDisplay.alpha=0 function messageQueue.hideMessage() print("HIDING MESSAGE") local m=queue[1] if m.fadeOut then local fadeOut = transition.to(messageDisplay, {alpha=0, time=500}) else messageDisplay.alpha=0 end end function messageQueue.showMessage() print("SHOWING MESSAGE") local m=queue[1] messageDisplay.text = m.message if m.fadeIn then local fadeIn = transition.to(messageDisplay, {alpha=1, time=500}) else messageDisplay.alpha=1 end timer.performWithDelay(m.displayTime, messageQueue.hideMessage() ) end function messageQueue.processQueue() isWorking = true if #queue \< 1 then isWorking = false return false else messageQueue.showMessage() end end function messageQueue:addMessage(msg, time, fadeIn, fadeOut) local newMessage={} newMessage.message. = msg newMessage.displayTime = time newMessage.fadeIn. = fadeIn newMessage.fadeOut. = fadeOut table.insert( queue, newMessage ) if not working then self.processQueue() end return end return messageQueue
and it is accessed like so:
main.lua
local messageQueue = require ( "messages" ) local f = 1 local tmpMsg = "This is message "..tostring(f) messageQueue:addMessage(tmpMsg, 8000, true, true) -- addMessage( message to be display, time to be displayed for, fadeIn? (boolean), fadeOut? (boolean)
The issue I’m having is that in the showMessage function if I comment out the timer then the message shows up as expected (either with our without fading in as specified).
But, if I uncomment the timer so that it should then go to the hideMessage function after the given time, what actually happens is that the message never appears and the console shows both the ‘show’ and ‘hide’ print statements.
I’m probably missing something obvious but I can’t for the life of me figure it out.
(apologies if the code isn’t brilliant, this is my first try at writing an external module).
Many thanks
Chris