help~question with~on coding mechanics
HegemonKhan
30 Dec 2013, 10:30using this structure (or if you got a better one, please share it, hehe):
your age: game.pov.age_integer
your year of birth: game.pov.year_integer
starting year of the game: global_data_object.year_integer = game.pov.age_integer + game.pov.year_integer
self-explanatory: global_data_object.old_leap_year_integer
self-explanatory: global_data_object.new_leap_year_integer
in my limited coding ability, I am using "old and new leap year integers" to increment the "leap year" for the checking of it (such as for whether february has 28 or 29 days, and thus also whether there are 365 or 364 days in that year), as after some thinking on this, this method seemed best and easiest to implement. I can code in a "foreach", but that would generate a huge list of leap year dates (even despite being able to code in a limit upon the number of leap year dates generated), so this isn't a good method, although it is cool code~math-wise, lol.
for example of how this method works (if I were to use a~this static method) conceptually (quasi-code):
global_data_object.year_integer = 2014
global_data_object.old_leap_year_integer = 2012
global_data_object.new_leap_year_integer = 2016
when (ie if) "global_data_object.year_integer = global_data_object.new_leap_year_integer ( ie = 2016)", then:
global_data_object.old_leap_year_integer = 2016
global_data_object.new_leap_year_integer = 2020 (ie 2016 + 4)
------------
however, dynamically, I can't pre-set the "old and new leap year integers", so I need a function (equation~formula~alogorithm), for generating~setting them:
<function name="a_function">
-> result_x = global_data_object.year_integer
-> if (result_x / 4 = "an integer") {
->-> global_data_object.old_leap_year_integer = result_x
->-> global_data_object.new_leap_year_integer = result_x + 4
-> else if (result_x / 4 = "a double") {
->-> b_function (result_x)
-> }
</function>
<function name="b_function" parameters="result_x">
-> result_x = result_x + 1
-> if (result_x / 4 = "an integer") {
->-> global_data_object.new_leap_year_integer = result_x
->-> global_data_object.old_leap_year_integer = result_x - 4
-> else if (result_x / 4 = "a double") {
->-> b_function (result_x)
-> }
</function>
--------------------------------------------------
so, my questions are:
first, would this structure work?
second, would the "IsInt" and~or "IsDouble" check for the resultant value of the "result_x / 4" ???
third, if answer is "no" for my "second" question, how would I code for this then? Using greater than and lesser than, somehow?
your age: game.pov.age_integer
your year of birth: game.pov.year_integer
starting year of the game: global_data_object.year_integer = game.pov.age_integer + game.pov.year_integer
self-explanatory: global_data_object.old_leap_year_integer
self-explanatory: global_data_object.new_leap_year_integer
in my limited coding ability, I am using "old and new leap year integers" to increment the "leap year" for the checking of it (such as for whether february has 28 or 29 days, and thus also whether there are 365 or 364 days in that year), as after some thinking on this, this method seemed best and easiest to implement. I can code in a "foreach", but that would generate a huge list of leap year dates (even despite being able to code in a limit upon the number of leap year dates generated), so this isn't a good method, although it is cool code~math-wise, lol.
for example of how this method works (if I were to use a~this static method) conceptually (quasi-code):
global_data_object.year_integer = 2014
global_data_object.old_leap_year_integer = 2012
global_data_object.new_leap_year_integer = 2016
when (ie if) "global_data_object.year_integer = global_data_object.new_leap_year_integer ( ie = 2016)", then:
global_data_object.old_leap_year_integer = 2016
global_data_object.new_leap_year_integer = 2020 (ie 2016 + 4)
------------
however, dynamically, I can't pre-set the "old and new leap year integers", so I need a function (equation~formula~alogorithm), for generating~setting them:
<function name="a_function">
-> result_x = global_data_object.year_integer
-> if (result_x / 4 = "an integer") {
->-> global_data_object.old_leap_year_integer = result_x
->-> global_data_object.new_leap_year_integer = result_x + 4
-> else if (result_x / 4 = "a double") {
->-> b_function (result_x)
-> }
</function>
<function name="b_function" parameters="result_x">
-> result_x = result_x + 1
-> if (result_x / 4 = "an integer") {
->-> global_data_object.new_leap_year_integer = result_x
->-> global_data_object.old_leap_year_integer = result_x - 4
-> else if (result_x / 4 = "a double") {
->-> b_function (result_x)
-> }
</function>
--------------------------------------------------
so, my questions are:
first, would this structure work?
second, would the "IsInt" and~or "IsDouble" check for the resultant value of the "result_x / 4" ???
third, if answer is "no" for my "second" question, how would I code for this then? Using greater than and lesser than, somehow?

jaynabonne
30 Dec 2013, 11:51First, for your a and b functions, everything after the first line of each is the same - that cries out for that bit to be factored out into a separate common function.
Second, a normal year has 365 days, and a leap year has 366.
(Generally - for an exception, look up September 1752. Yes, I wrote some calendar code once...)
Third, a year is a leap year if it's divisible by 400 or (failing that) if it's divisible by 4 but not by 100. So 2000 is a leap year, but 2100 is not.
Fourth, what you're really looking for with "is divisible by" is whether the remainder after division is 0. That's where your friendly mod operator comes in. So if year % 4 = 0, then it's evenly divisible by 4.
I have to think about your algorithm a bit. There has to be an easier way. One question is why you need the old and new leap year values.
Second, a normal year has 365 days, and a leap year has 366.

Third, a year is a leap year if it's divisible by 400 or (failing that) if it's divisible by 4 but not by 100. So 2000 is a leap year, but 2100 is not.
Fourth, what you're really looking for with "is divisible by" is whether the remainder after division is 0. That's where your friendly mod operator comes in. So if year % 4 = 0, then it's evenly divisible by 4.
I have to think about your algorithm a bit. There has to be an easier way. One question is why you need the old and new leap year values.

jaynabonne
30 Dec 2013, 11:58BTW, if you don't care about the multiple of 100s years, you could just do:
old_leap_year = year - (year % 4)
new_leap_year = old_leap_year + 4
That fits the algorithm (I think) you were trying to do.
old_leap_year = year - (year % 4)
new_leap_year = old_leap_year + 4
That fits the algorithm (I think) you were trying to do.
HegemonKhan
30 Dec 2013, 16:56I'm trying jayna, this date~time~calender coding is a challenge for me to try to figure out... I'm doing my best at trying to get this set up in code, as best as I can, lol. So, forgive the ugliness of it, it's what I've been able to come up with so far in design.
I'm sure date~time~calender stuff is pretty basic programming, but I'm still very new to coding~programming, and so this is a challenge for me to code-logic understand and to figure it's design out... sighs.
-----------
actually, in the poor (yes, I know this can be coded better, maybe I can make something better if I keep working at it, but this is what I was able to do for now) coding that I have, these two functions are needed for it to work, and they're not exactly the same (take a closer look at them, in how they're needed for what is my coding design).
using the simple testing of plugging in numbers:
year = 0
a_function:
0 / 4 = 0 -> old_leap_year = 0 and new_leap_year = 0 + 4
year = 0
old_leap_year = 0
new_leap_year = 4
-----------------
year = 4
a_function:
4 / 4 = 1 -> old_leap_year = 4 and new_leap_year = 0 + 4
year = 4
old_leap_year = 4
new_leap_year = 8
-----------------
year = 8
a_function:
8 / 4 = 2 -> old_leap_year = 8 and new_leap_year = 0 + 4
year = 8
old_leap_year = 8
new_leap_year = 12
-------------------
year = 1
a_function:
1 / 4 = 0.25 -> b_function
b_function:
1 + 1 = 2
2 / 4 = 0.50 -> b_function
2 + 1 = 3
3 / 4 = 0.75 -> b_function
3 + 1 = 4
4 / 4 = 1
year = 1
+ "function resultant years"
NEW_leap_year = 4
year = 1
OLD_leap_year = 4 - 4 = 0
------------------
year = 5
a_function:
5 / 4 = 1.25 -> b_function
b_function:
5 + 1 = 6
6 / 4 = 1.50 -> b_function
6 + 1 = 7
7 / 4 = 1.75 -> b_function
7 + 1 = 8
8 / 4 = 2
year = 5
+ "function resultant years"
NEW_leap_year = 8
year = 5
OLD_leap_year = 8 - 4 = 4
--------
year = 7
a_function:
7 / 4 = 1.75 -> b_function
b_function:
7 + 1 = 8
8 / 4 = 2
year = 7
+ "function resultant years"
NEW_leap_year = 8
year = 7
OLD_leap_year = 8 - 4 = 4
---------
you're probably wondering why the "old_leap" matters if the "year" is already exceeding it....
remember that the "change" method that I'm using is this:
year = 0
old_leap = 0
new_leap = old_leap + 4
if (year = new_leap) {
-> old_leap = year
-> new_leap = old_leap + 4
}
as this allows me do the easy incrementing of the leap years by "new_leap = old_leap + 4", and also to be able to use "if year = leap_year, then days in february = 29 and days in year = 366, else days in february = 28 and days in year = 365"
----------
err... used my memory... I was off by one day... argh!
my bad memory: 364 and 365
correct: 365.25 -> 365 and 366 (every 4th year ~ 29 days in february instead of 28)
----------
ya, it's ugly and messy... but unless I'm missing or over-looking something obvious, it should work... lol
----------
I figured that the "%" could be used too, but I was hoping that the "ToInt" and~or "ToDouble", could do the same job... so, can they or not?
---------
all this work on my part....
I'm depressed... I should quit trying to code... lol (j/k, THANK YOU jayna!, I'm learning bit by bit, lol, of coding and of coding better, from you, hehe)
(I really need to get a better comprehension of the "%"... I understood it... but not how to apply it beyond its definition... it never occured to me to do this: year - year % 4, ARGH!)
I do think my code works... but it sure is the "long ways" of doing your quick and simple:
old_leap_year = year - (year % 4)
new_leap_year = old_leap_year + 4
though my code finds the new_leap_year and then subtracts to get the old_leap_year, the reverse of yours
don't worry about trying to follow my code, as I know how hard it is to follow others' processii of code, math equations, and~or just another person's brain's thoughts-thinking. It took me along time to make sense of what Pertex' was even doing in~with his combat code, it took me awhile just to make sense of his code structure~design so that I could just follow~read it properly, let alone actually understanding how the code worked, hehe.
I'm sure date~time~calender stuff is pretty basic programming, but I'm still very new to coding~programming, and so this is a challenge for me to code-logic understand and to figure it's design out... sighs.
-----------
actually, in the poor (yes, I know this can be coded better, maybe I can make something better if I keep working at it, but this is what I was able to do for now) coding that I have, these two functions are needed for it to work, and they're not exactly the same (take a closer look at them, in how they're needed for what is my coding design).
using the simple testing of plugging in numbers:
year = 0
a_function:
0 / 4 = 0 -> old_leap_year = 0 and new_leap_year = 0 + 4
year = 0
old_leap_year = 0
new_leap_year = 4
-----------------
year = 4
a_function:
4 / 4 = 1 -> old_leap_year = 4 and new_leap_year = 0 + 4
year = 4
old_leap_year = 4
new_leap_year = 8
-----------------
year = 8
a_function:
8 / 4 = 2 -> old_leap_year = 8 and new_leap_year = 0 + 4
year = 8
old_leap_year = 8
new_leap_year = 12
-------------------
year = 1
a_function:
1 / 4 = 0.25 -> b_function
b_function:
1 + 1 = 2
2 / 4 = 0.50 -> b_function
2 + 1 = 3
3 / 4 = 0.75 -> b_function
3 + 1 = 4
4 / 4 = 1
year = 1
+ "function resultant years"
NEW_leap_year = 4
year = 1
OLD_leap_year = 4 - 4 = 0
------------------
year = 5
a_function:
5 / 4 = 1.25 -> b_function
b_function:
5 + 1 = 6
6 / 4 = 1.50 -> b_function
6 + 1 = 7
7 / 4 = 1.75 -> b_function
7 + 1 = 8
8 / 4 = 2
year = 5
+ "function resultant years"
NEW_leap_year = 8
year = 5
OLD_leap_year = 8 - 4 = 4
--------
year = 7
a_function:
7 / 4 = 1.75 -> b_function
b_function:
7 + 1 = 8
8 / 4 = 2
year = 7
+ "function resultant years"
NEW_leap_year = 8
year = 7
OLD_leap_year = 8 - 4 = 4
---------
you're probably wondering why the "old_leap" matters if the "year" is already exceeding it....
remember that the "change" method that I'm using is this:
year = 0
old_leap = 0
new_leap = old_leap + 4
if (year = new_leap) {
-> old_leap = year
-> new_leap = old_leap + 4
}
as this allows me do the easy incrementing of the leap years by "new_leap = old_leap + 4", and also to be able to use "if year = leap_year, then days in february = 29 and days in year = 366, else days in february = 28 and days in year = 365"
----------
err... used my memory... I was off by one day... argh!
my bad memory: 364 and 365
correct: 365.25 -> 365 and 366 (every 4th year ~ 29 days in february instead of 28)
----------
ya, it's ugly and messy... but unless I'm missing or over-looking something obvious, it should work... lol
----------
I figured that the "%" could be used too, but I was hoping that the "ToInt" and~or "ToDouble", could do the same job... so, can they or not?
---------
all this work on my part....
Jayna wrote:Yes, I wrote some calendar code once...)
old_leap_year = year - (year % 4)
new_leap_year = old_leap_year + 4
I'm depressed... I should quit trying to code... lol (j/k, THANK YOU jayna!, I'm learning bit by bit, lol, of coding and of coding better, from you, hehe)
(I really need to get a better comprehension of the "%"... I understood it... but not how to apply it beyond its definition... it never occured to me to do this: year - year % 4, ARGH!)
I do think my code works... but it sure is the "long ways" of doing your quick and simple:
old_leap_year = year - (year % 4)
new_leap_year = old_leap_year + 4
though my code finds the new_leap_year and then subtracts to get the old_leap_year, the reverse of yours
don't worry about trying to follow my code, as I know how hard it is to follow others' processii of code, math equations, and~or just another person's brain's thoughts-thinking. It took me along time to make sense of what Pertex' was even doing in~with his combat code, it took me awhile just to make sense of his code structure~design so that I could just follow~read it properly, let alone actually understanding how the code worked, hehe.

