Skip to content

Porting scripts from Warlock 2

Sean Proctor edited this page Jul 27, 2022 · 6 revisions

Warlock 3 has changed some aspects of the Warlock Scripting Language. Most of these changes were to simplify the language or eliminate some unexpected behaviors.

Breaking changes

The biggest incompatible change is the removal of the $ variable prefix for local variables. All variables now share the same namespace and are prefixed with %.

The %() syntax has been removed. This was mainly useful for building a facsimile of arrays. Can be replaced with %{variables[%foo]}

The "instant" keyword has been removed and all commands except "pause", "put", and "move" are instantaneous. This is a minor incompatibility with SF scripts. In practice, you shouldn't notice any negative issues from this. If you do, "wait" and "pause" can be used to work around the issue.

The "action" command has been removed. This was originally added for compatibility with Genie scripts. I'm no longer considering adding compatibility with Genie scripts, and "action" was the largest source of bugs in the old scripting engine. "AddTextListener" has been added to replace some of the functionality that "action" provided. "action" requires threading, and I'm not currently intending to add that to WSL scripts. If you need that functionality, it can be achieved with JS.

The status commands have been removed, which included "getcomponent", "getstatus", "gettime", "gettitle", and "getvital". getcomponent is replaced by %components, getstatus and getvital are replaced by %properties.

The special variables %roundtime, %lhand, %rhand, %spell, and %character have been removed. The values can be found in %properties (rhand is now right, and lhand is now left). The special variables %roomdesc, %roomexits, %roomplayers, and %roomobjects have been removed, their values can now be found in %components. %lastcommand has been removed and does not have a replacement.

Additions

You can now put arbitrary expressions anywhere in your script using %{}. For instance, setVariable sum %{a + b}.

You can now create maps (a mapping of a string to a value). mapadd variableName key value

Porting

Actions

Replace:

setvariable arrived 0
action setvariable arrived 1 when "its crew ties the ferry off"
action setVariable arrived 1 when "pulls up to the dock"
action setVariable arrived 1 when "A great clanging bell"
...
if %arrived = 1 then ...

With:

unsetvar arrived
addTextListenerRe arrived /(its crew ties the ferry off|pulls up to the dock|A great clanging bell)/
...
if exists %arrived then ...

Replace:

action clear

With:

removeTextListener arrived

Replace:

getcomponent appraisal exp Appraisal
if %appraisal contains "lock" then goto idle

With:

if components["exp Appraisal"] contains "lock" then goto idle

Replace:

getvital curHealth health
getvital curMana mana
getstatus isHidden hidden
echo Health: %curHealth
echo Mana: %curMana
if %isHidden then echo You are hidden

With:

echo Health: %{properties["health"]}
echo Mana: %{properties["mana"]}
if properties contains "hidden" then echo You are hidden

Replace:

instant setVariable attempting 1
instant put play lyre
instant pause 5

With:

setVariable attempting 1
send play lyre
delay 5
Clone this wiki locally