[TOT] Feedback Thread for [TOTPP] Get Started With Lua Events

Is it possible to insert line returns within the simple civ.ui.text without using the func.splitlines?

Code:
local Text =
[[Emperor Napoléon, having failed to subdue any of the other major powers in your bid for mastery of the continent, Austria has sent a diplomatic letter to your minister of foreign affairs stating that it has joined the ranks of the anti-French coalition and therefore that, once again, a state of war exists between your two nations.
^
Expect no further peace treaty from it, other than one gained by the conquest of all its cities.
^
Furthermore, any Austrian troops that were still in your service have deserted.]]

civ.ui.text(func.splitlines(introText))

I've read in lua forums that the "\n" serve that purpose but when I try to enter it in my text it doesn't appear to do work.

Code:
civ.ui.text("Emperor Napoléon, having failed to subdue any of the other major powers in your bid for mastery of the continent, Austria has sent a diplomatic letter to your minister of foreign affairs stating that it has joined the ranks of the anti-French coalition and therefore that, once again, a state of war exists between your two nations. \nExpect no further peace treaty from it, other than one gained by the conquest of all its cities.\nFurthermore, any Austrian troops that were still in your service have deserted.")
 
Is it possible to insert line returns within the simple civ.ui.text without using the func.splitlines?

Code:
local Text =
[[Emperor Napoléon, having failed to subdue any of the other major powers in your bid for mastery of the continent, Austria has sent a diplomatic letter to your minister of foreign affairs stating that it has joined the ranks of the anti-French coalition and therefore that, once again, a state of war exists between your two nations.
^
Expect no further peace treaty from it, other than one gained by the conquest of all its cities.
^
Furthermore, any Austrian troops that were still in your service have deserted.]]

civ.ui.text(func.splitlines(introText))
I've read in lua forums that the "\n" serve that purpose but when I try to enter it in my text it doesn't appear to do work.

I've tried several things, but have not yet figured out how to manually start a new line. What I've done when I needed that functionality is to use a 'dialog' box and use checkboxes for each line.
 
Is it possible to insert line returns within the simple civ.ui.text without using the func.splitlines?

Code:
local Text =
[[Emperor Napoléon, having failed to subdue any of the other major powers in your bid for mastery of the continent, Austria has sent a diplomatic letter to your minister of foreign affairs stating that it has joined the ranks of the anti-French coalition and therefore that, once again, a state of war exists between your two nations.
^
Expect no further peace treaty from it, other than one gained by the conquest of all its cities.
^
Furthermore, any Austrian troops that were still in your service have deserted.]]

civ.ui.text(func.splitlines(introText))

I've read in lua forums that the "\n" serve that purpose but when I try to enter it in my text it doesn't appear to do work.

Code:
civ.ui.text("Emperor Napoléon, having failed to subdue any of the other major powers in your bid for mastery of the continent, Austria has sent a diplomatic letter to your minister of foreign affairs stating that it has joined the ranks of the anti-French coalition and therefore that, once again, a state of war exists between your two nations. \nExpect no further peace treaty from it, other than one gained by the conquest of all its cities.\nFurthermore, any Austrian troops that were still in your service have deserted.")

After taking another look at the definition of splitlines and trying to understand it (and not yet succeeding), I finally tried something which appears to work. Split lines with \n^ or \r^ and func.splitlines.

Code:
civ.ui.text(func.splitlines("Line 1 \n^Line 2\r^Line 3"))
 
After taking another look at the definition of splitlines and trying to understand it (and not yet succeeding), I finally tried something which appears to work. Split lines with \n^ or \r^ and func.splitlines.

Code:
civ.ui.text(func.splitlines("Line 1 \n^Line 2\r^Line 3"))

Yes, that worked. Thank you!
 
Prof. Garfield, one more time thank you very much for all your work ! :) Renovating my home makes good progress and I´m glad to come back to your tutorial when the renovating work will be finished (what will be approximately in the next month).

The space civs of my mod need lua events and I´m wondering how even a normal Civ 2 epic game will perform, with all the new possibilities that lua does offer (and when I understand how to use them). The modding universe of Civ 2 ToTPP is in front of us - and you give us the key to enter it. :goodjob:
 
From lesson 2 - Was this not supposed to run anything in the lua: demo?

Code:
function fToC(tempInF)
fFreezeTemp = 32 -- Water freezing point in Fahrenheit
fPerC = 1.8 -- This is the number of Fahrenheit degrees per degree Celsius
local fFreezeAt0Temp = tempInF -fFreezeTemp
local tempInC = fFreezeAt0Temp/fPerC
return tempInC
end

It isn't doing anything and to try to get it to do something, I've written both of these above it. Neither causes it to do anything:

tempInF = ("100")
tempInF = 100

I also tried putting these within the function and after it.

Then, I tried write

Code:
if tempInF == 100 then
print(tempInC)
end

and just got nil.

I'm having much more luck progressing through the civ-specific examples, just wondering if I'm missing something here.
 
Try this
Code:
function fToC(tempInF)
fFreezeTemp = 32 -- Water freezing point in Fahrenheit
fPerC = 1.8 -- This is the number of Fahrenheit degrees per degree Celsius
local fFreezeAt0Temp = tempInF -fFreezeTemp
local tempInC = fFreezeAt0Temp/fPerC
return tempInC
end
print(fToC(100)) -- this will print the Celsius conversion of 100 degrees Fahrenheit

