Quote: "Most of the errors I get is lua getting finicky about variables being nil."
when you say that
A is greater than B
, you are making a comparison, the problem is that
A is equal to 5 while
B is equal to nil,
B has no value, therefore there is nothing to compare, and therefore an error occurs.
To avoid this problem, ensure that the variables always receive a value, either by direct assignment [i]A = B[/i], or by receiving the value from another variable:
Local A = nil or 0 -- avoid empty var error (nil)
Local A = 5 -- direct assignment
or
if A == 5 then B = A end.
A is passing a value to
B, therefore
B is no longer an empty variable, now you can establish the comparison, without receiving any error.
When I work on a new script, I usually copy and paste the code version in the notepad before making drastic modifications, if I achieve the following objective, I copy and paste the new version of the code and as it works well, I add:
--ok +, and I continue, when I get another success in the operation of the code I repeat the operation but this time I add:
--ok ++ and so on.
If after a long time, If find this code, I know which version does one thing or another. And if the next attempt to improve the code is disastrous, I can go back to an earlier version of the code that worked well, and continue from there. Things like this help isolate an error to find it more easily.
In real life things have characteristics, unique features that differentiate them from others.
A car has color, brand, size, weight, etc.
In GG entities also have characteristics or properties, and you can work with them.
A table / array is like a bag, here you can put all the features together, and work with them.
car = {color = "blue",size="small",brand="bmw", weight=1000}
Now you can do:
if car.color == "blue" then car.color = "black" end -- here you change car color.
Question is not
why, but
when. When use a table/array or does not.
That depends on how many characteristics the object with which you are going to work has, for example in the case of particles, they are many as you can see.
You have 200 apples and you have to transport them from point
A to point
B, you can take them one by one and make 200 trips, or put them all in a bag, and carry them at once.
In real life we execute code every day, in each of our actions.
I wake up in the morning and go to the kitchen, if I have oranges I will drink a juice, and if I don't have a cup of coffee. This in itself is already a decision making that implies a condition:
if apples == 1 then
drink juice = true
else
drink coffee = true
end
Easy. LOL
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz
OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4