Good Practice to start using variables

So starting here, would be a good time to start using variables in your script. While for this particular course it may not be all that essential, it is still worth getting in the habit of using variables instead of hardcoding the numbers, and it’s good coding. As your scripts get longer, having descriptive variables makes things a lot easier.

so the code would look more like this (your var names can be different):


var force: float = 1000.0
if Input…
apply_central_force(basis.y * delta * force)

The variable could be local to the function or placed globally (if you think you may use it in other places), but it makes debugging easier as if you need to make a change to the force applied, you only need to make that change in 1 place, rather than looking through your entire script trying to find all the places where force is being applied.

Again, for a small script it may not matter, but as your scripts get longer and longer and more complex, having variables with make your life simpler, and getting in the practice of using variables now will help in the long run.

definitely, Bram starts removing magic numbers and using variables in the ‘Export Annotation’ Lecture (number 10 just now when i checked)

Privacy & Terms