Author Topic: Scripting Order  (Read 11536 times)

0 Members and 1 Guest are viewing this topic.

Offline Solaufein

  • Lord of the Realms
  • Administrator
  • Level 5
  • *****
  • Posts: 5149
  • Karma: +127/-19
  • Gender: Male
  • The night is dark and full of terrors...
    • ICQ Messenger - 251194643
    • Yahoo Instant Messenger - gscott7833
    • View Profile
    • http://teambg.net
Scripting Order
« on: December 14, 2007, 04:48:51 AM »
Is there a certain order to follow in scripting checks before an action is taken? My question deals with the OR and Global. OR goes first or a Global check?

Example

Code: [Select]
IF
      OR(2)
            Dead("me"
            Dead("me2")
     Global("CreateThisCre","GLOBAL",0)
THEN
      RESPONSE #100
      SetGlobal("CreateThisCre","GLOBAL",1)
      CreateCreature("foo",[2915.942],10)
END



My mods:
Dark Horizons
The Undying
Nikita
IWD2 store

Co-contributor:
Dark Side of the Sword Coast BG1 Weidu
Aurils Bane
Encounters
Saerileth
Baldur's Gate - Enhanced Edition beta tester
Baldur's Gate 2 - Enhanced Edition beta tester
Icewind Dale - Enhanced Edition beta tester

Offline Miss Sakaki

  • Level 2
  • **
  • Posts: 660
  • Karma: +0/-0
  • Gender: Female
    • MSN Messenger - hpowellsmith@hotmail.com
    • View Profile
    • http://www.mods.chosenofmystra.net/nathaniel
Re: Scripting Order
« Reply #1 on: December 14, 2007, 05:40:06 AM »
It doesn't matter what order it goes in - it's really down to whatever is easier for you to read and tinker around with.
Would you give a guy a foot massage? If so, maybe you'd like Nathaniel.

What's a little falsehood between friends? The mysteries of The Luxley Family are soon to be unravelled.

Offline Mike1072

  • Newbie
  • *
  • Posts: 12
  • Karma: +2/-0
  • Gender: Male
    • View Profile
Re: Scripting Order
« Reply #2 on: December 14, 2007, 06:32:06 PM »
From a programming standpoint, ordering by the ones that are likeliest to be false will stop things from being needlessly checked.

Offline berelinde

  • Global Moderator
  • Level 3
  • *****
  • Posts: 1011
  • Karma: +102/-31
    • View Profile
Re: Scripting Order
« Reply #3 on: December 15, 2007, 05:39:13 AM »
Mike1072 is absolutely correct, of course, but there is another thing to consider: in order for any OR() block to be evaluated, every line has to be checked. So if you've got OR(8), stick it right before the THEN.

But yeah, putting your key trigger variable, the one most likely to be false right up until the moment the script actually fires, at the top of the list really does make your code more efficient.

There's a catch: in the dream script, putting an AreaType() ahead of the InParty() or !StateCheck("DV",CD_STATE_NOTVALID) will result in a CTD if one of the actors is dead but still in the party. So it isn't a bad idea to put your InParty() and !SC(CDNV) checks ahead of the check variable.