Page 1 of 1
LUA timed text popups [Solved]
Posted: Thu Nov 25, 2010 4:22 pm
by Fiodis
I'm trying to create a LUA code that will display a text countdown to a specific event. To this aim, I composed the following code:
Unfortunately, it returns the following error:
My question is in two parts, then. What's wrong with my current code, and how could I rewrite it to make it more streamlined? The current "elseif" pattern seems somewhat inefficient.
Re: LUA timed text popups
Posted: Thu Nov 25, 2010 4:26 pm
by Firefang
Try looking at the lua from kamino campaign and see how they show the five minute timer on the screen.
Re: LUA timed text popups
Posted: Thu Nov 25, 2010 11:51 pm
by Maveritchell
Drop your comma. Use a single, one-second timer that displays a different message each time it expires.
Re: LUA timed text popups
Posted: Fri Nov 26, 2010 2:34 pm
by Fiodis
Alright, I revised the code to use one timer, and to reset and restart the timer each time it expires, also showing a different message each time:
I kept the comma since removing it gave me another error and the stock campaign scripts I looked at used the comma in the same place. This time the error made a bit less sense:
It's telling me to add a "then" near that = mark, but the "then" is there already. I have a nagging feeling I'm going about this the wrong way, but I can't think of any stock campaign scripts with repeating timers to look at for guidance.
When it come's to that, I just don't know that much about timers. What happens when a timer elapses? Is it automatically reset, and I can just use StartTimer to kick it back into motion? And what's the difference, exactly, between a timer reaching zero and me using DestroyTimer? I assume it complete removes the timer from memory, so I have to recreate it if I want to use it again, but I'm not sure, since the stock documentation says not to use a timer at all after it's destroyed.
Firefang wrote:Try looking at the lua from kamino campaign and see how they show the five minute timer on the screen.
That won't quite work for what I have in mind, since I want to display a text message rather than a number.
Re: LUA timed text popups
Posted: Fri Nov 26, 2010 8:51 pm
by Maveritchell
Now you're getting an error because your "if" statements are equations and not equalities: "=" =/= "==".
=
Re: LUA timed text popups
Posted: Fri Nov 26, 2010 9:12 pm
by Fiodis
So the if statements are saying "if speakcount is equivalent to #" rather than "if speakcount is equal to #"? Adding in == instead of = gave me the original comma error again, so I took out the comma and got something very strange:
I can't see how an = anywhere near that particular "end" would make any sense at all.

Re: LUA timed text popups
Posted: Fri Nov 26, 2010 10:36 pm
by Maveritchell
Fiodis wrote:So the if statements are saying "if speakcount is equivalent to #" rather than "if speakcount is equal to #"? Adding in == instead of = gave me the original comma error again, so I took out the comma and got something very strange:
I can't see how an = anywhere near that particular "end" would make any sense at all.

Now you
are missing a comma. In your first posted code, the comma was incorrect, but in your most recently posted code (just above my last post) the comma was in the correct place, which is why I didn't mention it.
Re: LUA timed text popups
Posted: Sat Nov 27, 2010 11:13 am
by Fiodis
I added a final elseif statement to set the function = to nil after it's done, to save CPU power. Adding in the comma and that new section, the updated code is:
The place around the comma gives me another error:
Code: Select all
C:\BF2_ModTools\data_FTG\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\FTG\FTGc_con.lua:139: unexpected symbol near `,'
I'm not sure what the symbol could be unless it's the comma itself. For future reference, what is the use of the comma there for?
Re: LUA timed text popups
Posted: Sat Nov 27, 2010 1:33 pm
by [RDH]Zerted
No, your comma is in the wrong place, along with the variable after it. The below code has been corrected:
Code: Select all
elseif speakcount == 5 then
ShowMessageText("level.FTG.conversations.five")
speakcount = speakcount +1
elseif speakcount == 6 then
textspawn = nil
end
end -- This is troublesome line 139.
end, --This end is the end of the function
onesecondtimer --This is the second parameter/argument to OnTimerElapse
) ---this is the end of OnTimerElapse
end
end
)
Also, use the ReleaseXXXX methods to clean up callbacks. They tell the C++ to forget about it. Just doing
textspawn = nil only makes Lua forget about it. I don't have the modding docs with me, so the name might be slightly off:
ReleaseObjectinit(textspawn) then
textspawn = nil and don't forget to kill your timer too.
Re: LUA timed text popups
Posted: Sat Nov 27, 2010 2:46 pm
by Fiodis
Ah, thanks Zerted and Mav, that last modification worked!
