Modifier la taille de la police
Nous sommes le Dim 27 Mai 2018 10:52

Écrire un nouveau sujetRépondre Page 1 sur 1   [ 9 messages ]
Auteur Message
 Sujet du message: MP : ManiaScripts
MessagePosté: Ven 19 Aoû 2011 15:34 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand
Je vais regrouper ici différentes infos sur les ManiaScripts, surtout que certains n'ont pas du tout accès aux infos sur la partie beta du forum maniaplanet...

Je vais faire en plusieurs posts, ça sera plus facile à mettre à jour.

Des exemples

Pour l'instant les maniascripts ne sont utilisables que sur les manialinks et les MT apparemment (à part regarder un peu les exemples, leurs sources, et les embryons de doc, j'ai pas vraiment testé)

Manialinks notables avec du script (en faisant 2 fois ctrl+g on a le debugger avec le script visible) :
* ManiaPlanet\PacksCache\\Media\Manialinks\Solitaire (on doit pouvoir y accéder avec un file://Media/... je crois)
* maniaplanet://:easing (src: )
* maniaplanet://:akbalder?Connect4 (src: ... p?Connect4 )
* maniaplanet://:___xbx___ (src: )

Sinon il y a aussi des scripts (MT et/ou editeur?) dans ManiaPlanet\PacksCache\\Scripts\EditorPlugins\

Infos diverses complémentaires glannées dans les réponses aux questions ou rapports de bugs
(si vous en voyez passer, soit editez ici pour ajouter, soit postez en réponse et on ajoutera ça la après)

* problème que 5 est strictement considéré comme Integer, et 5. ou 5.0 comme Real. Donc 1/4 donne 0 alors que 1./4. donnera 0.25.
Attention aux mix Integer et Real dans les opérations apparemment, plusieurs râlent après la non souplesse de la chose. Je n'ai pas testé mais je crois avoir compris que 1./4 ou 1/4. donnera 0.25, auquel cas seules des opérations entre Integer donnent un Integer et ça ne me semble donc pas spécialement un problème. Reste à voir si c'est bien ça.

Dernière édition par Slig le Ven 19 Aoû 2011 15:56, édité 2 fois.

 Sujet du message: Scripts in Manialinks
MessagePosté: Ven 19 Aoû 2011 15:35 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand

Scripts in Manialinks
Gugli a écrit:
One of the new features about manialinks is the possibility to use scripts. It allows to dynamically modify the page, in a similar fashion that Javascript can do in an HTML page.

For exemple, it allows to do more reactive menus, since the page must not be reloaded from the server each time the user clicks.

It works in older manialinks, as soon as they're not using the old "line"/"cell" syntax.

Where to write scripts
<manialink version="1">
// The script goes here
<quad  id ="background" posn="-64 48 -1" sizen="128 96" image="file://Manialinks/bg.png" />

There can be many <script> elements in one page. They will be concatenated to form the final script.

For now, I'll focus on finishing the "Script basics" topic ASAP. I'll get back here to give more details afterwards. ... 672#p36922

Dernière édition par Slig le Ven 19 Aoû 2011 15:40, édité 2 fois.

 Sujet du message: Syntax basics
MessagePosté: Ven 19 Aoû 2011 15:35 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand

Syntax basics
problème, le topic est vérouillé, donc pas moyen de récupérer un quote pour faire une copie propre :(
par Gugli » 19 Juil 2011, 23:39
The script language is one of the (numerous) new features in Maniaplanet. It allows players to customize some aspects of the game (like game rules, or Mediatrack cameras).

In this topic, I will explain only the script syntax, which is common to all the different scripts. The various script contexts will be exposed in other threads. I will suppose that readers are somewhat used to programming languages, although Maniascript is made to be as simple as can be (do you know what a variable is ???). If you're new to programming, you can safely ignore the Protips.

A script is a text, composed by lines (aka, instructions). Instructions are separated by semicolons, as in C/C++.
It looks like

Code: Tout sélectionner
declare MyVar = 12;
MyVar += 1;

Beware : Case is important, always !

Simple data Types
Boolean : can be either True or False
Integer : numbers such as 2 or -5 or 31337
Real : decimal numbers such as -4.2 or 99. (do not forget the final dot, because 99 is an Integer. Beware, those are different)
Text : any character sequence between double quotes : "plop" "gouzi" or "456.32".

Protips :
- inside a Text, The usual escape sequences such as "\n" or "\\" are supported.
- you can also declare a Text value between 3 double quotes. When doing so, you won't need to escape chars, and it can expand on many lines. """plop="452.12.22" toto"""

Variable declaration
In Maniascript, variables must be declared, either by specifying a Type, or an initial value :

Code: Tout sélectionner
declare Integer MyVariable;


Code: Tout sélectionner
declare MyVariable = 42.;

After having declared a variable, you'll be able to use it to store data.
If the variable is defined as a Integer, you will never be able to store anything else inside. The same goes for other types.

Protip : Variables are always defined and initialized when declared, meaning they always have a valid value. If not specified, this value will be a default value for the current type.

Variable affectation
Once declared, you can change the value of a variable with a single equal sign :

Code: Tout sélectionner
MyVariable = 13+37;

As said earlier, the types must match. No implicit conversions are made.

Anything right of a double slash // is a comment
Anything between /* and */ is also a comment

Code: Tout sélectionner
Var = 2 + 5; // This is a comment
Var = 2 /* This is a comment */ + 5;

Simple operators

Boolean operations are : ! && ||

Code: Tout sélectionner
Var1 && (!Var2 || Var3)

Mathematical operations are the usual ones : + - * /

Code: Tout sélectionner
Var1 + (Var2 / Var3)*1000

You can add/substract/multiply/divide a Real and an Integer, the result will be a Real.

To append strings, you can use the ^ operator. You can also append a Real or a Bool or an Integer. It will be converted to Text.

Code: Tout sélectionner
MyVar = "Hello " ^ "world!";

Protip : when using triple-double-quoted Texts you can include variables or expressions in your text with triple-culry-brackets, resulting in something like :

Code: Tout sélectionner
MyVar = """Hello {{{NameOfThePlayer}}}, how are you today??? Five = {{{2+3}}}. \o/ """;


To compare values, you can use the usual : == != < > <= >=
Greater/lower comparisons do not work with Booleans.

When trying to found bugs in a script, you'll use the Debugger. For now, you can only access it by pressing Ctrl+G. It works pretty much anywhere in game. It has 2 modes : a reduced mode where you can only see the logs without interacting, and the Full mode. In Full mode you can select the script that you want to debug (because many scripts can be running at once, for exemple a camera effect, and the rules of your game). It will show you only the log of the selected script, along with the code of the script, which you can not edit there.

Log and assertions
It's often usefull to print some text in the log. You can do that with :

Code: Tout sélectionner
log("Something went wrong!");

The text will be printed in the bottom part of the debug window.

Sometimes it is more easy to check if some requirements are met.

Code: Tout sélectionner
assert(MyVariable == 3);

This will check if MyVariable is equal to 3. If not, the script will be halted as if an error had occured.

Control structures
In maniascript, you'll find the usual control structures :
if(Boolean ) Instructions;
while (Boolean ) Instructions;
for(VariableName , FirstValue , LastValue ) Instructions;
foreach(Element in Array ) Instructions;
foreach(Key =>Element in Array ) Instructions;
switch(Expression ) {
case Expression1: Instructions;
case Expression2: Instructions; .....
default : Instructions;

where Instructions; can be either a one-line instruction or a curly-bracketed set of instructions.

Functions and main()
Most Maniascripts are to complicated to fit in one set on instructions. That's why you can define functions. A function definition looks like that :

Code: Tout sélectionner
[TypeOfTheReturnedValue] [NameOfTheFunction] ([TypeArg1] [NameArg1], [TypeArg2] [NameArg2] .... )

Here's an exemple :

Code: Tout sélectionner
Integer Minimum (Integer A, Integer B)
if (A<B) return A;
return B;

One of the functions is called main (). It has no arguments, and no return type. It's the function called at the beginning of the program.

If your code is simple enough to fit entirely in the main() function, you can omit the function header, and write the instructions without any enclosing brackets.

Variable scope
After a declare instruction, the variables are only accessible in the directly enclosing curly-brackets {...}.

At the top of a script, some special code may be required : those special lines start with the '#' character. Note that directives are not finished with a semicolon ';'

#RequiredContext XXX : the context of a script. This is meant to avoid trying to use an EditorPlugin as a GameMode, because it will always fail
#Const XXX YYYY : declare a constant named XXX, with value YYYY. This value can not be modified.
#Setting XXX YYYY : from the script's scope, #Setting behave exactly as #Const. But this value can be modified from "outside" the script
#Include "XXX" as YYYY : load a library or include a file, and bind the functions to the namespace YYYY.

Exemple of include :

Code: Tout sélectionner
#Include "Library.Script.txt" as MyLib1


Code: Tout sélectionner
// contents of "Library.Script.txt"
Void Function1() {


Advanced types : list and arrays
Advanced types : classes
Advanced types : enums
Timing instructions : yield/sleep/wait
Those instructions allow to pause the exectution of the script. It is very useful, since during the execution script, nothing else happen : the display is not updated, the simulations of the game are stuck, the logs are not being updated, and so on.

yield; The script pauses for the shortest amout of time.
sleep(XXXX); The script pauses for XXXX miliseconds.
wait(YYYYY); The script pause until Boolean YYYYY is True. YYYYY will be evaluated repeteadly, so be careful when YYYYY is a function call : the fonction will be called many times.

Equivalents :
yield; is equivalent to : sleep(0); or wait(True);
sleep could be written :

Code: Tout sélectionner
void Sleep(Integer XXXX){
Start = Now;
while(Now < Start + XXXX) {
wait could be written :
    while(!YYYYY) {

Protip : If you use sleep(XXXX) in a script where you catch events (Manialink scripts for exemple), you will miss the events which occured during the sleep(). This is so because one event is only valid during 1 script "frame", i.e the time between two consecutive "yield;" . To avoid that, you can use wait instead :
Start = Now;
wait(Now > Start + 1000 || PendingEvents.count >= 1);

declare for

Dernière édition par Slig le Ven 19 Aoû 2011 15:45, édité 1 fois.

 Sujet du message: Maniascript Documentation
MessagePosté: Ven 19 Aoû 2011 15:35 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand

Maniascript Documentation
celui c'est c'est pas qq1 de nadeo, mais quelques infos utiles...
konte a écrit:
I've been trying to collect all the properties and methods for the last few days, so I'm going to write a small documentation, a bit a tutorial too, about everything I know. Of course I will add everything you found out :)
I tried almost only on Manialinks, so there is nothing about Plugins/MT, yet. But I guess other people figured out more there :thumbsup:

Also, this documentation is not supposed to be in competition to destroflyer's tutorial. This is supposed to be a compact reference with all relevant information; You need to have read Gugli's syntax basics.

There is this following standard construct to react on events:
while(True) {
   foreach(Event in PendingEvents) {
      switch(Event.Type) {
         // case blabliblubb and so on

Event has the following properties:
  • Event.Type: There are the following types:
    • CGameManialinkScriptEvent::Type::MouseClick
    • CGameManialinkScriptEvent::Type::MouseOver
    • CGameManialinkScriptEvent::Type::MouseOut
    • CGameManialinkScriptEvent::Type::KeyPress
    The mouse events occur only, if the corresponding Manialink element has the property ScriptEvents="1" set. The element doesn't need to have an id="".
  • Event.ControlId: In case of the mouse events (MouseClick; MouseOver; MouseOut) this property has the id of the element. If the element doesn't have an id, the value is "Unassigned".
  • Event.CharPressed: In case of KeyPress this property returns an unique number of the key pressed, e.g. 327680, 393216. Many numbers look like the result of a 2^n operation. So, when I took the logarithm of some, I got more friendly numbers like 16 or so, but sometimes it is in between of e.g. 16 and 17 and irrational. Shift, Ctrl and Alt won't cause an event and futhermore, there is no difference between a and A e.g.
    This event is always provoked, you don't need to have selected an entry or so. Even further, it is also provoked in the script editor or when you type in the address bar.

Page is also a predefined object. By now, the only use I found out for it is to select elements and get properties of it or change properties.
  • Page.GetFirstChild(): Expects a text, which is the id of a Manialink element. There doesn't need to be a ScriptEvents="1" for this, this is only for events (as the name says^^). GetFirstChild() is global over the Manialink: you can also address elements within a frame.
  • Page.MainFrame.Controls: The second possibility is MainFrame.Controls, which is an Array. That way you can also select elements by its id (text), but also by the position it occurs in the Manialink (integer). Examples:
    Page.MainFrame.Controls[3] // Addresses the fourth element in the manialink

    With Controls you cannot address elements within a frame; You can only address the frame as such.

Element Classes
Both MainFrame.Controls and GetFirstChild() return an object. This object can be cast as one of the following classes, but every object has the following standard properties and methods also without casting. After casting, those will still work of course.
  • Id: Id of the element; Normally only relevant for addressing elements by its position with Controls.
  • PosnX: Real; x-value of the element; readable and writable
  • PosnY: y-value of the element
  • PosnZ: z-value of the element
  • Hide(): Expects no argument; Hides the element
  • Show(): Expects no argument; Shows the element (again)
  • Unload(): Expects no argument; deletes the element. Using the variable afterwards will cause an error.

  • ChangeImageUrl(): Expects a text; Changes the image of the quad
  • Value: Text; readable and writable
  • Value: Text; readable and writable
  • FullFileName: Text; read-only (allegedly; Marcel said that :P)
  • SetText(): expects a text, maybe you already supposed so ;)
  • Controls: The same Controls as the Page.MainFrame.Controls - you can access elements in this frame with it.

The math functions are a bit weird. For some (so far, two) of them, you have to load the Math object:
#Include "Math" as Math

  • Math::ToInteger(): Expects a text or a real. Returns an integer. Numbers are rounded - "2.5" results in 3.
  • Math::ToReal(): Expects a integer and returns a real. Yes, no text. For converting inputs to reals you have to write your own function so far.
  • sin(): (The following functions are directly accessable without loading the Math object) Expects a real and returns a real.
  • cos()
  • tan()
  • exp(): Expects and returns a real. exp(x) equals e^x, where e is Euler's number. So, exp(1.) will return e.
  • rand(): Expects to arguments, where both are either integers or reals. First will return a random integer between the first and second number, second will be the same, only with a real, which has 5 digits after the dot.

Other Variables
  • MouseX and MouseY: Returns the position (real) of the mouse in Manialink positioning of version="1", whether you use version="1" or not (in my case, hovering a version="0" element with x=10 resulted in MouseX=25).
  • CurrentLocalDateString: Well, sounds like a string, but it is a text :P Example: 2011/08/15 15:28:32
  • CurrentTimeString: Example: 4:02:18.69
  • CurrentTime: Integer - Example: 145941538; I cannot tell you what exactly this is (as well as CurrentTimeString), but those are milliseconds.

Dernière édition par Slig le Ven 19 Aoû 2011 15:47, édité 1 fois.

 Sujet du message: Re: MP: ManiaScripts
MessagePosté: Ven 19 Aoû 2011 15:36 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand

 Sujet du message: Re: MP: ManiaScripts
MessagePosté: Ven 19 Aoû 2011 15:41 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand

 Sujet du message: Re: MP: ManiaScripts
MessagePosté: Ven 19 Aoû 2011 16:04 
Avatar de l’utilisateur

Inscription: Mar 5 Aoû 2008 11:04
Messages: 1895
Super merci. Rien de très étonnant pour l'instant, et rien qu'on puisse en faire ou presque ^^

moun a écrit:
"Salut, je suis champion du monde de rally sur coast !"
"Oui, c'est ca ! Et moi je suis champion de france d'island sur désert !"

 Sujet du message: Re: MP: ManiaScripts
MessagePosté: Ven 19 Aoû 2011 16:49 
Avatar de l’utilisateur

Inscription: Mar 19 Aoû 2008 11:23
Messages: 2032
Localisation: TraXicoLand
Gued a écrit:
Super merci. Rien de très étonnant pour l'instant, et rien qu'on puisse en faire ou presque ^^

Pour le jeu lui même effectivement non.

Encore que je n'ai pas réellement essayé si on peut glisser un maniascript au client dans les affichage online envoyés par le script serveur, or si c'était possible ça permettrait des choses genre masquer ou déplacer un panel sans occuper ni le dédié, ni le script serveur, ni la bande passante, donc fait 100% par le client. Mais bon ça serait sympa et/ou utile pour alléger certaines choses, mais par contre ça n'en fait pas un gamemode ;)

 Sujet du message: Re: MP: ManiaScripts
MessagePosté: Ven 19 Aoû 2011 17:53 
Garfield Driver
Avatar de l’utilisateur

Inscription: Mar 5 Aoû 2008 07:09
Messages: 3460
Localisation: Cambrai
Ca reste du charabia quand même tout ça :|


Afficher les messages postés depuis:  Trier par  
Écrire un nouveau sujetRépondre Page 1 sur 1   [ 9 messages ]

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité

Vous ne pouvez pas poster de nouveaux sujets
Vous ne pouvez pas répondre aux sujets
Vous ne pouvez pas éditer vos messages
Vous ne pouvez pas supprimer vos messages
Vous ne pouvez pas joindre des fichiers

Aller à:  

Développé par phpBB® Forum Software © phpBB Group
610nm Style by Daniel St. Jules of

Traduction par