Results 1 to 30 of 33

Thread: Scripting problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Finder of Little Oddities Senior Member Makanyane's Avatar
    Join Date
    Jan 2006
    Posts
    2,220

    Default Re: Scripting problems

    *bumps old thread* - am still trying to sort out possible script induced CTD mentioned in other thread.... in effort to try and simplify things I wondered
    should everything that works as an
    and....
    condition work as an
    if ....
    end_if
    condition?

    have got
    and SettlementBuildingExists > militia_barracks
    which works and detects building present or not correctly but stops event firing if put as
    if SettlementBuildingExists > militia_barracks
    ...
    end_if

    does that show that there is something dodgy about it? Or are there types of things you can't use in 'if'

    EDIT: that also only seems to work if its outside an 'if' as part of basic conditions for event and not as an 'and' inside an if clause. Using SettlementBuildingExists with = has exactly same problem.
    Last edited by Makanyane; 12-18-2007 at 20:33.
    Not used mods before? Looking for something small and fun?!
    Download the:

  2. #2
    Notepad user Member Red Spot's Avatar
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    491

    Default Re: Scripting problems

    In an other scripting-language you'd be absolutelly correct, though in this game as you noticed it doesnt work that way ..

    Rome's scripting-engine doesnt work with variables, so everything that needs a "reference" needs to be in some sort of "export of data" that contains both refrence as any data that you want available to you, or at least the coders once wanted available ..

    In the case of the condition "SettlementBuildingExists" you need the refrence [settlement] and get an "export of data" that is linked to/contains the settlement, the building data, and anything else you have available on the settlement, to get this "export of data" you connect the [setlement] to a command to get the export, in this case likelly the "SettlementTurnStart/End" events.


    G

  3. #3
    Finder of Little Oddities Senior Member Makanyane's Avatar
    Join Date
    Jan 2006
    Posts
    2,220

    Default Re: Scripting problems

    I'd realised a while ago about needing the export from SettlementTurnEnd (had temporarily forgotten - been round in so many circles)

    but same thing applies to that so if its

    Code:
    monitor_event SettlementTurnEnd SettlementName Rajah
       and I_CompareCounter Rajah = 1
       and GarrisonSettlementRatio < 0.8
       and not SettlementBuildingExists > militia_barracks
      if I_SettlementOwner Rajah = vandals
          and I_FactionBesieged vandals
             set_counter Rajah 2
        	 console_command add_money vandals, 1000
             console_command create_unit Rajah "semin" 1
    terminate_monitor
      end_if
    end_monitor
    it works
    Code:
    monitor_event SettlementTurnEnd SettlementName Rajah
       and I_CompareCounter Rajah = 1
       and GarrisonSettlementRatio < 0.8
      if I_SettlementOwner Rajah = vandals
          and not SettlementBuildingExists > militia_barracks
          and I_FactionBesieged vandals
             set_counter Rajah 2
        	 console_command add_money vandals, 1000
             console_command create_unit Rajah "semin" 1
    terminate_monitor
      end_if
    end_monitor
    with building check moved inside 'if' doesn't work - so 'if' statement breaks link to the returned information from the event????

    if that is general principle it might help explain other problems, as I've probably got ifs checking a lot more that they are meant to be, I was trying to reduce monitors by having more things as ifs inside, might not be the way to go!
    Not used mods before? Looking for something small and fun?!
    Download the:

  4. #4

    Default Re: Scripting problems

    'if' statement breaks link to the returned information from the event?
    Yes. The information returned by the event is only used by the conditions of the event (the main condition plus the additional "and" lines).
    With "if" statments you can only use conditions that starts by "I_", because they do not need any reference.

    I agree it seems you win some efficiency in the scripts when you reduce the monitor conditions by using "ifs" instead, because the "if" is only checked when all the other conditions are true.
    However, I guess that the conditions of the monitor are also checked in order, I mean that the 2nd condition should not be checked if the first is already false (this is how they usually work in other programing languages). If this is true, I suggest to place the conditions that are easy to check first, and conditions harder to be checked at the bottom. Although I have not verified it.
    Last edited by Bardo; 12-20-2007 at 01:16.

  5. #5
    Anything that isn't 'member' Member Squid's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    596

    Default Re: Scripting problems

    Not quite, most programing/scripting language make a choice about they want their language to "shortcut" and/or connectors by default, which only evaluate extra conditions if required.

    Take VB for example it doesn't use shortcut connectors if you use a simple OR between condition, you need to use ORELSE in order for it to shortcut the condition after it. Meanwhile c/c++ users are typically taught to use the shortcut && and || by default. So really it may or may not be impelemented as a shortcut connector and unless you check you really don't know.

    -Trait/Ancillary/Building Editor

    "Two things are infinite: the universe and human stupidity;
    and I'm not sure about the universe." -----Albert Einstein

  6. #6
    Finder of Little Oddities Senior Member Makanyane's Avatar
    Join Date
    Jan 2006
    Posts
    2,220

    Default Re: Scripting problems

    thanks for responses

    though Squid, you lost me after first paragraph!

    Re Red Spot's earlier question
    also GarrisonSettlementRatio < 0.8, does that work??
    not so sure it does now, it seemed to be when I first tested it but have gone back to test on a simple end of settlement turn trigger and it now doesn't seem to be doing anything.

    EDIT: think we might be using the wrong bit for that docudemon entry is
    Identifier: GarrisonToPopulationRatio
    Trigger requirements: settlement
    Parameters:
    Sample use: GarrisonSettlementRatio > 0.35
    Description: Calculate the ratio of soldiers to civilians
    Battle or Strat: Strat
    Class: GARRISON_TO_POPULATION_RATIO
    Implemented: Yes
    Author: Guy
    writing it as
    and GarrisonToPopulationRatio < 0.1
    definitely works and goes on straightforward ratio, eg: if population is 5000 that will only trigger if less than 500 men are in the garrison troops.

    .....goes away to re-design script again......

    EDIT 2: just realised; that makes most sorts of calculation useless unless you also set it according to which unit size user is using.
    Last edited by Makanyane; 12-20-2007 at 17:22.
    Not used mods before? Looking for something small and fun?!
    Download the:

  7. #7
    EB Traitor Member BozosLiveHere's Avatar
    Join Date
    Jan 2006
    Location
    Uqbar, Tlön
    Posts
    3,662

    Default Re: Scripting problems

    That's why we have the UnitSize trait and scripts in EB. Check our campaign_script to see how we handle it.

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