LUA timed text popups [Solved]
Moderator: Moderators
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
LUA timed text popups [Solved]
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.
Hidden/Spoiler:
Hidden/Spoiler:
Last edited by Fiodis on Sat Nov 27, 2010 2:47 pm, edited 1 time in total.
- Firefang
- Major

- Posts: 518
- Joined: Mon Nov 15, 2010 8:55 pm
- Location: California
Re: LUA timed text popups
Try looking at the lua from kamino campaign and see how they show the five minute timer on the screen.
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA timed text popups
Drop your comma. Use a single, one-second timer that displays a different message each time it expires.
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: LUA timed text popups
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.
Hidden/Spoiler:
Hidden/Spoiler:
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.
That won't quite work for what I have in mind, since I want to display a text message rather than a number.Firefang wrote:Try looking at the lua from kamino campaign and see how they show the five minute timer on the screen.
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA timed text popups
Now you're getting an error because your "if" statements are equations and not equalities: "=" =/= "==".
=
=
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: LUA timed text popups
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. 
Hidden/Spoiler:
Hidden/Spoiler:
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: LUA timed text popups
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.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:Hidden/Spoiler:I can't see how an = anywhere near that particular "end" would make any sense at all.Hidden/Spoiler:
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: LUA timed text popups
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:
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?
Hidden/Spoiler:
Code: Select all
C:\BF2_ModTools\data_FTG\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\FTG\FTGc_con.lua:139: unexpected symbol near `,'- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: LUA timed text popups
No, your comma is in the wrong place, along with the variable after it. The below code has been corrected:
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.
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
)- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: LUA timed text popups
Ah, thanks Zerted and Mav, that last modification worked! 
