Jump to content


Photo

Coding scripts in SSL: some lessons


22 replies to this topic

#16 Icendoan

Icendoan

    King of Parsing Errors

  • Modders
  • 1704 posts
  • Gender:Male
  • Location:The hall of 1000 posts!

Posted 20 August 2008 - 11:05 PM

Ah, it is just that 1 and l look very similar.

Icen
Mods in development: Keeping Yoshimo
Posted Image

#17 HerrSvensson

HerrSvensson
  • Members
  • 23 posts
  • Gender:Male

Posted 24 January 2013 - 02:32 PM

Seems very useful.

Why are targets separated in different blocks? Wouldn't it be sufficient to simply add an OR(x)?

Example:
Library definitions:
For example:
TARGET=test
[PC]
SecondNearest([PC])

Action definition:
BEGIN_ACTION_DEFINITION
Name(Spell)
TRIGGER
  HaveSpell(scsargument1)
  !CheckStatGT(scstarget,0,SANCTUARY)
  CheckStatLT(Myself,50,SPELLFAILUREMAGE)
  !CheckStat(scstarget,2,WIZARD_SPELL_TRAP)
ACTION
  RESPONSE #scsprob1
  SetGlobalTimer("castspell","LOCALS",6)
  Spell(scstarget,scsargument1)
END

ssl script:
IF TRIGGER
  TargetBlock(test)
THEN DO
   Action(Spell,WIZARD_FIREBALL)
END

Will compile into:
IF
HaveSpell(WIZARD_FIREBALL)
!CheckStatGT([PC],0,SANCTUARY)
CheckStatLT(Myself,50,SPELLFAILUREMAGE)
!CheckStat([PC],2,WIZARD_SPELL_TRAP)
See([PC])
THEN
RESPONSE #100
SetGlobalTimer("castspell","LOCALS",6)
Spell([PC],WIZARD_FIREBALL)
END
IF
HaveSpell(WIZARD_FIREBALL)
!CheckStatGT(SecondNearest([PC]),0,SANCTUARY)
CheckStatLT(Myself,50,SPELLFAILUREMAGE)
!CheckStat(SecondNearest([PC]),2,WIZARD_SPELL_TRAP)
See(SecondNearest([PC]))
THEN
RESPONSE #100
SetGlobalTimer("castspell","LOCALS",6)
Spell(SecondNearest([PC]),WIZARD_FIREBALL)
END

Is there a way to compile it into the following instead?
IF
HaveSpell(WIZARD_FIREBALL)
OR(2)
See([PC])
See(SecondNearest([PC]))
!CheckStatGT(LastSeenBy(),0,SANCTUARY)
CheckStatLT(Myself,50,SPELLFAILUREMAGE)
!CheckStat(LastSeenBy(),2,WIZARD_SPELL_TRAP)
THEN
RESPONSE #100
SetGlobalTimer("castspell","LOCALS",6)
Spell(LastSeenBy(),WIZARD_FIREBALL)
END

I think the script would then be quicker, or am I wrong about that? Does infinity engine read triggers from bottom and up instead of top to bottom like I assume it does?

Edited by HerrSvensson, 24 January 2013 - 03:51 PM.


#18 DavidW

DavidW
  • Gibberlings
  • 4308 posts
  • Gender:Male

Posted 25 January 2013 - 05:07 AM

They're not equivalent.

Scenario: there are two PCs, one protected by Spell Trap and one not .What the script needs to do is find the nearest PC who is not protected by Spell Trap. The standard SSL-compiled code looks at the nearest PC to see if they're protected. If they aren't, cast at'em. If they are, look at the next PC.

Your code first just finds the nearest PC. If that PC isn't protected, cast at'em. If they are, give up.

#19 HerrSvensson

HerrSvensson
  • Members
  • 23 posts
  • Gender:Male

Posted 25 January 2013 - 09:21 PM

Thanks, you are right.

