Custom scripting gives experienced developers even more power by allowing you to run your own javascript.
By Tiers
Free and Pro-tier developers only have access to in-play scripting. Enterprise customers can run javascript anywhere in their game, including sets, community pages, landing pages, etc.
Getting started with JavaScript
The simplest way to try custom scripting is through the custom javascript action in the effect builder.
All javascript is executed in the context of that action. Custom javascript action can be executed either client side or server side. Server-side execution affects the logic of the game while client-side execution affects the rendering and visuals on the client. Even if your game doesn't have a server, the logic of the game is still considered server-side with a local server.
Examples of custom javascript commands on the server:
console.log(thisCard)
thisCard.variable = {
"foo": "bar"
}
console.log(parseVariable('$variable'))
console.log(dotSyntax('$variable.variable2'))
Included third party libraries
Server side libraries:
- Async
- Lodash
Client side Libraries:
- Async
- Lodash
- jQuery
- three.js
- hammer.js
Server side API
Global Variables
thisMatch
cardsList
Array of all card objects in this game, equivalent to thisMatch.cardsList
Local Variables
thisCard
effectIndex
effects
This line's effects. Equivalent to thisCard.effects[effectIndex]
playerNumber
This card's playerNumber. Equivalent to thisCard.playerNumber
Helper Functions
clientUpdateCard(thisMatch, ciid)
ciid parameter
A number that is a ciid.
otherPlayer(playerNumber)
In games with 2 players, get the playerNumber of the other player. Returns either string "player1"
or "player2"
getIndexFromEffectName(effectName, context)
Returns index as number.
effectName parameter
A string that is the name of the effect. Typically saved by assign variable. Should be in either _effectTriggers
or _effectNames
.
context parameter
Optional. Context object, default thisCard.
runEffectFromAnotherAction(effect, callback)
effect parameter
A string that evaluates to an effectIndex or an array of effectIndexes.
callback parameter
Optional.
runEffect(thisMatch, options, callback)
thisMatch parameter
Specify the match. Should always be "thisMatch".
options parameter
key | description | type |
---|---|---|
ciid | The ciid of the card you're executing. | int |
effectIndex | The index of the effect you're executing on the target card. | int |
callback parameter
Optional.
setStat(thisMatch, newValue, playerProperty, localPlayerNumber)
effectAfterAction()
Proceed to the effect completion.
assignTargetVariable(target, key)
target parameter This assigns the target to the line like the assign variable action. The target may be any number, string, object, function or array of ciids.
key parameter
Optional. Create an additional property on thisCard in the form of effect-${effects.effectName}Key
.
safeEvalInput(string)
Checks to see if there's math that can be done. If there is, do the math and return a number. Otherwise return the string.
dotSyntax(string)
Like parseVariable but works with dot syntax.
stringVariableReplacement(string)
With a string, replace any variables within. Uses dotSyntax. Example:
stringVariableReplacement("This card is called $title. It has an attack power of $atk and a health of $health.")
effectSelectCard(callback)
callback parameter
function (selectedCards)
selectedCards may a string error message, fail cancel
, failed
, or an array of ciids.
dulstError(errorMessage)
Prints a dulst error in the logs. Does not stop the game.
errorMessage parameter
String explaining the error.
thisMatch.getRandom()
Dulst safe random generator. Never use your own random.
Returns float like Math.random()
thisMatch.shuffle(collection)
Dulst safe random shuffler. Never use your own random shuffler.
Returns shuffled collection.
collection parameter
Array to shuffle.
thisMatch.sample(collection, n)
Dulst safe random sampling. Never use your own random sample.
Returns array.
collection parameter
Array of possible choices.
n parameter
Number of elements to return.
Client side API
Platform
ty.dulst.game.attributes
Game attributes.
ty.dulst.endSelectingAnimation()
End the select animation.
In play
mod
This module.
mod.matchID
mod.cardBack
mod.locations
mod.locationsVisible
List of all locations that are visible on screen. This way you instantly know whether or not a card is visible.
mod.locationsHiddenStack
List of all locations hidden stack that needs a cardback shown.
mod.clientPlayerFromNumber(playerNumber)
Return "me" or "opponent".
mod.mousemoveCallbacks
mod.opponentMousemoveCallbacks
Array of functions with the event as the first parameter.
matchData
selectCount
turnPlayer
cardRatio
Play Functions
ty.dulst.playAnimations.position(options)
options parameter
key | description | type |
---|---|---|
positionOffsetX | X offset. | int |
positionOffsetY | Y offset. | int |
positionDirection | One of top, bottom, left, right, center. | string |
cards | Array of ciids for the cards you're positioning. | Array |
relativeTo | The ciid of the card it is positioned relative to. | int |
flashMessage(text, callback)
Show a popup message where the mouse is.
getCard(ciid, cardData)
ciid paramter
String.
cardData paramter
Optional. Object with the card data.
Return the card element as a jQuery element. Create the card based on cardData if it doesn't already exist, replace the card with the supplied cardData if it already does.
cancelChoice()
playVideo(cid)
setStatus(text)
moveCard(cardEl, toLocationName, fromLocationName)
Move a card.
flipCard(cardData)
cardData paramter
Object.
Flip a card.
cardPosition(locationName)
locationName paramter
String.
Reposition all the cards in the location.
safeReplaceCardEl (oldCard, newCard)
oldCard paramter
jQuery element.
newCard paramter
jQuery element.
Change a card by overwriting the attributes of a card element with the attributes of another card element. Unlike getCard()
it is non-destructive, allowing animations to flow smoothly from one state to another.
Getting card properties
All cards have their full card properties attached to their jQuery element, which you can access through $('#c-[cardID]').data('json').