What is a constant variable and what is the benefits of using it? Give me one good example when its better to use then a normal variable. Asking purely out of curiosity.
As you can see, I'm using the value of 7 over and over, because it is the number of players in my game (So I want to track their hero, if they are alive or not, their score and so on.
Now, imagine you want to go back and change it so that 10 players can now play. With the above code, I have to track down every single place I've used 7 and change it to 10. Not fun, and almost certainly will result in a bug/broken game. To prevent this, I can do the following instead
In this version, to change how many players requires me to change one variable, and I'm done, no matter how big the code has grown and how many times I've used the number 7 for the number of players.
As far as i understand it mostly meant for speed up huge codes and to be used in array sizes, it sound to me like its very very close to be unnecessary in sc coding.
But to be exact. Variables you don't intend to change with anything else then the editor, set it to constant to gain a minimal performance boost. Correct?
i would argue that the performance boost is non existant. it's a workflow boost if you have to change one value instead of X values with a chance of missing one. saves you time in changing things and debugging.
use const variables whenever you have a reoccuring constant value i.e dialog button size and their offsets (which is based on the size of the buttons if you group alot)
What is a constant variable and what is the benefits of using it? Give me one good example when its better to use then a normal variable. Asking purely out of curiosity.
A variable that is unmodified inside the game. (ie: set constant_variable = X will not work, since it is constant)
Public resources (systems) is a good example of it. It's not 'better', is just a variable that can't be changed inside the game.
People use it in system for things like:
constant real imageX = 100
constant real imageY = 170
Because the imported image has this dimension, more like a configuration thing.
In a programming language it results in cleaner/faster code because the compiler knows the value won't change.
To avoid having to go back and change a constant value that is used in multiple places, you use a constant variable.
A simple example would be to have the following:
As you can see, I'm using the value of 7 over and over, because it is the number of players in my game (So I want to track their hero, if they are alive or not, their score and so on.
Now, imagine you want to go back and change it so that 10 players can now play. With the above code, I have to track down every single place I've used 7 and change it to 10. Not fun, and almost certainly will result in a bug/broken game. To prevent this, I can do the following instead
In this version, to change how many players requires me to change one variable, and I'm done, no matter how big the code has grown and how many times I've used the number 7 for the number of players.
Arcane, it is not a exclusive function of constants, it can be easily be done using a normal integer.
Actually, array sizes can only use constants. The array size must be known at compile time.
Don't know why I put functions.
Actually, it can only use a directly value or a constant.
another field of use are dialogs. especially if you have to move/group alot of them. having a const size for the items is pretty neat.
As far as i understand it mostly meant for speed up huge codes and to be used in array sizes, it sound to me like its very very close to be unnecessary in sc coding.
But to be exact. Variables you don't intend to change with anything else then the editor, set it to constant to gain a minimal performance boost. Correct?
yes.
i would argue that the performance boost is non existant. it's a workflow boost if you have to change one value instead of X values with a chance of missing one. saves you time in changing things and debugging.
use const variables whenever you have a reoccuring constant value i.e dialog button size and their offsets (which is based on the size of the buttons if you group alot)