I don't know a good reason for why you would want to code like I did then, but it's still possible to do in SSL, that's good:
IF TRIGGER
OR(2)
   See([PC])
   See(SecondNearest([PC])
Target(LastSeenBy(Myself))  
THEN DO
Action(Spell, WIZARD_FIREBALL)
END

Edited by HerrSvensson, 26 January 2013 - 04:14 AM.


#20 DavidW

DavidW
  • Gibberlings
  • 4308 posts
  • Gender:Male

Posted 14 February 2017 - 01:23 AM

For the two or three people who use SSL:

The version of SSL that will ship with v31 of SCS has two new features:

1) SSL now recognises a set of "Boolean variables", which can be defined when it's run using the -b tag: e.g.,
 
ssl.exe testscript.ssl -l ssl/library.slb -o stratagems_external/workspace/ssl_out -b WIZARD_MAGIC_MISSILE WIZARD_FLAME_ARROW 
sets Booleans WIZARD_MAGIC_MISSILE and WIZARD_FLAME_ARROW.

Booleans are referenced in SSL scripts via

SSLBoolean(firstBoolean|secondBoolean|etc)

which will blank the script unless at least one Boolean is set.

The point of this (over and above SSL's existing variables) is that Booleans are evaluated right before a given block is printed (whereas standard SSL variables are evaluated pretty much at the start). So in particular, SSL action arguments can be placed in an SSLBoolean command.

Example:
 
BEGIN_ACTION_DEFINITION
Name(Spell)
TRIGGER
SSLBoolean(scsargument1)
HaveSpell(scsargument1)
ACTION
RESPONSE #scsprob1
Spell(scstarget,scsargument1)
END

IF TRIGGER
Target(NearestEnemyOf(Myself))
THEN DO
Action(Spell,WIZARD_MAGIC_MISSILE)
Action(Spell,WIZARD_CHROMATIC_ORB)
compiles to
 
IF
      See(NearestEnemyOf(Myself))
      HaveSpell(WIZARD_MAGIC_MISSILE)
THEN
RESPONSE #100
Spell(NearestEnemyOf(Myself),WIZARD_MAGIC_MISSILE)
END
i.e the CHROMATIC_ORB block is skipped.

Edited by DavidW, 14 February 2017 - 01:23 AM.


#21 DavidW

DavidW
  • Gibberlings
  • 4308 posts
  • Gender:Male

Posted 14 February 2017 - 01:27 AM

2) SSL library files now have two more options, alongside the existing TRIGGER and TARGET: TRIGGER_REPLACE and TARGET_REPLACE. These define triggers and targets (respectively) that destructively overwrite the existing trigger/target (the SSL default is to add to the existing one).

So:

TRIGGER=Imprisonment
!CheckSpellState(scstarget,STATE_ENRAGED)
TRIGGER=Imprisonment
!CheckSpellState(scstarget,IMMUNE_TO_EVERYTHING)
leaves the STATE_ENRAGED check in place, whereas

TRIGGER=Imprisonment
!CheckSpellState(scstarget,STATE_ENRAGED)
TRIGGER_REPLACE=Imprisonment
!CheckSpellState(scstarget,IMMUNE_TO_EVERYTHING)
removes the STATE_ENRAGED check.

Obviously this makes the order of libraries fairly crucial. (The point of the functionality is to make it easier to use custom library entries, e.g. for Spell Revisions compatibility.)

#22 kreso

kreso
  • Modders
  • 2535 posts
  • Gender:Male
  • Location:Istra, Croatia

Posted 15 February 2017 - 03:53 AM

Fantastic.

 

On a sidenote, and unrelated to above - I couldn't get the custom library file to work in v30. I only tried it two times; but it didn't work. The lib file shipped with SCS always got processed instead of a custom one (I edited .ini file to set a custom lib).



#23 DavidW

DavidW
  • Gibberlings
  • 4308 posts
  • Gender:Male

Posted 15 February 2017 - 07:51 AM

Known bug (known from your own report earlier), fixed in v31.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users