Results 1 to 9 of 9

Thread: My First Script Error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default My First Script Error

    Since the the families/traits section of my mod's been finished, I finally decided to suck it up and try scripting. I thought it would be a nice easter egg in the game if Spartacus and Crixus were to appear on 73 BC, so I looked for some resources and started working.

    I copied and pasted from HouseofHam's background script tutorial as much as possible, so as to not cause an error. When I start up the game, there was, of course, an error. I can't even get to the CTD phase; the game won't load past the copyright information. So yet again, I need to ask help from the powers that be in scripting:

    From export_descr_advice:
    Code:
    ;------------------------------------------
    AdviceThread My_Script_Thread
        GameArea Campaign
    
        Item my_script_Item_1
            Uninhibitable
            Verbosity  0 
            Threshold  1 
            MaxRepeats  0 
            RepeatInterval  1 
            Attitude Normal
            Presentation Default
            Title my_script_Title_1
            On_display scripts\show_me\my_script.txt
            Text my_script_Text_1
    Code:
    ;------------------------------------------
    Trigger my_script_trigger_1
        WhenToTest ButtonPressed
    
        Condition I_ThreadCount My_Script_Thread = 0
        
        AdviceThread My_Script_Thread  1
    
    ;------------------------------------------
    Trigger my_script_trigger_2
        WhenToTest CharacterSelected
    
        Condition I_ThreadCount My_Script_Thread = 0
        
         AdviceThread My_Script_Thread  1
    
    ;------------------------------------------
    Trigger my_script_trigger_3
        WhenToTest SettlementSelected
    
        AdviceThread My_Script_Thread  1
    
    {my_script_Title_1}Background Script
    {my_script_Text_1}Script started.
    I copied and pasted the stuff from Section II involving descr_strat.

    From C:\Program Files\The Creative Assembly\Rome - Total War\data\scripts\show_me\my_script:
    Code:
    script
    
    ; Anything following a semicolon is a comment.
    
    ; Remove the adviser portrait from screen.
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    
    ; Wait for it to go away.
    while I_AdvisorVisible
    end_while
    
    suspend_unscripted_advice true
    
    ; Open the adviser message bubble automatically whenever advance_advice_thread is called.
    ; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
    ; Do NOT mix both methods, though, or the advisor will show and then immediately close before
    ; you get a chance to read the text.
    declare_show_me
    
    ; Very useful for debugging - uncomment to use
    ;console_command toggle_perfect_spy
    
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition
      terminate_script
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; This is where to put your own code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; For example, this will give you 1 gold at the beginning of every turn
    spawn_army
    monitor_event FactionTurnStart FactionType slave
    and I_TurnNumber = 434
    
    if spawn_armyA=0
    
    spawn_army
    faction slave
    character Spartacus, named character, command 5, influence 5, management 3, subterfuge 2, age 38, , x 104, y 67
    unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
    unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
    set_counter spawn_armyA 1
    end_if
    
    
    terminate_monitor
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; End of your code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    
    end_script
    As I've said before, I can't understand scripting at all, so feel free to edit my code and post it how it should be.

  2. #2
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: My First Script Error

    You should start by first following the directions in the tutorial exactly and making sure at least that much works. Then you can add your own code.

    1. These lines should be in text/export_advice.txt, not in export_descr_advice.txt
    Code:
    {my_script_Title_1}Background Script
    {my_script_Text_1}Script started.
    2. The code you added:
    - Scripting stuff during the slave turn is a known source of problems. Better to do it at the beginning of the player turn.
    - You must declare counters before you can use them
    - The proper way to check a counter value is with if I_CompareCounter spawn_armyA = 0 (with spaces!).
    - But, in this case, you don't even need that check. It's not like the same turn could start multiple times for the same faction.
    - The spawn_army command needs to be terminated with the 'end' tag
    - To reduce the probability of getting a "cloning CTD", use console_command kill_character "Spartacus" before you spawn him.
    - Try this:

    Code:
    monitor_event FactionTurnStart FactionIsLocal
              and I_TurnNumber = 434
        console_command kill_character "Spartacus"
        spawn_army
            faction slave
            character Spartacus, named character, command 5, influence 5, management 3, subterfuge 2, age 38, , x 104, y 67
            unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
        end
        terminate_monitor
    end_monitor
    
    Make sure that:
    - Spartacus is a valid name for the slave faction
    - the coordinates are valid (i.e. not a river/river-crossing/sea/dense forest/mountain peak tile).
    - units types are correct

    The command, influence, management, and subterfuge parameters don't do anything in the spawn_army. I suspect they got left behind from an older version of the TW engine. If you want your character to have those qualities, give him some traits instead. For example,
    Code:
            console_command give_trait "Spartacus" GoodCommander 3
    For testing purposes, you could temporarily change the turn number to 1, to make sure the army gets properly spawned after you end turn 0.

    And, last but not least, a suggestion on formatting your code: Use indentation to show nested logic. It will make things 10x easier to read.
    Last edited by HouseOfHam; November 23, 2008 at 03:17 PM.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  3. #3

    Default Re: My First Script Error

    Thank you, your reply was really helpful, could you just explain this part to me?

    - You must declare counters before you can use them
    - The proper way to check a counter value is with if I_CompareCounter spawn_armyA = 0 (with spaces!).
    The advisor portrait pops up and then leaves, so I'm assuming the script is running, but the army doesn't spawn, and this is the only part I didn't understand, so I'm afraid I messed up on this part. Where in the code do I put "if I_CompareCounter spawn_armyA = 0"?

  4. #4

    Default Re: My First Script Error

    Replace "if spawn_armyA=0" with "if I_CompareCounter spawn_armyA = 0".

  5. #5

    Default Re: My First Script Error

    Where do I put it for HouseofHam's suggested replacement code?

    EDIT: show_err is telling me that the game doesn't "recognize token end_monitor" in the script. Any idea what that means and how it might be affecting things?
    Last edited by cfan01; November 25, 2008 at 07:04 PM.

  6. #6
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: My First Script Error

    Code:
    script
    
    ; Anything following a semicolon is a comment.
    
    ; Remove the adviser portrait from screen.
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_up
    
    ; Wait for it to go away.
    while I_AdvisorVisible
    end_while
    
    suspend_unscripted_advice true
    
    ; Open the adviser message bubble automatically whenever advance_advice_thread is called.
    ; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
    ; Do NOT mix both methods, though, or the advisor will show and then immediately close before
    ; you get a chance to read the text.
    declare_show_me
    
    ; Very useful for debugging - uncomment to use
    ;console_command toggle_perfect_spy
    
    ; Handle saved game reloads
    monitor_event GameReloaded TrueCondition
      terminate_script
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; This is where to put your own code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    monitor_event FactionTurnStart FactionIsLocal
              and I_TurnNumber = 434
        console_command kill_character "Spartacus"
        spawn_army
            faction slave
            character Spartacus, named character, command 5, influence 5, management 3, subterfuge 2, age 38, , x 104, y 67
            unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_velite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_samnite_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
            unit roman_mirmillo_gladiator, exp 0 armour 0 weapon_lvl 0
        end
        terminate_monitor
    end_monitor
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; End of your code
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
    while I_TurnNumber < 99999
      suspend_unscripted_advice true
    end_while
    
    end_script
    Declaring a counter is just:

    Code:
    declare_counter counter_name
    The new counter is then automatically initialized to 0.

    But, like I said, you don't need one in this case.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  7. #7

    Default Re: My First Script Error

    Now I get an errorless CTD when at the end of the Rebel turn when the script is supposed to activate.

  8. #8

    Default Re: My First Script Error

    Are all the text entries for the scripts properly defined?

  9. #9
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: My First Script Error

    Thou shall not blame it on the script!
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

Posting Permissions

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