A few points:

The function definition alone won't show anything, since that is simply storing instructions for later use.

The variables tempInF and tempInC only have meaning within the definition of the function fToC. You don't need to use those variable names outside the function. However, since they are defined within the function as local variables, you can use the same names elsewhere without ill effect. (Aside, I should have made fFreezeTemp, fPerC also local. Not sure why I didn't, I'll fix the error.)

To use a function, in this case fToC, you write the function name, then the data that goes into the function (the 'argument(s)') inside parentheses. Hence, fToC(100), or print(fToC(100)), where the output of fToC(100) is used as the input to the print function.

The Lua demo won't show anything unless the print command is used (this is different from the Civ II Lua console, which seems to have an implicit print command when the line returns a value). Hence, why we have the line print(fToC(100)) instead of just fToC(100).

Let me know if you need more guidance.
 
I'm through chapter 4 now. I think some of the examples from here on out are a little complex for what I'm trying to do right now, but it's good to see what is there, as it will help tremendously when I'm ready for them. Bearing in mind that one thing I really need is practice, I am looking forward to building a single player scenario as I think a simple campaign scenario against the AI should require significantly less advanced events, and be good to confirm I can handle scripting the basic macro in the new language (which I think I more or less could probably achieve at this point).

I really appreciate you putting this together. I can get why it is called a "language" as it feels similar to when I was trying to learn one. You get bits and pieces at a time and over time it starts to fit more and more together, but unless you're using it daily it's going to be challenging to really understand and retain it... In any event, a good reason for a new project to start soon.
 
I tried to apply your lesson for the leaders changing but wasn't able to get it to work:

Code:
local chinaRulers = {
[1] = {name = "Mao Zedong", female = false}, -- this is the year the game starts
[2] = {name = "Did this work?", female = false}, 
[3] = {name = "Female China", female = true},
[4] = {name = "Seleucus II Callinicus", female = false},
[5] = {name = "Seleucus III Ceraunus", female = false},
-- this makes the point
[-126] = {name = "Cleopatra Thea", female = true},
-- have a female ruler to test, though
}--close seleucidRulers


local function doThisOnTurn(turn)
    --My attempt to get the correct leaders per year

if chinaRulers[civ.getGameYear()] then
    -- if there is no entry for this index, it returns nil, which the if statement counts as false.
    object.tChina.leader.name = chinaRulers[civ.getGameYear()].name
    object.tChina.leader.female = chinaRulers[civ.getGameYear()].female
end --if seleucidRulers[civ.getGameYear()]   
end--doThisOnTurn

civ.scen.onTurn(doThisOnTurn)

Of note I first tried placing this (aside from the local and table) into civ.scen.onTurn(function (turn), where I already have a lot of stuff. It didn't seem to work. So I moved it outside and tried to mimic what you did, but it still didn't work, so I'm not sure what I need to do to get it working?
 
civ.getGameYear() is different from civ.getTurn()

If you want to specify leaders based on the game turn, you'll have to change instances of civ.getGameYear() to civ.getTurn().

I used civ.getGameYear() in my example, since turns were 1 year, and that way I didn't have to worry about exactly which turn was which. You may want to experiment with civ.getGameYear() to see how it works if a turn has both years and months.
 
I changed it around to civ.getTurn and this does not work:

Code:
local chinaRulers = {
[1] = {name = "Mao Zedong", female = false}, -- this is the year the game starts
[20] = {name = "Did this work?", female = false}, 
[30] = {name = "Female China", female = true},
--[4] = {name = "Seleucus II Callinicus", female = false},
--[5] = {name = "Seleucus III Ceraunus", female = false},
-- this makes the point
--[-126] = {name = "Cleopatra Thea", female = true},
-- have a female ruler to test, though
}--close seleucidRulers


local function doThisOnTurn(turn)
    --My attempt to get the correct leaders per year

if chinaRulers[civ.getTurn()] then
    -- if there is no entry for this index, it returns nil, which the if statement counts as false.
    object.tChina.leader.name = chinaRulers[civ.getTurn()].name
    object.tChina.leader.female = chinaRulers[civ.getTurn()].female
end    
end

civ.scen.onTurn(doThisOnTurn)

I also tried deleted "local function doThisOnTurn(turn...)" and just added

Code:
if chinaRulers[civ.getTurn()] then
    -- if there is no entry for this index, it returns nil, which the if statement counts as false.
    object.tChina.leader.name = chinaRulers[civ.getTurn()].name
    object.tChina.leader.female = chinaRulers[civ.getTurn()].female
end

To the "civ.scen.onTurn(function (turn)" section, but it too does not work.

Any ideas?
 
This is the events file with it placed on 419. Line 224 has been -- out
 

Attachments

  • ColdWarEvents.zip
    8.3 KB · Views: 132
How have you been testing this? Have you just been changing the game year in cheat mode, or have you been letting the game cycle through all the turns? The 'on turn' event only happens between the purple player's turn, and the barbarian's turn. That is when the event will trigger, and check if the name must be changed, and it will only check on those turns where you have an entry in the chinaRulers table.
 
Thank you! Yes, that was the problem. It works like a charm!

...Which means I now have tables of 7x national leaders over 50 years to fill out....
 
Top Bottom