jaynabonne
30 Dec 2013, 18:53I'm glad you're not depressed. lol. As you say, it's all about learning, and we're all doing that.
Mod (%) can be useful, especially for determining if something is evenly divisible. What it also gives you (as used above) is how far off you are from being evenly divisible. If the mod returns 2, for example, then the number is 2 above being evenly divisible. If that makes sense... It's like the extra bit left over after dividing evenly.
Anyway, I'm glad to help, and I hope it all works out.
Mod (%) can be useful, especially for determining if something is evenly divisible. What it also gives you (as used above) is how far off you are from being evenly divisible. If the mod returns 2, for example, then the number is 2 above being evenly divisible. If that makes sense... It's like the extra bit left over after dividing evenly.
Anyway, I'm glad to help, and I hope it all works out.

HegemonKhan
30 Dec 2013, 22:36well, if there wasn't the "%~mod" function, there's my two functions, which should~could work, with a little more code with finishing them up and also some tinkering of it as well (if the "IsInt" and~or "IsDouble doesn't work, I'd have to craft code for it... I can do this, I should be able to anyways, but it would be even more added coding... laughs).
depressed was the wrong word... jealous~envious is a more accurate word, laughs. At least now, I'm finally aware of just how powerful~useful the "%~mod" is, as it can be used~applied for doing lots of things, including what I was trying to do here, lol.
I am aware now of the great utility of these:
1. if (expression) { script }
2. object.attribute = value_or_expression
3. %~mod (division and its remainder)
depressed was the wrong word... jealous~envious is a more accurate word, laughs. At least now, I'm finally aware of just how powerful~useful the "%~mod" is, as it can be used~applied for doing lots of things, including what I was trying to do here, lol.
I am aware now of the great utility of these:
1. if (expression) { script }
2. object.attribute = value_or_expression
3. %~mod (division and its remainder)