Subtracting from an integer value

XanMag
29 Nov 2015, 15:25So I have several codes within my game that call for something similar to this:
Garage.PostitsReadCount = Garage.PostitsReadCount - 1
The integer count that it is subtracting from is 3 in the above example.
Will it create a problem if the player reads the post-it note fifteen times? Will there be an error (or create some problem) if you subtract from a zero integer? I do have a changedPostitsReadCount attribute that produces a final message when all three are read.
If so, I assume I need to put a first time script for each instance where it applies. Let me know. Thanks!
XanMag
Garage.PostitsReadCount = Garage.PostitsReadCount - 1
The integer count that it is subtracting from is 3 in the above example.
Will it create a problem if the player reads the post-it note fifteen times? Will there be an error (or create some problem) if you subtract from a zero integer? I do have a changedPostitsReadCount attribute that produces a final message when all three are read.
If so, I assume I need to put a first time script for each instance where it applies. Let me know. Thanks!
XanMag
max17
29 Nov 2015, 17:51Let me know if I understood what you need. You could use:
in this way you'll count only once the read count. I suppose the postits the player has to read are different and it is not the same one.
firsttime {
Garage.PostitsReadCount = Garage.PostitsReadCount - 1
//other code
}
otherwise{
//other code
}
in this way you'll count only once the read count. I suppose the postits the player has to read are different and it is not the same one.
HegemonKhan
29 Nov 2015, 18:08your Attribute's Value will merely subtract into a negative Value (nothing weird occurs because this is programming, it works exactly like it does normally in math), so in general it's not a problem, unless you have some game design need~issue with the Attribute's Value not going below zero into negative numbers. Life~HP is generally one such game aspect that you don't want the Value to be negative.
It's similar to if you don't want a Value to go over a maximum Value, well for some things you don't want a Value to go below a minimum Value too, such as the minimum Value of zero.
------
if you want to "prevent" an Attribute's Value from being negative, an example:
orc.current_life = orc.current_life - player.damage
// player.damage = 9999
// orc.current_life = 100
//
// conceptually:
//
// orc.current_life = 100 - 9999
// orc.current_life = -9800
if (orc.current_life < 0) {
orc.current_life = 0
It's similar to if you don't want a Value to go over a maximum Value, well for some things you don't want a Value to go below a minimum Value too, such as the minimum Value of zero.
------
if you want to "prevent" an Attribute's Value from being negative, an example:
orc.current_life = orc.current_life - player.damage
// player.damage = 9999
// orc.current_life = 100
//
// conceptually:
//
// orc.current_life = 100 - 9999
// orc.current_life = -9800
if (orc.current_life < 0) {
orc.current_life = 0

XanMag
29 Nov 2015, 21:14So... I'm good! Thanks.