Results 1 to 15 of 15

Thread: The use of 'if' (terminology)?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default The use of 'if' (terminology)?

    I have been struggling with the use of if - is it correct that you can only use conditions that start wit 'I_'? Because somehow the lines below might not work. Any suggestions\clarifications please?

    Example: A faction gets attacked. Various attackers will have various actions.

    Code:
    monitor_event FactionWarDeclared TargetFactionType venice
    
    if 
               factiontype france
               'action1'
    end_if
    
    if 
               factiontype hre
               'action2'
    end_if
    
    end_monitor










  2. #2
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    Yes, that's true. There may be a couple exceptions, such as TrueCondition and RandomPercent, though I haven't tried them.

    The principle is that the monitor doesn't export any of the information it has gathered and supplies to its conditions and send it to any non-connected conditions, such as those in if or while statements. Most I_ conditions supply their own parameters which makes them event independent, whereas other types of conditions will only run on certain events.

    This makes them more versatile, but it narrows down the usages. That's one of the main gripes with the scripting language, is nesting can only be done at a very primitive level compared to the range of commands which require events.
    Last edited by Augustus Lucifer; September 28, 2009 at 03:26 AM.

  3. #3
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: The use of 'if' (terminology)?

    Any idea on how I could script the above? That would give me a guide line for other 'if' scripting.

    Isn't there a tutorial somewhere about this kind of stuff? I read a simple one, but how about an 'intermediate' one?










  4. #4
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    You would need separate monitors to script the above, that's pretty much the long and the short of it. There aren't really any diplomacy I_ commands, so there's not any real event counter workaround to condense the monitors used in that situation. You could possibly use the EDCT to fire 'blank' triggers when certain things it picks up happen, and then use the I_IsTriggerTrue condition in an if statement, but you'd still need triggers for everything you'd be using separate monitors for, so it'd end up with no real loss of event checks.

    I'm not sure what you mean by 'if' scripting as it's more of an occasionally applicable methodology than a replacement for monitors. The above method for instance does not get condensed any by using if statements so the usage of them would be frivolous. Certain other scripts, especially scripts which work in the abstract and use a lot of counters, can utilize 'if' and 'while' statements effectively to cut down on the number of events called. That's more of a design decision than anything else though, I've yet to note any empirical effects of using monitors, it just looks cleaner and may run a bit faster(kind of like refactoring). If every condition could be used in 'if' and 'while' statements it would be different, but the vast majority can't.

    Basically, if some of the conditions you want to differentiate based on have I_ in front of them, you can use 'if' statements to cut down on monitors, multiple times within one another if applicable. If none of the conditions you want to differentiate on have I_ in front of them, every differentiation requires a separate monitor.
    Last edited by Augustus Lucifer; September 28, 2009 at 05:51 AM.

  5. #5
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: The use of 'if' (terminology)?

    Sorry Gigantus, multiple monitors or nothing is all I see... ..If statements don't carry info from the event monitored, so targetfaction would have nothing to work with.
    Last edited by Taiji; September 28, 2009 at 05:59 AM.

  6. #6
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    Quote Originally Posted by Taiji View Post
    Perhaps if you had events for each faction set up to '1' at the start of their turn, then '0' at the end. Then you could have different if statements depending on which faction is currently taking their turn by using the event (I_comparecounter) instead of 'targetfaction' which cannot work due to the limitations of 'if' statements... what do you think AL?
    I'm pretty sure the 'TargetFaction' refers to the faction which war is declared on, so you'd want to use a counter instead of 'faction' as target faction would be the recipient of the declaration who you couldn't track through another event. It's a possibility, if we assume all war declarations occur within the aggressor's turn, which seems logical, then that would be a way of ascertaining the declaring faction and you'd only need one monitor for each potential target faction. You'd essentially need to be thinking about the effects backwards, but it should work.

    Code:
    declare_counter france_turn
    
    monitor_event PreFactionTurnStart FactionType france
    
    set_counter france_turn 1
    
    end_monitor
    
    monitor_event FactionWarDeclared TargetFactionType england
    
    if I_CompareCounter france_turn == 1
     ;do something
    end_if
    
    end_monitor
    
    monitor_event FactionTurnEnd FactionType france
    
    set_counter france_turn 0
    
    end_monitor
    That's one potential mockup. One of the problems with the above is that if he wants to terminate the monitors it would have some funky functionality if it's being considered backwards. It would help to know why the monitors are to be terminated in order to devise a solution for it. Is it trying to track only the first war declaration by each faction for instance? Or something else?
    Last edited by Augustus Lucifer; September 28, 2009 at 06:02 AM.

  7. #7
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: The use of 'if' (terminology)?

    So I take it, that I will basically have to make a monitor for each of the attacking factions. I had planned to have this monitor terminated, one use only. That would leave the others running which I do not want. So I would basically have to work with a counter I guess. Why do things have to be so difficult?










  8. #8
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: The use of 'if' (terminology)?

    I didn't realised you'd replied to that, I worked out that it couldn't work and edited my post. Factionwardeclared would require a targetfaction, it would not be happy with a counter instead.

  9. #9
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    Quote Originally Posted by Taiji View Post
    I didn't realised you'd replied to that, I worked out that it couldn't work and edited my post. Factionwardeclared would require a targetfaction, it would not be happy with a counter instead.
    The above mockup supplies the target faction with the monitor, and the declaring faction in an if statement. So you're essentially checking to see if X faction had war declared on them, and then using counters to surmise who did the declaring based on whose turn it is. It should work, but there's pitfalls.

  10. #10
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: The use of 'if' (terminology)?

    Quote Originally Posted by Augustus Lucifer View Post
    The above mockup supplies the target faction with the monitor, and the declaring faction in an if statement. So you're essentially checking to see if X faction had war declared on them, and then using counters to surmise who did the declaring based on whose turn it is. It should work, but there's pitfalls.
    Looking at it again, I think you're right about me being right

    Only joking, you deserve the credit, nice idea

  11. #11
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: The use of 'if' (terminology)?

    My goal is twofold:
    1. the event in case of war should fire only once
    2. the termination should occur for all factions to make it 'neat' - no unnecessary monitors

    What would be the drawback of those counters? It appears to me a viable solution. And I could use those counters in a different\similar monitor again.










  12. #12
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    Quote Originally Posted by gigantus View Post
    My goal is twofold:
    1. the event in case of war should fire only once
    2. the termination should occur for all factions to make it 'neat' - no unnecessary monitors

    What would be the drawback of those counters? It appears to me a viable solution. And I could use those counters in a different\similar monitor again.
    So you only want the very first war declaration by any faction to throw up an event based on who they're at war with, and then no events besides that one? Or, you only want the event to fire once for each aggressor? Or, you only want the event to fire once for each pairing?

    Those three approaches require different solutions but they can all be solved I'd say. Here's an example of all three methods, the first and last bits apply to all methods. Each method is only an example, they'd need to have *_turn counters and 'if' statements added for every applicable faction, as well as having monitors for each applicable faction to check that war was declared on them.
    Code:
    declare_counter france_turn
    declare_counter england_turn
    declare_counter scotland_turn
    declare_counter milan_turn
    ;etc
    
    ; Set the counters to 1 at the start of the turn, Kingdoms only command, use FactionTurnStart if on M2
    monitor_event PreFactionTurnStart FactionType england
        set_counter england_turn 1
    end_monitor
    
    monitor_event PreFactionTurnStart FactionType france
        set_counter france_turn 1
    end_monitor
    
    monitor_event PreFactionTurnStart FactionType scotland
        set_counter scotland_turn 1
    end_monitor
    
    monitor_event PreFactionTurnStart FactionType milan
        set_counter milan_turn 1
    end_monitor
    
    ;; Method #1
    ;; Use this method if you only want to check the very first
    ;; war declaration of any faction
    
    ; Someone has declared war on Milan
    monitor_event FactionWarDeclared TargetFactionType milan
    
    ; If it's England's turn at the time, we can assume it was them
    if I_CompareCounter england_turn == 1
      and I_EventCounter war_has_been_declared == 0
    ; do something
    end_if
    
    ; If it's France's turn at the time, we can assume it was them
    if I_CompareCounter france_turn == 1
      and I_EventCounter war_has_been_declared == 0
    ; do something
    end_if
    
    ; If it's Scotland's turn at the time, we can assume it was them
    if I_CompareCounter scotland_turn == 1
      and I_EventCounter war_has_been_declared == 0
    ; do something
    end_if
    
    set_event_counter war_has_been_declared 1
    terminate_monitor
    
    end_monitor
    
    ;; End Method #1
    
    ;;Method #2
    ;; Use this method if you want to spawn an event for each
    ;; aggressor only once, based on which faction it's attacking
    
    ;Someone has declared war on Scotland
    monitor_event FactionWarDeclared TargetFactionType scotland
    
    ; If it's France's turn at the time, we can assume it was them
    if I_CompareCounter france_turn == 1
      and I_EventCounter france_declared_a_war == 0
    ; do something
     set_event_counter france_declared_a_war 1
    end_if
    
    ; If it's England's turn at the time, we can assume it was them
    if I_CompareCounter england_turn == 1
      and I_EventCounter england_declared_a_war == 0
    ; do something
     set_event_counter england_declared_a_war 1
    end_if
    
    ; If it's Milan's turn at the time, we can assume it was them
    if I_CompareCounter milan_turn == 1
      and I_EventCounter milan_declared_a_war == 0
    ; do something
     set_event_counter milan_declared_a_war 1
    end_if
    
    if I_EventCounter milan_declared_a_war == 1
      and I_EventCounter england_declared_a_war == 1
      and I_EventCounter france_declared_a_war == 1
      and I_EventCounter milan_declared_a_war == 1
      ;; etc etc for each faction
     terminate_monitor
    end_if
    
    end_monitor
    
    ;; End Method #2
    
    ;; Method #3
    ;; Use this method if you want the event to fire
    ;; once for each war pairing
    
    ;Someone has declared war on England
    monitor_event FactionWarDeclared TargetFactionType england
    
    ; If it's Milan's turn at the time, we can assume it was them
    if I_CompareCounter milan_turn == 1
      and I_EventCounter milan_vs_england == 0
    ; do something
     set_event_counter milan_vs_england 1
    end_if
    
    ; If it's Scotland's turn at the time, we can assume it was them
    if I_CompareCounter scotland_turn == 1
      and I_EventCounter scotland_vs_england == 0
    ; do something
     set_event_counter scotland_vs_england 1
    end_if
    
    ; If it's France's turn at the time, we can assume it was them
    if I_CompareCounter france_turn == 1
      and I_EventCounter france_vs_england == 0
    ; do something
     set_event_counter france_vs_england 1
    end_if
    
    if I_EventCounter france_vs_england == 1
      and I_EventCounter scotland_vs_england == 1
      and I_EventCounter milan_vs_england == 1
      ;;etc etc for each vs. England
     terminate_monitor
    end_if
    
    end_monitor
    
    ;; End Method #3
    
    ;Set the counters back to 0 at the end of the turn
    monitor_event FactionTurnEnd FactionType england
        set_counter england_turn 0
    end_monitor
    
    monitor_event FactionTurnEnd FactionType france
        set_counter france_turn 0
    end_monitor
    
    monitor_event FactionTurnEnd FactionType scotland
        set_counter scotland_turn 0
    end_monitor
    
    monitor_event FactionTurnEnd FactionType milan
        set_counter milan_turn 0
    end_monitor
    You can also kill the *_turn monitors based on the same criteria as whatever it takes to kill the other monitors. For the last method you'd want to use a further event counter set in the terminate_monitor 'if' statements and then check all of those for true.

    Quote Originally Posted by Taiji View Post
    Looking at it again, I think you're right about me being right

    Only joking, you deserve the credit, nice idea
    I probably wouldn't have thought of it actually.
    Last edited by Augustus Lucifer; September 28, 2009 at 05:22 PM.

  13. #13
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: The use of 'if' (terminology)?

    Wicked! I love you guys, at long last someone who knows the deep stuff about scripting. It was actually the first method I was looking for, but I will keep all of the script in my modding library.

    Last question: is it necessary to keep these monitors at the end of the script? I would like to keep them together with their counterparts for 'better housekeeping'.
    monitor_event FactionTurnEnd FactionType france
    set_counter france_turn 0
    end_monitor










  14. #14
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: The use of 'if' (terminology)?

    Quote Originally Posted by gigantus View Post
    Last question: is it necessary to keep these monitors at the end of the script? I would like to keep them together with their counterparts for 'better housekeeping'.
    Not it's not necessary, the script reads top to bottom so in some cases order matters, but with those there's nothing that makes them conflict about order and they run off different events.

  15. #15
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: The use of 'if' (terminology)?

    Thanks for the info.
    And it works like a charm (not the correct movie yet):










Posting Permissions

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