[TOTPP] Lua Scenario Template

Setting up Lua in a testbed folder clone of the ToTPP Overlords scenario.
Followed the instructions, and loaded the save...And a popup gave me an error...
Probably something wrong in my events...? Sorry if this is a basic newbie error by me.

Output was as follows...

WARNING: setGuaranteeUnitActivationType was set to nil. The functionality to guarantee that a tribe will have an active unit is disabled. Some events may not work properly until a unit type is specified.
File number 1 event ending at line 23 successfully parsed. Event number is 1.
File number 1 event ending at line 39 successfully parsed. Event number is 2.
File number 1 event ending at line 58 successfully parsed. Event number is 3.
File number 1 event ending at line 73 successfully parsed. Event number is 4.
File number 1 event ending at line 88 successfully parsed. Event number is 5.
File number 1 event ending at line 103 successfully parsed. Event number is 6.
File number 1 event ending at line 118 successfully parsed. Event number is 7.
File number 1 event ending at line 127 successfully parsed. Event number is 8.
File number 1 event ending at line 136 successfully parsed. Event number is 9.
File number 1 event ending at line 145 successfully parsed. Event number is 10.
File number 1 event ending at line 156 successfully parsed. Event number is 11.
File number 1 event ending at line 165 successfully parsed. Event number is 12.
File number 1 event ending at line 174 successfully parsed. Event number is 13.
File number 1 event ending at line 183 successfully parsed. Event number is 14.
File number 1 event ending at line 192 successfully parsed. Event number is 15.
File number 1 event ending at line 203 successfully parsed. Event number is 16.
File number 1 event ending at line 212 successfully parsed. Event number is 17.
File number 1 event ending at line 221 successfully parsed. Event number is 18.
File number 1 event ending at line 230 successfully parsed. Event number is 19.
File number 1 event ending at line 241 successfully parsed. Event number is 20.
File number 1 event ending at line 250 successfully parsed. Event number is 21.
File number 1 event ending at line 259 successfully parsed. Event number is 22.
File number 1 event ending at line 268 successfully parsed. Event number is 23.
File number 1 event ending at line 277 successfully parsed. Event number is 24.
File number 1 event ending at line 286 successfully parsed. Event number is 25.
File number 1 event ending at line 297 successfully parsed. Event number is 26.
File number 1 event ending at line 306 successfully parsed. Event number is 27.
File number 1 event ending at line 315 successfully parsed. Event number is 28.
File number 1 event ending at line 324 successfully parsed. Event number is 29.
File number 1 event ending at line 333 successfully parsed. Event number is 30.
File number 1 event ending at line 342 successfully parsed. Event number is 31.
File number 1 event ending at line 353 successfully parsed. Event number is 32.
File number 1 event ending at line 362 successfully parsed. Event number is 33.
File number 1 event ending at line 371 successfully parsed. Event number is 34.
File number 1 event ending at line 380 successfully parsed. Event number is 35.
File number 1 event ending at line 391 successfully parsed. Event number is 36.
File number 1 event ending at line 400 successfully parsed. Event number is 37.
File number 1 event ending at line 409 successfully parsed. Event number is 38.
File number 1 event ending at line 418 successfully parsed. Event number is 39.
File number 1 event ending at line 427 successfully parsed. Event number is 40.
File number 1 event ending at line 447 successfully parsed. Event number is 41.
File number 1 event ending at line 464 successfully parsed. Event number is 42.
...ERLORDS 1940 - Lua Update\LuaCore\legacyEventBuilder.lua:378: Event file 1 at line number 474 doesn't have an open action.
stack traceback:
[C]: in function 'error'
...ERLORDS 1940 - Lua Update\LuaCore\legacyEventBuilder.lua:378: in function 'legacyEventBuilder.buildLegacyEvents'
(...tail calls...)
[C]: in function 'require'
N:\CIV2 TOT\1_OVERLORDS 1940 - Lua Update\events.lua:52: in main chunk
 
Probably something wrong in my events...? Sorry if this is a basic newbie error by me.

Yes, it is a problem with your events. However, it looks like I should change the error message to something more helpful to everyone who isn't me from a couple years ago.

WARNING: setGuaranteeUnitActivationType was set to nil. The functionality to guarantee that a tribe will have an active unit is disabled. Some events may not work properly until a unit type is specified.

Don't worry about this warning for now.

File number 1 event ending at line 464 successfully parsed. Event number is 42.

This means that you're events are correct (or, at least make sense to the Legacy Event Engine) up to line 464. You should check the next event to make sure it is written correctly.

...ERLORDS 1940 - Lua Update\LuaCore\legacyEventBuilder.lua:378: Event file 1 at line number 474 doesn't have an open action.
stack traceback:

Line 474 is where the parser realised that there was a problem. No "open action" means that the line isn't recognised as an action key word (Create Unit, Text, etc.), and there wasn't an action key word on a previous line for the current line to be a parameter for the action.
 
@Prof. Garfield
Thanks, sir - I loaded up PFE, and the event in question that ends at line 464, is this one:

@IF
RECEIVEDTECHNOLOGY
technology=19
receiver=United States
@THEN
JUSTONCE
TEXT
^
^^ America helps the Allied nations in the form of a "Lend-Lease" system.
^^ Supplies, hardware, and money are provided, for a promise of repayment
^^ when the war is over. Truly, the USA is the "Arsenal of Democracy"...
^
ENDTEXT
PLAYWAVEFILE
TELE.wav
@ENDIF

Not what is wrong here, but I can see no obvious errors. Naturally, I am missing something.
 
(Prof. Garfield explains below)
Spoiler :
Maybe is it because the "onReceivedTechnology" isn't supported in Lua at the moment ?
(while it could be tested on other occurences if a technology is owned)


Prof. Garfield shall enlighten us.
 
Last edited:
An interesting point, sir - If that is the case, then workarounds will have to be considered...RECEIVEDTECHNOLOGY events are pre-dominant in this scenario.
 
Thanks, sir - I loaded up PFE, and the event in question that ends at line 464, is this one:

The event after the event that ends at line 464 is the one that caused the error. The error itself should be close to line 474 (probably something out of order).

Maybe is it because the "onReceivedTechnology" isn't supported in Lua at the moment ?
(while it could be tested on other occurences if a technology is owned)

Prof. Garfield shall enlighten us.

The received technology event does work. I use the onTurn event to make the check, which is the way TOT does it.
 
I noticed that you uploaded the scenario, so had a look at the events myself.

Line 474 has a couple extra 'tab' characters on the end of the line, which are causing the parser to not realise that givetechnology is a proper event keyword. I'll have to fix that. I thought to remove extra spaces, but didn't think of tabs.

EDIT: The same error occurs at lines 497 and 520, after which the events should load properly.
 
Aha! I see what you mean - Excellent detective work, man. I would not have noticed that.

Seems all the givetech events have the tabbing...Going through, and fixing this now.
 
Last edited:
1. The zones/region system is extremely powerful and useful in many different ways. We should try to make it intuitive to designate certain areas zones or regions. I'd probably "ship" with an "Area of Recruitment" built into this.

Could you explain what this system exactly does please? Depending on what effects it will allow, I would like to use it in 1453 as I have different regions like Europe, Middle East and the New World.
 
Many thanks for the thread and the LUA template. This is really helpful to understand the basics of LUA.:thumbsup:

I too plan to write every event complete in LUA.
 
Could you explain what this system exactly does please? Depending on what effects it will allow, I would like to use it in 1453 as I have different regions like Europe, Middle East and the New World.

So in Cold War, this is the system that prevents European Infantry from being built in Africa, for example. It's the canBuildSettings that has shipped with the template (go check it out in Cold War to get an idea of what one can do).
 
@JPetroski

I am about to finish fixing up the map in Overlords to stop the "goto" crash, using Lua to segment it into poly zones - Thanks to @Prof. Garfield.
If you have the time, this coming week I was going going to ask your advice on how to set up the "canbuild" systems for the scenario?
Looking forward to wading into Lua fully - I have questions too about unit upgrades, and a few other features...:)
 
So in Cold War, this is the system that prevents European Infantry from being built in Africa, for example. It's the canBuildSettings that has shipped with the template (go check it out in Cold War to get an idea of what one can do).

Ah, thanks. Than I know what it does. I used the canBuildSettings in the AWI scenario for preventing the British Empire building regular british units in America.
 
@JPetroski

I am about to finish fixing up the map in Overlords to stop the "goto" crash, using Lua to segment it into poly zones - Thanks to @Prof. Garfield.
If you have the time, this coming week I was going going to ask your advice on how to set up the "canbuild" systems for the scenario?
Looking forward to wading into Lua fully - I have questions too about unit upgrades, and a few other features...:)

Here's the Github page for the template, though I think the only changes I made since I posted the template here was the changed polygon stuff. However, you might need it.

https://github.com/ProfGarfield/LuaTemplate

First, in the LuaParameterFile, you will have to change object.lua to give "lua names" to your unit types, improvements, technologies, etc., or at least those you'll want to refer to with Lua code.

To use the build restrictions, look in the LuaRulesEvents folder, and open canBuildSettings.lua. You will make changes there. I've attached a copy of Imperialism II which I used for testing. The canBuildSettings.lua file there can give you some examples.

If you want units to upgrade beyond veteran status, you will have to have extra unit types for them. You may want to consider what units you plan to cut, if you've already used all the unit types available.

I strongly recommend doing my Lua Lessons at least until completing the discussion of tables at the start of lesson 3. That should give you at least a basic idea of what is going on.
 

Attachments

Thanks, man - The upgrade thing is for a future scenario - And I had the Object file and canBuildSettings opened and ready to edit...
So that will be my next move. I will use your coldwar files, and the linked thread to keep myself right. Cheers for the example, it will be useful.

Hopefully I can get this working...:)
As it will be a big aspect for the Overlords scen.
 
Forgive me if this a silly question, but is there a way with Lua to change the tribe leader name mid-game?
 
Forgive me if this a silly question, but is there a way with Lua to change the tribe leader name mid-game?

Absolutely.

Code:
civ.getTribe(0).leader.name="New Leader Name"
Replace 0 above with the tribe id number (0-7).

If you've given the tribe a name in the object.lua file, you can do

Code:
object.tTribeName.leader.name="New Leader Name"

Double check that you have the line
Code:
local object = require("object")
at the top of the file where you make this event.

As it happens, I use this kind of an event as an example in the second Lua Lesson.
 
I just updated the Github repository for the template. I believe there were a couple fixes to the bestow improvement event in the Legacy Event Engine, and I fixed some error checking for the can build functionality. I also put a link to the repository in the first post.
 
Back
Top Bottom