https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&feed=atom&action=historyAPI:Guide d'utilisation (Français) - Revision history2024-03-28T23:38:28ZRevision history for this page on the wikiMediaWiki 1.20.3https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&diff=4112&oldid=prev235259: 235259 moved page API : Guide d'utilisation to API:Guide d'utilisation (Français)2014-12-29T22:33:57Z<p>235259 moved page <a href="/API_:_Guide_d%27utilisation" class="mw-redirect" title="API : Guide d'utilisation">API : Guide d'utilisation</a> to <a href="/API:Guide_d%27utilisation_(Fran%C3%A7ais)" title="API:Guide d'utilisation (Français)">API:Guide d'utilisation (Français)</a></p>
<table class='diff diff-contentalign-left'>
<tr style='vertical-align: top;'>
<td colspan='1' style="background-color: white; color:black;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black;">Revision as of 22:33, 29 December 2014</td>
</tr></table>235259https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&diff=4111&oldid=prev235259 at 22:33, 29 December 20142014-12-29T22:33:36Z<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 22:33, 29 December 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 74:</td>
<td colspan="2" class="diff-lineno">Line 74:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>[[Category:API|<del class="diffchange diffchange-inline">Use </del>Guide]]</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>[[Category:API|Guide <ins class="diffchange diffchange-inline">d'utilisation]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">[[Category:Language-FR|Guide d'utilisation</ins>]]</div></td></tr>
</table>235259https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&diff=3261&oldid=prev567895: /* Proactive Scripts: Do Things Without User Intervention */2014-08-19T07:02:01Z<p><span dir="auto"><span class="autocomment">Proactive Scripts: Do Things Without User Intervention</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 07:02, 19 August 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 49:</td>
<td colspan="2" class="diff-lineno">Line 49:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Utiliser les fonctions utilitaires est toujours une bonne idée car elles permettent de s'adapter aux modifications apportées aux paramètres de la page ou à une modification sur un jeton.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Utiliser les fonctions utilitaires est toujours une bonne idée car elles permettent de s'adapter aux modifications apportées aux paramètres de la page ou à une modification sur un jeton.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>==<del class="diffchange diffchange-inline">Proactive </del>Scripts: <del class="diffchange diffchange-inline">Do Things Without User Intervention</del>==</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>== Scripts <ins class="diffchange diffchange-inline">proactifs </ins>: <ins class="diffchange diffchange-inline">exécutez des actions sans intervention de l'utilisateur </ins>==</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">In addition to reacting to user events, you can also do things with the API automatically that aren't tied to a specific event from the players. For example, let's have a token that patrols back and forth on the map.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>''Note'': <del class="diffchange diffchange-inline">Although this </del>type <del class="diffchange diffchange-inline">of </del>script <del class="diffchange diffchange-inline">is not dependent on user interaction</del>, <del class="diffchange diffchange-inline">the API </del>scripts <del class="diffchange diffchange-inline">for your campaign will still only run when at least one person is connected to your campaign</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">En plus de réagir aux événements créés par l'utilisateur, vous pouvez également réaliser des actions automatiques qui ne sont pas liées à un événement produit par les joueurs avec l'API. Par exemple, prenons un jeton qui patrouille d'avant en arrière sur une carte.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>''Note'': <ins class="diffchange diffchange-inline">Même si ce </ins>type <ins class="diffchange diffchange-inline">de </ins>script <ins class="diffchange diffchange-inline">est indépendant des actions utilisateur</ins>, <ins class="diffchange diffchange-inline">les </ins>scripts <ins class="diffchange diffchange-inline">de votre campagne ne seront actifs que lorsqu'au moins une personne sera connectée à votre campagne</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><pre data-language="javascript"></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><pre data-language="javascript"></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>on("ready", function() {</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>on("ready", function() {</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   //<del class="diffchange diffchange-inline">Wait until the </del>ready <del class="diffchange diffchange-inline">event fires so we know the campaign is completely loaded</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   //<ins class="diffchange diffchange-inline">Attend que l'événement "</ins>ready<ins class="diffchange diffchange-inline">" soit reçu, nous saurons alors que la campagne est complètement chargée</ins>.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   //<del class="diffchange diffchange-inline">Get a reference to our patrolling token</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   // <ins class="diffchange diffchange-inline">Récupère la référence de notre jeton patrouilleur</ins>.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   var <del class="diffchange diffchange-inline">patroltoken </del>= findObjs({_type: "graphic", name: "Guard A"})[0]; //<del class="diffchange diffchange-inline">We know there is a token in the Campaign called </del>"<del class="diffchange diffchange-inline">Guard </del>A".</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   var <ins class="diffchange diffchange-inline">jetonPatrouilleur </ins>= findObjs({_type: "graphic", name: "Guard A"})[0]; //<ins class="diffchange diffchange-inline">Nous savons qu'il existe un jeton dans notre campagne nomme </ins>"<ins class="diffchange diffchange-inline">Garde </ins>A".</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   var direction = -70; //<del class="diffchange diffchange-inline">Walk left </del>70 pixels<del class="diffchange diffchange-inline">.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   var direction = -70; //<ins class="diffchange diffchange-inline">On le déplace de </ins>70 pixels <ins class="diffchange diffchange-inline">à gauche</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   var <del class="diffchange diffchange-inline">stepstaken </del>= 0; //<del class="diffchange diffchange-inline">How many steps have we walked in the current </del>direction?</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   var <ins class="diffchange diffchange-inline">nombrePas </ins>= 0; //<ins class="diffchange diffchange-inline">Combien de pas avons-nous fait dans la </ins>direction <ins class="diffchange diffchange-inline">actuelle </ins>?</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   setInterval(function() {</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   setInterval(function() {</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>     if(<del class="diffchange diffchange-inline">stepstaken </del>> 3) {</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>     if(<ins class="diffchange diffchange-inline">nombrePas </ins>> 3) {</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>       //<del class="diffchange diffchange-inline">Switch directions</del>!</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>       //<ins class="diffchange diffchange-inline">On change de direction </ins>!</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>       direction = direction * -1; //<del class="diffchange diffchange-inline">will "flip" the </del>direction <del class="diffchange diffchange-inline">we're walking</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>       direction = direction * -1; //<ins class="diffchange diffchange-inline">On inverse la </ins>direction <ins class="diffchange diffchange-inline">dans laquelle nous marchons</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>       <del class="diffchange diffchange-inline">stepstaken </del>= 0; //<del class="diffchange diffchange-inline">reset steps back to 0</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>       <ins class="diffchange diffchange-inline">nombrePas </ins>= 0; //<ins class="diffchange diffchange-inline">Et on réinitialise le nombre de pas</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>     }</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>     }</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>     <del class="diffchange diffchange-inline">patroltoken</del>.set("left", <del class="diffchange diffchange-inline">patroltoken</del>.get("left") + direction); //<del class="diffchange diffchange-inline">walk</del>!</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>     <ins class="diffchange diffchange-inline">jetonPatrouilleur</ins>.set("left", <ins class="diffchange diffchange-inline">jetonPatrouilleur</ins>.get("left") + direction); //<ins class="diffchange diffchange-inline">Marchons </ins>!</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>     <del class="diffchange diffchange-inline">stepstaken</del>++;</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>     <ins class="diffchange diffchange-inline">nombrePas</ins>++;</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   }, 5000); //<del class="diffchange diffchange-inline">take an </del>action <del class="diffchange diffchange-inline">every 5 seconds</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   }, 5000); //<ins class="diffchange diffchange-inline">L'</ins>action <ins class="diffchange diffchange-inline">se déroule toutes les cinq secondes.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>});</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>});</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>[[Category:API|Use Guide]]</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>[[Category:API|Use Guide]]</div></td></tr>
</table>567895https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&diff=3260&oldid=prev567895: /* A Note on Utility Functions */2014-08-19T06:52:11Z<p><span dir="auto"><span class="autocomment">A Note on Utility Functions</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 06:52, 19 August 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 33:</td>
<td colspan="2" class="diff-lineno">Line 33:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Note importante :''' Vous devez utiliser les méthodes <code>set</code> et <code>get</code> pour modifier et récupérer les valeurs actuelles des objets ou vos changements ne seront pas enregistrés. (Voir ci-dessous pour une liste des types d'objets et leurs attributs, ainsi qu'une liste de tous les événements et quels arguments attend chaque événement.)</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>'''Note importante :''' Vous devez utiliser les méthodes <code>set</code> et <code>get</code> pour modifier et récupérer les valeurs actuelles des objets ou vos changements ne seront pas enregistrés. (Voir ci-dessous pour une liste des types d'objets et leurs attributs, ainsi qu'une liste de tous les événements et quels arguments attend chaque événement.)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>=== <del class="diffchange diffchange-inline">A </del>Note <del class="diffchange diffchange-inline">on Utility Functions </del>===</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>=== Note <ins class="diffchange diffchange-inline">sur les fonctions utilitaires </ins>===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Of course</del>, <del class="diffchange diffchange-inline">the previous example isn</del>'<del class="diffchange diffchange-inline">t incredibly helpful because it always adds 70 pixels to the location of the token</del>. <del class="diffchange diffchange-inline">But what if the user has changed their scale so that 5ft is </del>140 pixels? <del class="diffchange diffchange-inline">The Roll20 </del>API <del class="diffchange diffchange-inline">provides several handy utility functions to help with this (and other) common scenarios</del>. <del class="diffchange diffchange-inline">Let's modify our previous example to use the </del><code><del class="diffchange diffchange-inline">distanceToPixelsfunction</del></code><del class="diffchange diffchange-inline">, which will tell us how many </del>pixels "<del class="diffchange diffchange-inline">five feet</del>" (<del class="diffchange diffchange-inline">or inches</del>, <del class="diffchange diffchange-inline">or meters</del>, <del class="diffchange diffchange-inline">or whatever other </del>distance <del class="diffchange diffchange-inline">type has been set</del>) <del class="diffchange diffchange-inline">on the tabletop is</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Bien sûr</ins>, <ins class="diffchange diffchange-inline">l</ins>'<ins class="diffchange diffchange-inline">exemple précédent n'est pas très pratique car il déplace tout le temps le jeton de 70px</ins>. <ins class="diffchange diffchange-inline">Mais que se passerait-il si l'utilisateur changeait l'échelle de sa carte pour que cinq pieds fassent </ins>140 pixels ? <ins class="diffchange diffchange-inline">L'</ins>API <ins class="diffchange diffchange-inline">Roll20 fournit plusieurs fonctions utilitaires pratiques pour aider à résoudre ce type de scénarios</ins>. <ins class="diffchange diffchange-inline">Modifions notre exemple précédent en utilisant la fonction </ins><code><ins class="diffchange diffchange-inline">distanceToPixels()</ins></code> <ins class="diffchange diffchange-inline">qui nous dira combien de </ins>pixels <ins class="diffchange diffchange-inline">représentent </ins>"<ins class="diffchange diffchange-inline">cinq pieds</ins>" (<ins class="diffchange diffchange-inline">ou pouces</ins>, <ins class="diffchange diffchange-inline">mètres</ins>, <ins class="diffchange diffchange-inline">ou n'importe quel unité de </ins>distance <ins class="diffchange diffchange-inline">qui a été précisée dans les paramètres de la page</ins>) <ins class="diffchange diffchange-inline">sur la table de jeu</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><pre data-language="javascript"></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div><pre data-language="javascript"></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>on("change:graphic", function(obj) { <del class="diffchange diffchange-inline">  </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>on("change:graphic", function(obj) {</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>   obj.set({ <del class="diffchange diffchange-inline">      </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>   obj.set({</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>     left: obj.get("left") + distanceToPixels(5); <del class="diffchange diffchange-inline">  </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>     left: obj.get("left") + distanceToPixels(5);</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   });</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>   });</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>}</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div></pre></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Now if the current </del>page <del class="diffchange diffchange-inline">is setup to use the default grid sizing</del>, <code>distanceToPixels(5)<del class="diffchange diffchange-inline">;</del></code> <del class="diffchange diffchange-inline">will still return </del>70 pixels, <del class="diffchange diffchange-inline">but if the </del>page <del class="diffchange diffchange-inline">is setup to have </del>a <del class="diffchange diffchange-inline">scale twice the size of normal</del>, <del class="diffchange diffchange-inline">it would return </del>140.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Désormais, si la </ins>page <ins class="diffchange diffchange-inline">courante est paramétrée avec la taille de grille par défaut</ins>, <code>distanceToPixels(5)</code> <ins class="diffchange diffchange-inline">renverra bien <code></ins>70<ins class="diffchange diffchange-inline"></code> </ins>pixels, <ins class="diffchange diffchange-inline">mais si l'échelle de la grille de la </ins>page a <ins class="diffchange diffchange-inline">été doublée</ins>, <ins class="diffchange diffchange-inline">elle renverra <code></ins>140<ins class="diffchange diffchange-inline"></code> pixels</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">It'</del>s <del class="diffchange diffchange-inline">always a good idea to use utility functions whenever they</del>'<del class="diffchange diffchange-inline">re available to help keep your script from breaking if the settings of a </del>page <del class="diffchange diffchange-inline">or a token change</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Utiliser les fonctions utilitaires est toujours une bonne idée car elles permettent de </ins>s'<ins class="diffchange diffchange-inline">adapter aux modifications apportées aux paramètres de la </ins>page <ins class="diffchange diffchange-inline">ou à une modification sur un jeton</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==Proactive Scripts: Do Things Without User Intervention==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>==Proactive Scripts: Do Things Without User Intervention==</div></td></tr>
</table>567895https://wiki.roll20.net/index.php?title=API:Guide_d%27utilisation_(Fran%C3%A7ais)&diff=3258&oldid=prev567895: Created page with "{{apibox}} == L'éditeur de scripts == Pour éditer les scripts de votre campagne, cliquez sur le lien "API Scripts" dans la page de détails de la campagne (le même endroi..."2014-08-18T18:41:01Z<p>Created page with "{{apibox}} == L'éditeur de scripts == Pour éditer les scripts de votre campagne, cliquez sur le lien "API Scripts" dans la page de détails de la campagne (le même endroi..."</p>
<p><b>New page</b></p><div>{{apibox}}<br />
<br />
== L'éditeur de scripts ==<br />
<br />
Pour éditer les scripts de votre campagne, cliquez sur le lien "API Scripts" dans la page de détails de la campagne (le même endroit où se trouvent les options telles que le "Chat log" "Copy/Extend Campaign"). Une page contenant plusieurs fonctions vous sera alors présentée :<br />
<br />
* Une liste d'onglets en haut. Votre campagne peut contenir plusieurs scripts pour faciliter l'organisation. Notez que tous les scripts fonctionneront dans le même contexte, ce qui signifie que vous ne devriez pas avoir plusieurs script tentant d'écraser les mêmes valeurs à un même moment sous peine d'avoir des résultats inattendus.<br />
* Un éditeur de scripts. Vous pouvez utiliser cet éditeur ou les modifier dans un éditeur externe puis les copier ici.<br />
* Une console API en bas (voi ci-dessous).<br />
<br />
Lorsque vous cliquez sur le bouton "Sauvegarder les scripts", le sandbox de votre campagne sera "redémarré" (supprimant son état précédent) et utilisera les nouvelles modifications que vous venez d'apporter. Cela s'applique également si vous ajouter ou supprimez un nouveau script ou si vous activez ou désactivez un script.<br />
<br />
=== La Console API ===<br />
<br />
La console API vous permet de suivre l'exécution de vos scripts. Jusqu'à ce que les scripts soient exécutés dans le sandbox, vous n'y avez pas accès directement pour voir des informations sur les résultats ou erreurs du script. La console apporte ces informations hors du sandbox de manière à ce que vous puissiez les voir lors de l'édition des scripts. Toutes les commandes <code>log()</code> apparaîtront ici ainsi que les erreurs rencontrées durant l'exécution. Pour plus d'informations, consultez [[API : Débugger|les informations sur le débuggage des scripts]].<br />
<br />
== Des scripts réactifs : écoutez les événements, modifiez des objets ==<br />
<br />
La première (et plus simple) utilisation de l'API est la réaction aux changements de la table de jeu pour y répondre en appliquant des modifications sur certains objets. Ce type de script est composé d'un certain nombre de fonctions qui écoutent les événements produits durant la partie. Puis il modifiera les objets envoyés avec cet événement, ce qui modifiera la table de jeu.<br />
<br />
Le script le plus simple qui bougerait simplement un objet de 5 pieds vers la droite (en supposant que les paramètres de la page soient ceux par défaut) pourrait ressembler à ceci :<br />
<br />
<pre data-language="javascript"><br />
on("change:graphic", function(obj) {<br />
obj.set({<br />
left: obj.get("left") + 70 <br />
});<br />
});<br />
</pre><br />
<br />
Comme vous pouvez le voir, nous avons créer une simple fonction qui sera exécutée chaque fois que l'événement <code>change:graphic</code> sera entendu. Cette fonction reçoit l'élément graphique <code>obj</code>. Pour faire une modification, nous changeons simplement <code>obj</code> en utilisant la méthode <code>set</code> -- chaque propriété que nous modifions sera détectée et mise à jour sur la table de jeu.<br />
<br />
'''Note importante :''' Vous devez utiliser les méthodes <code>set</code> et <code>get</code> pour modifier et récupérer les valeurs actuelles des objets ou vos changements ne seront pas enregistrés. (Voir ci-dessous pour une liste des types d'objets et leurs attributs, ainsi qu'une liste de tous les événements et quels arguments attend chaque événement.)<br />
<br />
=== A Note on Utility Functions ===<br />
<br />
Of course, the previous example isn't incredibly helpful because it always adds 70 pixels to the location of the token. But what if the user has changed their scale so that 5ft is 140 pixels? The Roll20 API provides several handy utility functions to help with this (and other) common scenarios. Let's modify our previous example to use the <code>distanceToPixelsfunction</code>, which will tell us how many pixels "five feet" (or inches, or meters, or whatever other distance type has been set) on the tabletop is.<br />
<br />
<pre data-language="javascript"><br />
on("change:graphic", function(obj) { <br />
obj.set({ <br />
left: obj.get("left") + distanceToPixels(5); <br />
});<br />
}<br />
</pre><br />
<br />
Now if the current page is setup to use the default grid sizing, <code>distanceToPixels(5);</code> will still return 70 pixels, but if the page is setup to have a scale twice the size of normal, it would return 140.<br />
<br />
It's always a good idea to use utility functions whenever they're available to help keep your script from breaking if the settings of a page or a token change.<br />
<br />
==Proactive Scripts: Do Things Without User Intervention==<br />
In addition to reacting to user events, you can also do things with the API automatically that aren't tied to a specific event from the players. For example, let's have a token that patrols back and forth on the map.<br />
<br />
''Note'': Although this type of script is not dependent on user interaction, the API scripts for your campaign will still only run when at least one person is connected to your campaign.<br />
<br />
<pre data-language="javascript"><br />
on("ready", function() {<br />
//Wait until the ready event fires so we know the campaign is completely loaded.<br />
//Get a reference to our patrolling token.<br />
var patroltoken = findObjs({_type: "graphic", name: "Guard A"})[0]; //We know there is a token in the Campaign called "Guard A".<br />
var direction = -70; //Walk left 70 pixels.<br />
var stepstaken = 0; //How many steps have we walked in the current direction?<br />
setInterval(function() {<br />
if(stepstaken > 3) {<br />
//Switch directions!<br />
direction = direction * -1; //will "flip" the direction we're walking<br />
stepstaken = 0; //reset steps back to 0.<br />
}<br />
patroltoken.set("left", patroltoken.get("left") + direction); //walk!<br />
stepstaken++;<br />
}, 5000); //take an action every 5 seconds<br />
});<br />
</pre><br />
<br />
[[Category:API|Use Guide]]</div>567895