Results 1 to 20 of 20

Thread: Intermediate Guide to Scripting Discussion

  1. #1

    Default Intermediate Guide to Scripting Discussion

    I've posted a sequel to the beginner guide to scripting in the Scriptorium by myself and Myrddraal. If people have any questions coming out of that guide, feel free to ask them here.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  2. #2
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Intermediate Guide to Scripting Discussion

    Good one
    You know that you can use "while TrueCondition" to loop forever?
    You only need to do that thing with the counter if you want an escape condition for the script.

  3. #3
    CeltiberoRamiroI Member Monkwarrior's Avatar
    Join Date
    Apr 2004
    Location
    Salduie/Caesaraugusta/ Sarakusta/Saragossa
    Posts
    828

    Default Re: Intermediate Guide to Scripting Discussion

    Thanks ER. Nice tutorial. I'm waiting for the advanced one.

    I'd like to know something about the compatibility of scripts with patches.

    Does a script for 1.2 work with 1.3?
    I think there are commands available in 1.3 but not in 1.2, so perhaps the opposite is not always possible, but I'm not sure if some of the commands in 1.2 are deactivated in 1.3.

    @alpaca
    Could you please give an example of the use of "while TrueCondition"?
    Thanks in advance.

  4. #4

    Default Re: Intermediate Guide to Scripting Discussion

    Cool idea, alpaca.

    I think, Monkwarrior he just means that adding

    Code:
    while TrueCondition
    end_while
    at the bottom of the script will keep it looping without the need for the loop counter.

    There won't be a single advanced guide as - to be honest - the first two cover the conceptual ground needed to get you started. I've no experience of coding languages aside from RTW so this was the sort of thing I needed to get going.

    From here, we'll start pulling out the scripts used in actual mods and talking people through how they function. The 'Advanced Guide' will be lots and lots of different analyses contributed (hopefully) by many of the community scripters.

    As for patch compatibility - you have to remember that the scripting language was not originally intended to be in RTW - as was only shoe-horned in there at the last minute largely for the purpose of the Prologue. So there were no changes in scripting from 1.0 to 1.2.

    There are a few new scripting things in BI - as you can see by comparing the old and new docudemon files - not sure if they're in 1.3 as well.

    One of the more interesting ones is the Reload event, and potentially using it to bring up an Advisor to prompt the background script. I haven't had a crack at that one yet.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  5. #5
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Intermediate Guide to Scripting Discussion

    Ya that was exactly what I meant ;)
    However, you should theoretically also be able to differentiate different sequential parts of a script (for example PreEvent and AfterEvent parts) by specifying a counter loop like this example:

    Code:
    declare_counter event_triggered
    .
    .
    .
    monitor_event
    set_counter event_triggered 1
    terminate_monitor
    end_monitor
    
    while I_CompareCounter event_triggered = 0
    end_while
    .
    .
    .
    while TrueCondition
    end
    What this does is loop the first part until event_triggered is set to 1, which happens when you reach your desired event, and then starts looping the second part. This struct is what I meant with "escape condition"; if you want to use it, make sure that all your monitors in the first part look like this:
    Code:
    monitor_*
    if I_CompareCounter event_triggered = 0
    ...code...
    end_if
    if not I_CompareCounter event_triggered = 0
    terminate_monitor
    end_if
    end_monitor
    So that they are destroyed when we hit our event.
    I'm not sure whether monitors are pre-loaded when the script starts executing, but if they are, you also need to make the monitors of the second part look like this:
    Code:
    monitor_*
    if I_CompareCounter event_triggered = 1
    ...code...
    end_if
    end_monitor
    Might be useful for some stuff, I don't know ;) I just derived this from my programming skills.
    Last edited by alpaca; 11-17-2005 at 16:44.

  6. #6
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Intermediate Guide to Scripting Discussion

    Woah. I really need to get out of the EB forums more often.


    May I add one piece of information about the condition monitors?

    It is, if you use an I_CompareCounter conditional in a condition monitor and try to modify the counter affecting the monitor from within the same monitor it won't work. E.g.

    Code:
    monitor_conditions I_CompareCounter counter = 1
    set_counter counter 0
    console_command add_money 1
    end_monitor
    won't work. The monitor loop will not end and will add infinite amounts of money once the counter activates the monitor once. This has something to do with monitor (and script) state saving (which shouldn't actually be there), but that goes mostly beyond my knowledge. But, you can do a workaround by using two monitors, both affecting each other's counter, like this:

    Code:
    monitor_conditions I_CompareCounter counter_1 = 1
    console_command add_money 1
    ;and do other stuff
    set_counter counter_2 1
    end_monitor
    
    monitor_conditions I_CompareCounter counter_2 = 1
    set_counter counter_1 0
    end_monitor
    Though, the initial piece of script setting the counter_1 to 1 must also set counter_2 to 0 to prevent the other monitor from disabling the first prematurely.

    Please notify me if I'm rambling, I'm quite tired after a rough week so the post may be somewhat inconsistent, or just poorly laid-out.

  7. #7
    Shaidar Haran Senior Member SAM Site Champion Myrddraal's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    5,752

    Default Re: Intermediate Guide to Scripting Discussion

    very good point The Mark

    alpaca, note that if you don't include terminate_monitor in the first monitor, then the script will wait for the event to be triggered, but that event could be triggered multiple times...

  8. #8
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Intermediate Guide to Scripting Discussion

    I know, that's why they are terminated once the counter becomes non-zero and they are invoked...
    Or did you mean something else?

  9. #9
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Intermediate Guide to Scripting Discussion

    Adding a thing about condition monitors and counters, the I_CompareCounter can be placed in an if just after the monitor. Much neater than using two monitors,a nd much simpler, too. Prolly that's why I didn't think of it earlier.

    Code:
    monitor_conditions condition
    if I_CompareCounter
    stuff
    end_if
    end_monitor

  10. #10
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Default Re: Intermediate Guide to Scripting Discussion

    I am trying to test the value of a character's trait during a turn and I had hoped that the following would work:

    script

    Code:
    console_command give_trait Barrivendos GoodCommander
    
    monitor_conditions not I_CharacterSelected Barrivendos
    and Trait GoodCommander >= 1
    	console_command give_trait Barrivendos GoodAttacker
    terminate_monitor
    end_monitor
    
    end_script
    But it does not Can anyone see what is wrong?

    Barrivendos does get the GoodCommander trait which should have a value of 1. Then the not I_CharacterSelected Barrivendos should put the focus on the character which then allows testing the value of the GoodCommander trait. Or doesn't it work like that?

    Any help would be greatly appreciated!

  11. #11
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Intermediate Guide to Scripting Discussion

    What you need to get the Trait condition work is an exported character_record, and condition monitors don't export values; you'll need an event monitor, and convenient events to do that are far and few between.

  12. #12
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Intermediate Guide to Scripting Discussion

    I don't think it's possible except through CharacterSelected which involves that the player does something and the character is on the map.
    You might also consider using a show_me

  13. #13

    Default Re: Intermediate Guide to Scripting Discussion

    I have a question regarding scripts.

    I'm trying to get a show_me script to run from a background script, but it doesn't seem to be working. This is similar to the Client Kingdoms mod implemented into the TFT mod. The background script works fine and all other functions within it work as intended. Here is the background script section that is supposed to start the show_me script:

    Code:
    monitor_event SettlementTurnStart SettlementName Rome
    	and SettlementIsLocal
    	and Treasury > 5000
    	advance_advice_thread Recruit_Legion_Thread
    end_monitor
    This is just temporary until I can get it working - then I'll tweak the costs and add a RandomPercent. Here is the advice thread it refers to:

    Code:
    AdviceThread Recruit_Legion_Thread
        GameArea Campaign
        
        Item Recruit_Legion
        		Uninhibitable
        		Verbosity  0 
        		Threshold  1  
        		Attitude Normal
        		Presentation Default
        		Title Recruit_Legion_Title
         	Script scripts\show_me\recruit_roman_legion.txt
    		Text Recruit_Legion_Text1
    And yes, I have set up the text. Finally, here is the whole show_me script:

    Code:
    script
    console_command create_unit Rome "roman hastati" 2
    console_command create_unit Rome "roman princeps" 2
    console_command create_unit Rome "roman velite" 2
    console_command create_unit Rome "roman Triarii" 1
    console_command create_unit Rome "roman light cavalry" 1
    console_command add_money -5000
    console_command add_population Rome -1210
    
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_down
    simulate_mouse_click lclick_up
    
    terminate_script
    end_script
    Can anyone see what I'm doing wrong here? I've tried changing it so that the script runs when Rome is selected using I_SettlementSelected SettlementName Rome but no dice...

  14. #14
    CeltiberoRamiroI Member Monkwarrior's Avatar
    Join Date
    Apr 2004
    Location
    Salduie/Caesaraugusta/ Sarakusta/Saragossa
    Posts
    828

    Default Re: Intermediate Guide to Scripting Discussion

    Well, perhaps it's a silly answer, but the first possible mistake is "roman Triarii" instead of "roman triarii".

    The second point is that I cannot see the need for a background script only for this purpose. It would be enough with a normal trigger in export_descr_advice, as in Client Kingdoms mod.

    Third point: Did you try the final script without the authomatic "button pressing"?

    You should include some "mark" just to know where the method is failing.

    Good luck!

  15. #15

    Default Re: Intermediate Guide to Scripting Discussion

    When you say not working, does the advisor come up at all? Do you have entries in text\export_advice for that advice thread?
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  16. #16
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Intermediate Guide to Scripting Discussion

    AFAIK RTW doesn't support multiple scripts running side by side; you'll have to include the event script in the background script in an event_monitor ButtonPressed ButtonPressed advisor_button_of_choice (excluding show_me button - no multiple scripts -> no script running -> no registered click on the button, or something to that effect; this limits the button quite surely to advisor_portrait_button).

  17. #17

    Default Re: Intermediate Guide to Scripting Discussion

    Well, perhaps it's a silly answer, but the first possible mistake is "roman Triarii" instead of "roman triarii".
    Didn't think of that. I'll fix it an give it a go.

    The second point is that I cannot see the need for a background script only for this purpose. It would be enough with a normal trigger in export_descr_advice, as in Client Kingdoms mod.
    Sorry, I didn't make it clear. I'm running a background script for a whole lot of things - such as 4tpy, historical events and such. I wanted to add this as a show_me script from the background script as the background script has the "suspend_unscripted_advice true" line added (otherwise I couldn't stop the script from continuously reloading).

    Third point: Did you try the final script without the authomatic "button pressing"?
    Good point, I'll give it a go if the Triarii typo doesn't fix it.

    You should include some "mark" just to know where the method is failing.
    Not entirely sure what you mean, or how to do it.

    When you say not working, does the advisor come up at all? Do you have entries in text\export_advice for that advice thread?
    Advisor doesn't even come up. Yes, as I said earlier, I have the text set up properly.

    Thanks for the help, guys, I'll give the script another go with a few changes.

    AFAIK RTW doesn't support multiple scripts running side by side; you'll have to include the event script in the background script in an event_monitor ButtonPressed ButtonPressed advisor_button_of_choice (excluding show_me button - no multiple scripts -> no script running -> no registered click on the button, or something to that effect; this limits the button quite surely to advisor_portrait_button).
    Good point, but I could have sworn that the TFT mod made this work...
    Last edited by Cheexsta; 12-07-2005 at 14:52.

  18. #18

    Default Re: Intermediate Guide to Scripting Discussion

    Quote Originally Posted by Cheexsta
    Not entirely sure what you mean, or how to do it.
    He means put something in the background script monitor or the script so you'll be able to see if its even being accessed. The discerning scripter uses the infamous console_command puppify_my_love for the purpose, for example:

    Code:
    monitor_event SettlementTurnStart SettlementName Rome and SettlementIsLocal and Treasury > 5000 console_command puppify_my_love advance_advice_thread Recruit_Legion_Thread end_monitor


    If your faction symbol turns into a puppy when you fulfil those criteria then you at least know that that monitor is being accessed.



    And Mark, I'm pretty sure you can run a show_me script during the campaign script of the Prologue. Guy made a special mention of how difficult it had been to get the two running at the same time.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  19. #19
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Intermediate Guide to Scripting Discussion

    Hmm. I remember Guy stating that RTW didn't support multiple scripts at all, though I could very well be mistaken. Have you tried declare_show_me command, if that'd affect it?

  20. #20

    Default Re: Intermediate Guide to Scripting Discussion

    Solution found! In export_descr_script.txt I put the following trigger:
    Code:
    Trigger 2134_Recruit_Legion_Trigger
        WhenToTest SettlementPanelOpen
        
        Condition I_SettlementSelected Rome
        
        AdviceThread Recruit_Legion_Thread 0
    And in the background script:
    Code:
    monitor_event SettlementPanelOpen Rome
    	and Treasury >= 5000
    	suspend_unscripted_advice false
    end_monitor
    
    monitor_event ButtonPressed advisor_speech_bubble
    	suspend_unscripted_advice true
    end_monitor
    And then finally the Legion Recruitment script:
    Code:
    script
    
    select_ui_element advisor_dismiss_button
    simulate_mouse_click lclick_down
    simulate_mouse_click lclick_up
    
    console_command create_unit Rome "roman hastati" 2
    console_command create_unit Rome "roman princeps" 2
    console_command create_unit Rome "roman velite" 2
    console_command create_unit Rome "roman triarii" 1
    console_command create_unit Rome "roman light cavalry" 1
    console_command add_money -5000
    console_command add_population Rome -1210
    
    terminate_script
    end_script
    So what happens is that if you open the settlement panel for Rome (ie, double-click Rome) while the background script is running, it momentarily disables the "suspend_unscripted_advice" command, allowing seperate show_me scripts to run. Simultaneously, the Legion Recruitment show_me script runs (but only if Rome is selected), and the advisor pops up. Then, when the player clicks on the advisor's face (at least I think that's what advisor_speech_bubble is), the background script re-enables the "suspend_unscripted_advice" command.

    For some reason, this can only be run once per turn, though, but that's no problem. I've only tested it briefly, so there may be some more little problems, but so far so good.

    Now, to get it working with post-Marian Legions as well...
    Last edited by Cheexsta; 12-11-2005 at 13:11.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO