Les tuiles [ça] et [eux] sont des idées propres au système When/Do de Project Spark, elles permettent de faire en sorte que votre kode ait l'air plus naturel quand vous l'écrivez. Par contre, il est important de comprendre quelles informations elles contiennent, car si vous ne ne mettez pas en place le côté When de la bonne manière, elles ne contiendront aucune information.
La tuile ça
La tuile [ça] fait référence au dernier côté When ... traduction à venir, il y a quelques imprécisions à corriger par rapport à ce qui est dit dans le texte anglais, et absence de la définition de "règle" et de "parent" et "enfant".
The [it] tile looks at the when side of its line to see if it evaluates to either a single object or an object set. If so, then [it] refers to the object or the first object in the set. If an object or object set is not found, each parent rule is checked, starting with the nearest one, until either the value of [it] can be set, or there are no more parent lines to check.
Another interesting use of the [it] tile is in a [for each of] loop. If you loop over an object set, then you can use the [it] tile to refer to the current object.
La tuile eux
The [them] tile works similarly to the [it] tile, except it treats what is found as an object set.
One of the most common ways to use the [it] tile is to check if an object exists in your when section, then to do something.
This line checks to see if you have an object defined as [My Enemy], and if you do, shoots at it.
Another very common way of using both the it and them tiles are with sensors. Lets look at this line:
This could be for something like a fire zone your character puts on the ground. The [them] tile is referring to the enemies found in the trigger zone.
You could use [it] in place of [them] above, which would choose just one enemy out of the set. You could also be looking for a specific object to enter the trigger zone instead like this.
Note: [global] [player] is an object variable that has been defined, and not the custom [player] tile.
Please note an easy mistake to make here: Checking if your object set has a count greater than 0, or that your object variable is not equal to nothing will *not* set your [it] tile. Let's take a quick look at why.
The When side above is evaluating to a boolean. It is either true or false, and therefore is *not* going to set the [it] tile, so the object will never jump. However, we can update the kode to be:
This will work, because the when side evaluates to the object variable and so the [it] tile is set.
This is the same as the object set example.
The use of [greater than] changes the result of the expression into a boolean rather than an object set, which doesn't allow the [them] tile to function. Therefore the above kode will NOT work as intended.
À lire ensuite
Pour plus d'information