Results 1 to 14 of 14

Thread: Quick question about too-many spaces in scripting

  1. #1
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    3,841

    Default Quick question about too-many spaces in scripting

    Guys,
    have a look at this:
    Code:
            set_event_counter spainprincess 1    
    
        monitor_event PreFactionTurnStart I_TurnNumber > 60
            and FactionType slave
            
            inc_event_counter spainprincess 1
    
    
            if I_EventCounter spainprincess  > 28
                and I_IsFactionAIControlled spain
                if I_SettlementOwner Leon = spain
                    spawn_character spain random_name, princess, age 19, x 37, y 152
                    set_event_counter spainprincess 0
                end_if
            end_if
        end_monitor
    This seems to fire every turn after turn 60. Why it would happen?
    I've spotted there're two spaces between "spainprincess" and "> 28".
    Is it possible to be the cause? (the script taks the line as erronuous so it's always true, so it fires every turn)

    I think the code should look like this:

    Code:
        monitor_event PreFactionTurnStart I_TurnNumber = 60
    		and FactionType slave
    
            set_event_counter spainprincess 1    
    
        end_monitor
    
    
        monitor_event PreFactionTurnStart I_TurnNumber > 60
            and FactionType slave
            
            inc_event_counter spainprincess 1
    
            if I_EventCounter spainprincess > 28
                and I_IsFactionAIControlled spain
                if I_SettlementOwner Leon = spain
                    spawn_character spain random_name, princess, age 19, x 37, y 152
                    set_event_counter spainprincess 0
                end_if
            end_if
        end_monitor

    Last edited by Jurand of Cracow; May 04, 2020 at 02:18 AM.
    If you want to play a historical mod in the medieval setting the best are:
    the Stainless Steel Historical Improvement Project,
    and the Broken Crescent + Buff and Shine.
    ........................................................................................................................................
    Reviews of the mods (all made in 2018): SSHIP, Wrath of the Norsemen, Broken Crescent.
    Pros and cons of having merchants in an M2TW mod. Arguments against the forts in M2TW.
    Home rules for playing a game without exploiting the M2TW engine deficiencies.
    Thrones of Britannia: review, opinion on the battles, ideas for modding. No good mod yet, alas!
    Dominant strategy in Rome 2 TW and Attila TW: “Sniping groups of armies”. Still there, alas!
    .................................................................................................................................................................................
    Developer of the SSHIP: traits, ancillaries, script fixing, guides, historical improvements

  2. #2

    Default Re: Quick question about too-many spaces in scripting

    It is certainly possible that the extra space was the cause of the bug. It may invalidate the condition such that it simply isn't used. You definitely don't need the first monitor (that effectively terminates itself without terminating). The way you have your monitor conditions set up should work but it makes me uncomfortable to look at, so I moved them around to be more conventional. You also don't need the nested if loop since it contains the only effects in its parent, its conditions can be combined with the parent conditions. Btw, I'm not sure what will happen if the faction leader already has four children and you try to spawn a princess. Can princesses exist who aren't daughters of the faction leader?

    Code:
        set_event_counter spainprincess 1    
    
        monitor_event PreFactionTurnStart FactionType slave
        and I_TurnNumber > 60
            
            inc_event_counter spainprincess 1
    
            if I_EventCounter spainprincess > 28
            and I_IsFactionAIControlled spain
            and I_SettlementOwner Leon = spain
                spawn_character spain random_name, princess, age 19, x 37, y 152
                set_event_counter spainprincess 0
            end_if
        end_monitor

  3. #3
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    3,841

    Default Re: Quick question about too-many spaces in scripting

    Thanks for the answer. Actually, the code is slightly longer. This should work?

    Code:
            set_event_counter spainprincess 1
    ...
            set_event_counter cumansprincess 28
    
    
        monitor_event PreFactionTurnStart I_TurnNumber > 60
            and FactionType slave
            
            inc_event_counter spainprincess 1
    ...
            inc_event_counter cumansprincess 1
    
    
            if I_EventCounter spainprincess > 28
                and I_IsFactionAIControlled spain
                if I_SettlementOwner Leon = spain
                    spawn_character spain random_name, princess, age 19, x 37, y 152
                    set_event_counter spainprincess 0
                end_if
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Santiago = spain
                    spawn_character spain random_name, princess, age 19, x 14, y 155
                    set_event_counter spainprincess 0
                end_if
            end_if
    ...
    end_monitor
    The princesses are not in the family tree so there's no that limit of 4. There's a submod Royal Ladies of the Court that allows recruitment of unlimited (well, within the engine limits) princesses at a price.
    Last edited by Jurand of Cracow; May 05, 2020 at 02:47 AM.

  4. #4
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,251

    Default Re: Quick question about too-many spaces in scripting

    I tested a double space and it worked fine. Phew.

    All else looks right in that first script so I wonder if it was an end of line issue: http://www.twcenter.net/forums/showt...2#post13984052

    That last script...

    Code:
            if I_EventCounter spainprincess > 28
                and I_IsFactionAIControlled spain
                if I_SettlementOwner Leon = spain
                    spawn_character spain random_name, princess, age 19, x 37, y 152
                    set_event_counter spainprincess 0
                end_if
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Santiago = spain
    The bold line is re-testing something which which was already found to be true in the blue line. If the blue line wasn't true then the bold line won't be reached anyway. So you may as well just do this...

    Code:
            if I_EventCounter spainprincess > 28
                and I_IsFactionAIControlled spain
                if I_SettlementOwner Leon = spain
                    spawn_character spain random_name, princess, age 19, x 37, y 152
                    set_event_counter spainprincess 0
                end_if
                if I_SettlementOwner Santiago = spain
                    spawn_character spain random_name, princess, age 19, x 14, y 155
                    set_event_counter spainprincess 0
                end_if
            end_if
    Last edited by Withwnar; May 05, 2020 at 04:06 AM.

  5. #5
    nadalio's Avatar Civis
    Join Date
    Apr 2016
    Location
    Where the nameless things gnawing the earth
    Posts
    102

    Default Re: Quick question about too-many spaces in scripting

    I found this on IMTW, maybe could be useful..
    http://imtw.ru/tutorials/article/114...l-2-total-war/

    Spoiler Alert, click show to read: 

    Script Optimization in Medieval 2 Total War


    So, script optimization is mainly needed for speed, so as not to load the processor and OS. Perhaps, in addition to speed, the probability of departures at the same time will decrease. It is useful to know the principle of the program code (I am not a programmer, I do not pretend, I write only what I read in the topic about optimization). The game parses each monitor in stages, checks each condition, and if it is true, then proceeds to the next. The processor time is spent on this, so you need to be able to optimally select the script conditions. An example of how this works.
    Spoiler (expand)monitor_event FactionTurnStart FactionType england
    and FactionBuildingExists >= governor_house
    and FactionIsLocal

    The game checks the conditions step by step, i.e. the beginning of the course of the fraction, checks the type of fraction at the moment of the beginning of the course of each fraction, and if it is England, it goes further. At the same time, checking the condition for the faction of the building “governor's house” in the building takes longer than checking the FactionIsLocal condition, and with the above arrangement of monitors, it turns out that if you are not playing for England, the game takes a long time to check for the presence of the building in the British, and then discovers that this AI fraction and resets the monitor. In this case, it turns out that the processor has performed useless work, spending time idling. That is, in this example, at least FactionIsLocal should be checked before FactionBuildingExists so as not to waste processor time in vain. By this we mean a rational arrangement of conditions.




    Here is an even more illustrative example, with numbers. Let's say 300 characters are on the campaign map, of which 15 are English. For example, you need to check if at the beginning of the course of the English character with a certain unique trait England owns Paris - an event occurs. If another faction owns Paris, then another event. Such a script at the same time

    Spoiler (expand)CharacterTurnStart FactionType england monitor_event
    and Trait xx_trait> 0
    and I_SettlementOwner Paris england ... the desired effect on the FA
    end_monitor

    monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    and I_SettlementOwner Paris france ... the desired effect by France
    end_monitor

    monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    and I_SettlementOwner Paris hre ... desired effect from the Roman Empire
    end_monitor



    Thus, when checking these conditions, the monitor will work 900 times (3 monitors for 300 characters according to the CharacterTurnStart condition), of which 45 monitors (15 characters and 3 monitors) will work for England, then the trait will be tested 45 times, of which 3 will be effective (1 character with a unique trait and 3 monitors), and the accessory of Paris will be checked 3 times.

    But if the script is written like this
    Spoiler (expand)monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    if I_SettlementOwner Paris england ... desired effect from England
    end_if
    if I_SettlementOwner Paris france ... desired effect from France
    end_if
    if I_SettlementOwner Paris hre ... desired effect from the Roman Empire
    end_if
    endmon



    At the same time, the monitor will start 300 times (300 characters on the map for the CharacretTurnStart condition), Trait xx_trait> 0 (15 English characters on the map) will be checked 15 times for England and Paris will be checked 3 times. Altogether, 600 runs of CharacterTurnStart monitor less and 30 trait checks for England less. The processor is busy less than 2/3 while the same thing happens on the card. Considering that there are several thousand or more monitors in the script and more than 300 characters on the map, the numbers of the processor’s “idle” operation with irrational script writing increase by orders of magnitude.

    By the duration of the processor load, the commands are distributed as follows - if <monitor_event <monitor_conditions <while. That is, checking the condition with if takes the least time, then the event is periodically checked, the condition is checked constantly in the background and the processor constantly takes, as well as the while condition check. According to some reports, 70 monitor_conditions reduce the game speed to 1 fps. In any case, the more monitor_conditions and while you have in the script, the more the processor loads and the longer the script takes longer to calculate. In that topic on TVC, there is a mention of the DotS mod that uses the "nesting ifs" technique (as far as I understand, this is a branched tree using the if condition), where campain_script has a capacity of 60 megabytes, million lines of code and at the same time 1 monitor_event and 1 monitor_conditions and slows down only when rebooting, because executes numerous console commands.

    In addition to optimization topics - they write that they try to avoid monitor_conditions, like the plague, they give an example about the 1648 mod - adding / removing one monitor_event monitor containing 250 if checks does not affect game performance in any way. Adding / removing the script "Carl the taxman" (famous economic) containing 600 monitor_event monitors for all fractions in the game - changes productivity by 40 seconds.

    Here. One of the most harmful conditions is CharacterTurnStart / End, because as we now understand, it works for each character on the map, then this engine checks the membership of the fraction (and spends processor time on this too). Further down the load is SettlementTurnStart / End, less harmful, the same is checked for each settlement. Well and then FactionTurnStartEnd. Which alternative? The following operators offer: CharacterSelected (when the player selected the character), Pre / PostBattle (before or after the battle), EventCounter (value of a specific event counter). In theory, these monitors work less often and more targetedly, the load on the processor is reduced.

    Here is another important point from the alpaca tutorial. The loading order for TurnStart and TurnEnd events is as follows: CharacterTurn [Start / End], SettlementTurn [Start / End], FactionTurn [Start / End]. Why is it important? Sometimes there are interconnected monitors in the script, but they do not work as you intended, i.e. the event occurs at best a turn later, or does not occur at all. Then look at the sequence of monitors, perhaps, for example, some counter changes the value you need before checking its value in another monitor you need. Well, and quite general - the game reads all the files from top to bottom, in this sense, the sequence of scripts and especially traits is of great importance.


    Yes, here's another clarification - the order of files that the game checks is always the same, first campaign_script, then export_descr_character_traits, then export_descr_ancillaries.

    Why it matters personally I was convinced by a specific example - the same event, PostBattle, to which I wanted to bind effects in the script and traits, is checked with the above sequence and I had to change the script. I wanted after the battle if the "Wounded" trait appeared, the counter in campaign_script would start spinning. But it turns out that CS checks the PostBattle event first, and at that moment the traits have not yet been checked and assigned and the counter will never work, even if the general is still hurt. Therefore, I had to change the condition in CS to a less profitable CharacterTurnEnd, which is checked more often and loads the processor more, but it is checked when the traits after the battle are already assigned.




    credit to bitterhowl

  6. #6
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    3,841

    Default Re: Quick question about too-many spaces in scripting

    @Guys: thanks for all advice, I'll delve into it.

    @Withwnar: the second condition is to make only one princess spawned. If she's spawned in Leon, then the counter spainprincess goes to 0, and then the second if (for Santiago) doesn't fire.

    BTW - why may it happen that the princesse get nameless?
    I thought "random_name" would take one from the list for of the spanish names?
    It seems some princesses get their names, but some don't.

    I've had a look at another mod files and I've found eg.

    Code:
            spawn_character ireland, Noah of_Wicklow, merchant, age 25, x 19, y 41
            console_command give_trait "Noah of_Wicklow" GoodMerchant 3
            console_command give_trait "Noah of_Wicklow" NaturalMerchantSkill 3
            console_command give_trait "Noah of_Wicklow" MerchantsGuildMember 1
    Maybe that comma is necessary after the name of the faction (I don't have it in the SSHIP code, but it was neither present in the Royal Ladies of the Court submod for the base Stainless Steel?

    Besides, is it possible to give a trait to the princesses spawned with "random_name" (as in my code), or I need to make like for this merchant 1. give him a proper name, 2. give a trait via console?
    What happens if there'd be more characters with the same name? Would this be a problem to the console command?
    Last edited by Jurand of Cracow; May 06, 2020 at 02:24 AM.

  7. #7
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,251

    Default Re: Quick question about too-many spaces in scripting

    @Withwnar: the second condition is to make only one princess spawned. If she's spawned in Leon, then the counter spainprincess goes to 0, and then the second if (for Santiago) doesn't fire.
    Oh yes. Missed that.

    Maybe that comma is necessary after the name of the faction
    Can't say I've ever tried without one but I'd put money on it being required.

    is it possible to give a trait to the princesses spawned with "random_name"
    Nope. You can't give them labels either, to try and give the trait that way (via give_trait). Even the Unique Names method doesn't work with princesses.

    They can gain traits from trait triggers, of course, but what conditions could you use to single her out, such that only she gets it?

    What happens if there'd be more characters with the same name? Would this be a problem to the console command?
    It would give the trait to the first character of that name that it finds. It looks first in the player's faction, oldest to youngest, then other factions oldest to youngest. "Oldest" here meaning "been in the game the longest", not necessarily "age" because characters can come into the game at varying ages (other than come of age ones).
    Last edited by Withwnar; May 06, 2020 at 04:36 AM.

  8. #8
    Lusitanio's Avatar Content Staff
    Join Date
    Jan 2018
    Location
    Portugal
    Posts
    1,182

    Default Re: Quick question about too-many spaces in scripting

    Jurand what you can do regarding the traits is: if you just want a princess for the same dinasty/family, you can create triggers that give traits to the agent princess of the faction that you want.

    Let's say that you spawn a princess for France and want her to belong to the royal Family.

    Add a trigger with the agent type princess and if the trait is not present on that agent, give it to the agent.

  9. #9
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    3,841

    Default Re: Quick question about too-many spaces in scripting

    @Withwnar: thanks a lot, in this situation I'll create the names in such a situation. It'll kill two birds at once: the namelessness problem, and the lack of traits.
    @Lusitanio: thanks a lot, I've checked the SSHIP code and such a mechanism exists for any princess.

    I'll use such a script
    Code:
            if I_EventCounter spainprincess > 28;            and I_IsFactionAIControlled spain
    
    
                if I_SettlementOwner Leon = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Blanca, princess, age 19, x 37, y 152           ; Charm 4
                    console_command give_trait "Blanca" IAmPrincess 2
                    console_command give_trait "Blanca" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Blanca" PrettyWoman 1
                    console_command give_trait "Blanca" HumbleWoman 1
                    console_command give_trait "Blanca" SpiritedWoman 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if                
                
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Santiago = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Isabel, princess, age 19, x 14, y 155           ; Charm 3
                    console_command give_trait "Isabel" IAmPrincess 2
                    console_command give_trait "Isabel" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Isabel" PrettyWoman 1
                    console_command give_trait "Isabel" GoodPrincess 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if
    
    
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Leon = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Sancha, princess, age 19, x 37, y 152           ; Charm 1
                    console_command give_trait "Sancha" IAmPrincess 2
                    console_command give_trait "Sancha" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Sancha" PrettyWoman 1
                    console_command give_trait "Sancha" PretentiousWoman 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if
                
    
    
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Santiago = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Ana, princess, age 19, x 14, y 155           ; Charm 5
                    console_command give_trait "Ana" IAmPrincess 2
                    console_command give_trait "Ana" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Ana" PrettyWoman 1
                    console_command give_trait "Ana" HumbleWoman 1
                    console_command give_trait "Ana" SpiritedWoman 1
                    console_command give_trait "Ana" UnchasteWoman 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if
    
    
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Leon = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Jimena, princess, age 19, x 37, y 152           ; Charm 2
                    console_command give_trait "Jimena" IAmPrincess 2
                    console_command give_trait "Jimena" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Jimena" BigotWoman 1
                    console_command give_trait "Jimena" HumbleWoman 1
                    console_command give_trait "Jimena" FaithfulWoman 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if
                
    
    
                if I_EventCounter spainprincess > 28
                    and I_SettlementOwner Santiago = spain
                    and RandomPercent < 5
                    
                    spawn_character spain Inmaculada, princess, age 19, x 14, y 155           ; Charm 6
                    console_command give_trait "Inmaculada" IAmPrincess 2
                    console_command give_trait "Inmaculada" Princess_Royal_Blood_Spanish 1
                    console_command give_trait "Inmaculada" PrettyWoman 1
                    console_command give_trait "Inmaculada" TolerantWoman 1
                    console_command give_trait "Inmaculada" SpiritedWoman 1
                    console_command give_trait "Inmaculada" FaithfulWoman 1
                    console_command give_trait "Inmaculada" FairWoman 1
                    
                    historic_event princess_spawn_spain
                    set_event_counter spainprincess 0
                    
                end_if
                
            end_if
    Some additional explanation:

    Quote Originally Posted by Jurand of Cracow View Post
    There's no multiple spawns in one year - if a princess is spawned, then the counter is reset, and afterwards it'll move up by 1 only at 66% chance a turn, so the next princess will be spawned in 20 years (in other words: the cool-down period between spawns is around 20 years, and it's stochastic).
    There's a 18% probability that the next princess will be of the same name as the previous one. However, that one is now 20 years older and the normal triggers have fired on her 40 times (it's 20 years later 2TPY) so some of her traits would already have gone down (aging will hit her fast in her 30ties, the relevant triggers are so programmed by me). Thus even if there'd be a new lady with the same name, the console commands would just move her traits a bit up - and these few Charm doesn't matter for the gameplay. The fact that the other, the new princess has no traits is not a problem either - it actually simulates that the new lady at the court may have also Charm 0. It's a seventh kind of the ladies, fair play.
    More importandly, over those 40 turns the player would marry off his own princess, especially if she would have good traits (high Charm). So there's tiny probability that she still exists, and it's almost improbable that a high-Charm lady exists (unless the player doesn't care, but if he doesn't care, why these new traits would be a problem for him?). The AI would do it as well, maybe not so universally but still. However, this is not a problem either - in this script we bother about experience of a player, not the AI (does it have one?). Meeting a high-charm AI princess that would double with second similar spawn is very unlikely (I'd say a fraction of 1%?). And even if it happens it's even good for the game - how many times we've seen situations of elderly (>40) women with high charm? I can name a few Polish kings who would marry such elder, inferitile women.
    Lastly, I always try to economise on the script. What you proposes is not very time consuming for the processor (now new monitors, just some additional if clauses, still multiplied by 30 factions and 6 kinds of princesses) but with no benefit.
    Last edited by Jurand of Cracow; May 19, 2020 at 01:17 AM.

  10. #10
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,251

    Default Re: Quick question about too-many spaces in scripting

    That script is missing the commas again.

    Another way to give the traits...

    Create a hidden trait named "IsNotANewlySpawnedPrincess".

    Add a trigger...

    Code:
    ;------------------------------------------
    Trigger SpawnedPrincess_trigger1
        WhenToTest CharacterTurnStart
    
        Condition AgentType = princess
              and FactionType spain
              and Trait IsNotANewlySpawnedPrincess = 0
              
        Affects IAmPrincess 2 Chance 100
        Affects Princess_Royal_Blood_Spanish 1 Chance 100
        Affects PrettyWoman 1 Chance 80
        ... other traits ...
        Affects IsNotANewlySpawnedPrincess 1 Chance 100
    Newly spawned spain princesses won't have the IsNotANewlySpawnedPrincess trait so that will fire on them. And only fire once because it gives them the IsNotANewlySpawnedPrincess trait.

    If the spawn happens in PreFactionTurnStart then they'll get the traits in the same turn as the spawn.

    To prevent it from firing on non-spawned spain princesses, another trigger...

    Code:
    ;------------------------------------------
    Trigger SpawnedPrincess_trigger2
        WhenToTest CharacterComesOfAge
    
        Condition AgentType = princess
              and FactionType spain
    
        Affects IsNotANewlySpawnedPrincess 1  Chance  100
    However, the first monitor will also fire on any of-age spain princesses in descr_strat. You could script-give them the IsNotANewlySpawnedPrincess trait at campaign start (PreFactionTurnStart) to avoid that.

  11. #11
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    3,841

    Default Re: Quick question about too-many spaces in scripting

    Quote Originally Posted by Withwnar View Post
    That script is missing the commas again.
    but surprisingly it works (I've tested it and got Inmaculada ;-) - it seems that the comma is not needed.

    thanks for the codes!


    BTW, from the point of view of optimalization of processing time,

    this formulation of the trigger (with RandomPercent first)

    Code:
    ;------------------------------------------
    Trigger poetry_book_minnensang_JoustingList
     WhenToTest CharacterTurnEndInSettlement
     Condition  RandomPercent > 80   
     and IsGeneral 
     and RemainingMPPercentage > 95 
     and SettlementBuildingExists >= jousting_lists 
     and Trait Intelligent > 5
     and FactionReligion catholic
     and not FactionType spain
     and not FactionType aragon
     and not FactionType portugal
     and not HasAncType PoetryBook
     and Attribute Chivalry > 2
     
    AcquireAncillary bookpoet_minnensang chance 5
    is better than this one?

    Code:
    ;------------------------------------------
    Trigger poetry_book_minnensang_JoustingList
     WhenToTest CharacterTurnEndInSettlement
     Condition IsGeneral 
     and RemainingMPPercentage > 95 
     and SettlementBuildingExists >= jousting_lists 
     and Trait Intelligent > 5
     and FactionReligion catholic
     and not FactionType spain
     and not FactionType aragon
     and not FactionType portugal
     and not HasAncType PoetryBook
     and Attribute Chivalry > 2
     and RandomPercent > 80    
       AcquireAncillary bookpoet_minnensang chance 5
    Last edited by Jurand of Cracow; May 07, 2020 at 06:10 AM.

  12. #12
    bitterhowl's Avatar Centenarius
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    817

    Default Re: Quick question about too-many spaces in scripting

    Quote Originally Posted by nadalio View Post
    I found this on IMTW, maybe could be useful..
    http://imtw.ru/tutorials/article/114...l-2-total-war/

    Spoiler Alert, click show to read: 

    Script Optimization in Medieval 2 Total War


    So, script optimization is mainly needed for speed, so as not to load the processor and OS. Perhaps, in addition to speed, the probability of departures at the same time will decrease. It is useful to know the principle of the program code (I am not a programmer, I do not pretend, I write only what I read in the topic about optimization). The game parses each monitor in stages, checks each condition, and if it is true, then proceeds to the next. The processor time is spent on this, so you need to be able to optimally select the script conditions. An example of how this works.
    Spoiler (expand)monitor_event FactionTurnStart FactionType england
    and FactionBuildingExists >= governor_house
    and FactionIsLocal

    The game checks the conditions step by step, i.e. the beginning of the course of the fraction, checks the type of fraction at the moment of the beginning of the course of each fraction, and if it is England, it goes further. At the same time, checking the condition for the faction of the building “governor's house” in the building takes longer than checking the FactionIsLocal condition, and with the above arrangement of monitors, it turns out that if you are not playing for England, the game takes a long time to check for the presence of the building in the British, and then discovers that this AI fraction and resets the monitor. In this case, it turns out that the processor has performed useless work, spending time idling. That is, in this example, at least FactionIsLocal should be checked before FactionBuildingExists so as not to waste processor time in vain. By this we mean a rational arrangement of conditions.




    Here is an even more illustrative example, with numbers. Let's say 300 characters are on the campaign map, of which 15 are English. For example, you need to check if at the beginning of the course of the English character with a certain unique trait England owns Paris - an event occurs. If another faction owns Paris, then another event. Such a script at the same time

    Spoiler (expand)CharacterTurnStart FactionType england monitor_event
    and Trait xx_trait> 0
    and I_SettlementOwner Paris england ... the desired effect on the FA
    end_monitor

    monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    and I_SettlementOwner Paris france ... the desired effect by France
    end_monitor

    monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    and I_SettlementOwner Paris hre ... desired effect from the Roman Empire
    end_monitor



    Thus, when checking these conditions, the monitor will work 900 times (3 monitors for 300 characters according to the CharacterTurnStart condition), of which 45 monitors (15 characters and 3 monitors) will work for England, then the trait will be tested 45 times, of which 3 will be effective (1 character with a unique trait and 3 monitors), and the accessory of Paris will be checked 3 times.

    But if the script is written like this
    Spoiler (expand)monitor_event CharacterTurnStart FactionType england
    and Trait xx_trait> 0
    if I_SettlementOwner Paris england ... desired effect from England
    end_if
    if I_SettlementOwner Paris france ... desired effect from France
    end_if
    if I_SettlementOwner Paris hre ... desired effect from the Roman Empire
    end_if
    endmon



    At the same time, the monitor will start 300 times (300 characters on the map for the CharacretTurnStart condition), Trait xx_trait> 0 (15 English characters on the map) will be checked 15 times for England and Paris will be checked 3 times. Altogether, 600 runs of CharacterTurnStart monitor less and 30 trait checks for England less. The processor is busy less than 2/3 while the same thing happens on the card. Considering that there are several thousand or more monitors in the script and more than 300 characters on the map, the numbers of the processor’s “idle” operation with irrational script writing increase by orders of magnitude.

    By the duration of the processor load, the commands are distributed as follows - if <monitor_event <monitor_conditions <while. That is, checking the condition with if takes the least time, then the event is periodically checked, the condition is checked constantly in the background and the processor constantly takes, as well as the while condition check. According to some reports, 70 monitor_conditions reduce the game speed to 1 fps. In any case, the more monitor_conditions and while you have in the script, the more the processor loads and the longer the script takes longer to calculate. In that topic on TVC, there is a mention of the DotS mod that uses the "nesting ifs" technique (as far as I understand, this is a branched tree using the if condition), where campain_script has a capacity of 60 megabytes, million lines of code and at the same time 1 monitor_event and 1 monitor_conditions and slows down only when rebooting, because executes numerous console commands.

    In addition to optimization topics - they write that they try to avoid monitor_conditions, like the plague, they give an example about the 1648 mod - adding / removing one monitor_event monitor containing 250 if checks does not affect game performance in any way. Adding / removing the script "Carl the taxman" (famous economic) containing 600 monitor_event monitors for all fractions in the game - changes productivity by 40 seconds.

    Here. One of the most harmful conditions is CharacterTurnStart / End, because as we now understand, it works for each character on the map, then this engine checks the membership of the fraction (and spends processor time on this too). Further down the load is SettlementTurnStart / End, less harmful, the same is checked for each settlement. Well and then FactionTurnStartEnd. Which alternative? The following operators offer: CharacterSelected (when the player selected the character), Pre / PostBattle (before or after the battle), EventCounter (value of a specific event counter). In theory, these monitors work less often and more targetedly, the load on the processor is reduced.

    Here is another important point from the alpaca tutorial. The loading order for TurnStart and TurnEnd events is as follows: CharacterTurn [Start / End], SettlementTurn [Start / End], FactionTurn [Start / End]. Why is it important? Sometimes there are interconnected monitors in the script, but they do not work as you intended, i.e. the event occurs at best a turn later, or does not occur at all. Then look at the sequence of monitors, perhaps, for example, some counter changes the value you need before checking its value in another monitor you need. Well, and quite general - the game reads all the files from top to bottom, in this sense, the sequence of scripts and especially traits is of great importance.


    Yes, here's another clarification - the order of files that the game checks is always the same, first campaign_script, then export_descr_character_traits, then export_descr_ancillaries.

    Why it matters personally I was convinced by a specific example - the same event, PostBattle, to which I wanted to bind effects in the script and traits, is checked with the above sequence and I had to change the script. I wanted after the battle if the "Wounded" trait appeared, the counter in campaign_script would start spinning. But it turns out that CS checks the PostBattle event first, and at that moment the traits have not yet been checked and assigned and the counter will never work, even if the general is still hurt. Therefore, I had to change the condition in CS to a less profitable CharacterTurnEnd, which is checked more often and loads the processor more, but it is checked when the traits after the battle are already assigned.




    credit to bitterhowl
    Thanks for translation! It's very good. Have to say that it's completely twc stuff, article based on a twc discussion thread.

    My sister, do you still recall
    The blue Hasan and Khalkhin-Gol?

    Because AI is dumb and full of errors.

  13. #13
    nadalio's Avatar Civis
    Join Date
    Apr 2016
    Location
    Where the nameless things gnawing the earth
    Posts
    102

    Default Re: Quick question about too-many spaces in scripting

    Glad could be helpful, do you have the original source? i will put their name also as it's deserve

  14. #14
    bitterhowl's Avatar Centenarius
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    817

    Default Re: Quick question about too-many spaces in scripting

    Quote Originally Posted by nadalio View Post
    Glad could be helpful, do you have the original source? i will put their name also as it's deserve
    http://www.twcenter.net/forums/showt...s-information)
    Persons are still the same )

    My sister, do you still recall
    The blue Hasan and Khalkhin-Gol?

    Because AI is dumb and full of errors.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •