List Element: Difference between revisions
m
Rename to meaningful file names
(Updated the page. TODO: update the explanation.) |
-u ndefined- (talk | contribs) m (Rename to meaningful file names) |
||
Line 1: | Line 1: | ||
{{Block | {{Block | ||
|image=List Element.png | |image=List Element number.png | ||
|type=s | |type=s | ||
|folder=variables | |folder=variables | ||
Line 21: | Line 21: | ||
* A non-integer index number is rounded down to the next smallest integer. | * A non-integer index number is rounded down to the next smallest integer. | ||
* '''For experienced users:''' Plugging the Element output to the Variable of another List Element will add their indexes. This is similar to pointer arithmetic in languages like C. See the image below: | * '''For experienced users:''' Plugging the Element output to the Variable of another List Element will add their indexes. This is similar to pointer arithmetic in languages like C. See the image below: | ||
: | : {{Image|List Element example1.jpg|Index addition.}} | ||
== Example == | == Example == | ||
Line 27: | Line 27: | ||
Here is the script for when a player shoots a bullet. | Here is the script for when a player shoots a bullet. | ||
{{Image|List_Element_example1_bullet.jpg}} | |||
Explanation: | |||
* We create a bullet, store it in a variable, and set its position to the player's position. | * We create a bullet, store it in a variable, and set its position to the player's position. | ||
* Assuming that the player faces (0, 0, 1) if its rotation is 0°, we rotate that vector (0, 0, 1) by the player's rotation, and that gets us the player's direction, which should also be the bullet's velocity. | * Assuming that the player faces (0, 0, 1) if its rotation is 0°, we rotate that vector (0, 0, 1) by the player's rotation, and that gets us the player's direction, which should also be the bullet's velocity. | ||
Line 38: | Line 38: | ||
How do we fix that? | How do we fix that? | ||
{{Image|List_Element_example1_store_bullets.jpg}} | |||
Lists are like variables, but they can store more values in one, so we just have to store the bullets and their velocities like so. | Lists are like variables, but they can store more values in one, so we just have to store the bullets and their velocities like so. | ||
We have to make sure to increment the index, otherwise the next bullet would be stored in the list with the same index giving us the same problem we had with the previous script. | We have to make sure to increment the index, otherwise the next bullet would be stored in the list with the same index giving us the same problem we had with the previous script. | ||
{{Image|List_Element_example1_move_bullets.jpg}} | |||
Next thing we have to do is run the script for every bullet with a [[loop]]. | Next thing we have to do is run the script for every bullet with a [[loop]]. | ||
Line 53: | Line 53: | ||
Here is a simpler example that demonstrates how to create multiple objects and process them all at once: | Here is a simpler example that demonstrates how to create multiple objects and process them all at once: | ||
{{Image|List_Element_example2_object_processing.png}} | |||
By storing every object in a list to their respective indices, you can loop from 0 to the list's length amount of times, using the current index to get the current object from the list to be processed. | By storing every object in a list to their respective indices, you can loop from 0 to the list's length amount of times, using the current index to get the current object from the list to be processed. |