English Commentary on a Chinese LuaSTG Tutorial Pt 2
This part is about combining the Repeat node with Variables
= = =
Video 3:Ā https://www.bilibili.com/video/BV1st411N7Kg?p=3 tl;dr Stuff about 60FPS (this was covered in the last post) and using the Repeat node with Variables
Context: I believe we need a bit of context before diving into this video. This tutorial seems to use an older version of LuaSTG lacking newer QoL features. The first part of the tutorial is notably focused on creating a group of bullets using the Single Bullet node.
The actual concept they put into practice is sound (i.e. using the Repeat node in conjunction with Variables) and it's still a useful video but please note that this tutorial was for a version of LuaSTG that seemingly did not have the "Create Bullet Group" node (which can replicate what was achieved in this tutorial with far less hassle).
Also, you may notice that the tutorial makes use of Intervals within the Repeat node... and that the Sharps editor's Repeat node does NOT have an Interval parameter. This is something of a problem with trying to follow this tutorial.
When following and trying to recreate some of their examples, it is possible to use the Wait function in place of Interval. But in other scenarios, Wait will not work. I haven't figured out why Wait works sometimes but not others but be wary of that.
Content
3:04 is when the tutorial gets to the good stuff.
In case you're not just watching the video, when you create a Repeat node, you should see directly under the "Times [repeated] parameter four other parameters: these are Number of Var(iables), Var [no.] Name, Var [no.] Init Value and Var [no.] Increment.
Number of Var determines the number of variables in the Node. By default it is set to 1, meaning that besides "Times" and "Number of Var" there should be three other parameters (all related to each other). If you set the value higher, you will multiply the number of the three following parameters by whatever number you've inputted (i.e. you put "Number of Var" to 4, you will enable to Repeat node to have 4 sets of the following three parameters).
Those three parameters make up the Variable that will be used in conjunction with the Repeat node.
Var [no.] Name (1) is the variable name.
Var [no.] Init Value (2) is the init (initial?) value of the variable.
Var [no.] Increment (3) is the value of the increments.
1 is obvious. You must give your variable a name so that the program knows when you're using it. Note that there are some restrictions on what you can name your variable. I don't know these restrictions from the top of my head, but they are there, so not every type of name will work.
2 is the initial value of the variable. What is in the initial value? It's hard to explain because you can basically substitute variable into different parameters, and different parameters use the same values differently. Quick example. What happens if you use 0 on Velocity when creating a bullet? The answer is "you will spawn a bullet that doesn't move". Now what happens if you use 0 on Angle? The answer to that is "you will spawn a bullet fired at 0 degrees (aka to the right of itself)"... but even that's not true in all situations; a bullet fired at 0 degrees with Aim To Player active won't fire at 0 degrees, it'll fire at the player. Why am I bringing up these examples? The answer is that you can actually use a Variable for these two parameters (i.e. Velocity and Angle) as well as others. However, as you can see, the init value is very context dependent which makes it tricky to explain. The only thing consistent about init value is that it's the starting value for our variable. No matter whether it's for angle or velocity, the number you put into the init value is the number the variable begins with.
Now, increment... Let's see what increment actually means. Merriam-Webster has this very convenient first definition of: "the amount or degree by which something changes". It's a useful definition for bringing up "amount or degree" since increment can change either of these, depending on the initial value of the variable. However, a more useful definition is this: "one of a series of regular consecutive additions". This is what increment is really useful for. By combining a specific type of formula (made of Variables) with the Repeat function, you can make consecutive additions to... whatever it is you're doing. One application you might think of is changing a bullet to move slow or faster over time. What the video shows you to do is telling the game to change the firing angle of each bullet. There are obvious functions to this, like making the game create a bullet that increases in speed, but the video shows you another application: you can use the Variable to tell the game to fire a bullet at consecutive angles. The picture example at 5:00 illustrates it perfectly. The first bullet fired has the initial value (angle) of 0. After it's fired, the initial value changes because of the incremental value (36). When the second bullet fires, it uses the new value of 36... said value has now increased by 36 AGAIN so when the third bullet fires, it's now at 72 etc.
Let's recap:
Repeat nodes, by default, have 4 extra parameters besides "number of repeats". The first extra parameter determines the no. of extra variables (and their relevant parameters). The other three parameters determine the variable itself. Variable name allows the game to recognize the variable, and allows YOU to use it. Variable init value is the initial starting value of... whatever the variable is going to be used for (it could be the starting value for a change in velocity, a change in angle etc.). Variable increment is the value that the initial value is going to be consecutively changed by. (An extra note: the initial value doesn't need to be an additive value. The increment can be a negative value too. By using a negative value, you can make something move slower, or the angle can be a clockwise motion, instead of a counter-clockwise one).
As for how this all works: take note of the parameters in the Node they're showing off at 5:00. The Repeat node, set to repeat 10 times, has 1 Variable named "a", with init value 0 and incremental value 36. While inputting these parameters into the Repeat node is all well and good, there's one last important step. You can see it by looking at the Bullet node below it: the angle of the bullet is "a" (aka the Variable's name). This is how you tell the game that "I want you to use the Variable for this Parameter".
= = =
Phew that was a long-winded explanation.
I think the next post will be the last in this series. Just because there's not much else an English-only reader of the tutorial is going to get (though there's also not many parts left to the tutorial too).
UPDATE: Two more parts, not one. The third to last video is a lot longer and more complicated than I remembered.












