This is a documentation for Board Game Arena: play board games online !

ผลต่างระหว่างรุ่นของ "SandboxScripts"

จาก Board Game Arena
ไปยังการนำทาง ไปยังการค้นหา
ไม่มีความย่อการแก้ไข
บรรทัดที่ 15: บรรทัดที่ 15:


With this API, you can get properties values of game elements from the current game situation, modify them and/or trigger the game actions (ex : move this element here, flip this card, and so on).
With this API, you can get properties values of game elements from the current game situation, modify them and/or trigger the game actions (ex : move this element here, flip this card, and so on).


= Sandbox Scripts Hello World =
= Sandbox Scripts Hello World =

รุ่นแก้ไขเมื่อ 10:21, 14 ธันวาคม 2559

This is the reference of functions you can call from your Sandbox scripts.

Javascript

BGA Sandbox scripts are written in Javascript.

Using Javascript, you can write scripts to automate moves for your Sandbox games & provide rules reinforcement.

Important : in the opposite of the most common usage of Javascript, Sandbox scripts are executed on server side.

BGA API

To interact with your BGA Sandbox game, we provide you an API.

With this API, you can get properties values of game elements from the current game situation, modify them and/or trigger the game actions (ex : move this element here, flip this card, and so on).

Sandbox Scripts Hello World

From Sandbox editor "interface view" tab, select an element, and access to its property (top right icon).

Go to "Scripts (advanced)" section.

In front of "When this element is clicked", enter "onMyClick".

Close the window. Go to "script view" tab.

Enter the following :

function onMyClick(id)
   addToBgaLog("Hello world! You just clicked on element "..id..". Congrats!")
end

Save & publish your project, starts a test session, click on the previous element : your message appears in the log on the right!

Functions you can use in your Lua Sandbox scripts

addToBgaLog( txt )

Write something in the BGA log on the right.

This is also a very practical to debug your script ;)

Note : you can also pass an object in parameter. This will dump the content of this object in the log (for debugging purpose).

getElementById( id )=

Get an object with all the properties of the element with specified ID.

Throw an exception if the element does not exists.


getElementIdByName( name )=

Get the ID of a Sandbox element from its name.

Return null if there are no element with this name. Throw an exception if there are more than 1 element with this name.

moveElement( element_id, target_id )

Move element to specified target id.

เข้าถึงจาก "http:///index.php?title=SandboxScripts&oldid=2105"