Started by
Nosferatu8
on
Topic category: Advanced modding
Hello everyone. My problem is that listing my more than 128 spells became a problem. I've made a spellbook and to choose a spell and activate it i must deactivate all the rest. Is there an advanced and more sophisticated way than listing each of the variables and manually setting them?
Thanks for the help.
One option would be to store special spell as a bit inside integer. In Java, int is made out of 32 bits, so every bit of this value could represent one spell. If said bit is 1, spell is enabled, if it is 0, spell is not enabled.
Let's simplify this to 4-bit number, so say initial state is 0000 and the most right bit (first bit) is for first spell, second is for second spell and so on.
Value of 0001 (binary, decimal 1), which is 1 means that spell 1 is active. A value of 1000 (binary, decimal 8) means spell 4 is active. Value of 1001 (binary, decimal 9) means spells 1 and 4 are active.
In "math" procedure section, you have operators for numbers that include bitwise operators.
Further reading:
This way you can use one number (int) variable to store 32 states/spells
Another option I see is to store states in a string variable of 128 characters and each char e.g. if the char at index 10 is 1, it means spell 11 is active, if it is 0, it means this spell is not active.