Results 1 to 6 of 6

Thread: When to use wait and campaign_wait

  1. #1

    Icon5 When to use wait and campaign_wait

    Hello guys, I have seen wait and campaign_wait used in a lot of scripts, but I have trouble understanding the difference between both and when they are needed.

    What I understand:
    - wait works both on campaign and battle map
    - it allows for some events to fully take place before going further in the script : capturing/giving a settlement, death of a leader...

    Is there a detailed explanation somewhere I missed, or could please experienced scripters share their knowledge?

    I'm also wondering if it is good practice to use wait command extensively to let the events take place "quiletly"?

    For instance I want to reduce a building level on certain event, like this. Is the wait command at the end necessary, or just as a precaution maybe?
    Code:
                if I_CompareCounter player_treasury = 6000                ; to promote frugal players, they already have their problems
                    and I_EventCounter DifficultyLevel > 2                ; this one for M, H and VH difficulties
                    and RandomPercent < 40                                ; 1 great fire in 50 years (plus cool-off 20 years)
                
                    console_command set_building_health Speyer wonder_speyer_cathedral4 80
                    historic_event KAISERDOM_ZU_SPEYER_FIRE_GREAT
                    set_counter kaiserdom_zu_speyer_counter 40
                end_if
    
                if I_CompareCounter player_treasury = 5000                ; to promote frugal players, they already have their problems
                    and I_EventCounter DifficultyLevel > 3                ; this one only for VH difficulty
                    and RandomPercent < 10                                ; 1 destructive fire in 200 years (plus cool-off 20 years)
            
                    destroy_buildings venice wonder_speyer_cathedral4 false
                    destroy_buildings pisa wonder_speyer_cathedral4 false
                    destroy_buildings sicily wonder_speyer_cathedral4 false
                    destroy_buildings abbasid wonder_speyer_cathedral4 false
                    destroy_buildings denmark wonder_speyer_cathedral4 false
                    destroy_buildings egypt wonder_speyer_cathedral4 false
                    destroy_buildings scotland wonder_speyer_cathedral4 false
                    destroy_buildings cumans wonder_speyer_cathedral4 false
                    destroy_buildings turks wonder_speyer_cathedral4 false
                    destroy_buildings rum wonder_speyer_cathedral4 false
                    destroy_buildings france wonder_speyer_cathedral4 false
                    destroy_buildings hre wonder_speyer_cathedral4 false
                    destroy_buildings england wonder_speyer_cathedral4 false
                    destroy_buildings portugal wonder_speyer_cathedral4 false
                    destroy_buildings poland wonder_speyer_cathedral4 false
                    destroy_buildings byzantium wonder_speyer_cathedral4 false
                    destroy_buildings moors wonder_speyer_cathedral4 false
                    destroy_buildings russia wonder_speyer_cathedral4 false
                    destroy_buildings spain wonder_speyer_cathedral4 false
                    destroy_buildings hungary wonder_speyer_cathedral4 false
                    destroy_buildings aragon wonder_speyer_cathedral4 false
                    destroy_buildings lithuania wonder_speyer_cathedral4 false
                    destroy_buildings kievan_rus wonder_speyer_cathedral4 false
                    destroy_buildings norway wonder_speyer_cathedral4 false
                    destroy_buildings jerusalem wonder_speyer_cathedral4 false
                    destroy_buildings zengid wonder_speyer_cathedral4 false
                    destroy_buildings papal_states wonder_speyer_cathedral4 false
                    destroy_buildings mongols wonder_speyer_cathedral4 false
                    destroy_buildings serbia wonder_speyer_cathedral4 false
                    destroy_buildings georgia wonder_speyer_cathedral4 false
    
                    historic_event KAISERDOM_ZU_SPEYER_FIRE_DESCTRUCTION
                    set_counter kaiserdom_zu_speyer_counter 40
                    
                    wait 0.1 
                    console_command create_building Speyer wonder_speyer_cathedral1    ; or wonder_speyer_cathedral2? --- Belovèse
                end_if
    Thanks and cheers!
    Belovèse's Toolbox: export text files to spreadsheet, detailed unit stats
    Stainless Steel Historical Improvement Project (SSHIP) team member.
    Mini-mods: diplomacy and relation/reputation - detailled unit stats

  2. #2
    Gigantus's Avatar You should always listen to your inner voice! - Agreed, but which one?
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    50,001
    Blog Entries
    28

    Default Re: When to use wait and campaign_wait

    If in doubt use wait

    Especially when a command depends on the previous command to have been fully executed. Afaik 'campaign_wait' delays any pending actions on the map while the script continues to process, while 'wait' is the other way round, eg pausing the further processing of the script to allow actions (script and map) to 'catch up'.




  3. #3

    Default Re: When to use wait and campaign_wait

    Thanks, so in the example above do you think it is needed? Before destroying a building line and rebuilding a lower level of the same line I mean.

    About campaign_wait delaying action on the campaign map, I've got a question: can the game crash because of too much delay between the campaign map displayed and the scripts beeing run? Because sometimes our log indicates that it is one or two factions ahead of what is shows in the end turn by the faction symbols on the top of the screen. And we a just on wait and no campaign_wait on the SSHIP script.

    I think it would be interesting to make this thread into a list of the cases when using wait, campaign_wait or battle_wait is highly recommended or plainly needed, it would help a lot beginners like me.
    Belovèse's Toolbox: export text files to spreadsheet, detailed unit stats
    Stainless Steel Historical Improvement Project (SSHIP) team member.
    Mini-mods: diplomacy and relation/reputation - detailled unit stats

  4. #4

    Default Re: When to use wait and campaign_wait

    Neither wait nor campaign_wait will pause script execution. They merely stop execution on the 'local thread', if you will. I'm not exactly sure how many threads the game can execute in parallel, but it's a lot. Consider this example:

    Code:
    monitor_event PreFactionTurnStart
       campaign_wait 0.1
       set_event_counter test_counter 1
    end_monitor
    
    monitor_event FactionTurnStart
       if I_EventCounter test_counter == 1
          historic_event test_event
       end_if
    end_monitor
    The test_event will not fire because the FactionTurnStart event is triggered less than 0.1 seconds after the PreFactionTurnStart event (from my tests, it's actually less than 0.001 seconds in isolated conditions). The campaign_wait pauses execution of the thread in the PreFactionTurnStart monitor, but it doesn't pause anything else in the script. Replacing campaign_wait with wait does not change the results. In fact, I can't see any difference between wait and campaign_wait and the Docudemons says they're the same. Removing the wait/campaign_wait in the script above makes the test_event fire.

    So, the main concern with using wait/campaign_wait is "de-synchronizing" effects in different monitors. Fortunately, we can address this using the 'while' loop. In the example script above, we could say:

    Code:
    monitor_event PreFactionTurnStart
       set_event_counter setting_up 1
    
       campaign_wait 0.1
       set_event_counter test_counter 1
    
       set_event_counter setting_up 0   ;release processes that need to wait for setup to finish
    end_monitor
    
    monitor_event FactionTurnStart
       while I_EventCounter setting_up == 1   ;wait for the effects of the PreFactionTurnStart monitor to finish
       end_while
    
       if I_EventCounter test_counter == 1
          historic_event test_event
       end_if
    end_monitor
    'while' appears to the have the same effect in script as wait and campaign_wait, which limits the appropriate uses of wait and campaign_wait to only a handful of very specific scenarios (such as waiting for a non-identifiable character to finish their death animation).

    Quote Originally Posted by Gigantus
    Afaik 'campaign_wait' delays any pending actions on the map
    What are these "pending actions"? If you test fire campaign_wait or wait 10 (10 seconds), there is no noticeable effect on the strat map. It doesn't prevent characters from completing their actions, pause audio events, disable the UI, or anything else that I can tell.

    P.S. It's quite possible that wait and campaign_wait have different effects on the battle map, I only have experience on the strat map.
    Last edited by Callistonian; April 18, 2021 at 07:23 PM.

  5. #5

    Default Re: When to use wait and campaign_wait

    Quote Originally Posted by Callistonian View Post
    P.S. It's quite possible that wait and campaign_wait have different effects on the battle map, I only have experience on the strat map.
    There is a battle_wait. wait works on both battle and strat map, but if you use campaign_wait in battle, the effect will be delayed. Thus if you do something like this:
    Code:
    monitor_event BattleConflictPhaseCommenced FactionIsLocal
        campaign_wait 5
        historic_event test
    end_monitor
    Then nothing will happen in battle, but once back on the strat map, the historic_event will fire after 5 sec, independently of the duration of the battle.

    Also, if you use wait 30 for example and end the battle after 10 sec, the message will not appear on the strat map after 20 or even 30 sec. In brief, wait seems to behave depending on the situation, but then not differently of campaign_wait or battle_wait.

  6. #6

    Default Re: When to use wait and campaign_wait

    @Erken - So, you're issuing the campaign_wait command on the battle map, and it's being added to the execution order for the strat map. Seems like the same is happening with the historic_event - these are both strat map only commands.

Posting Permissions

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