Date, Time, Age, and a way to use "At Every X Years" Coding

HegemonKhan
25 Nov 2013, 02:12
here's some coding work of mine, as I work on time and date (and etc like things, and other things entirely too):

I'll update this thread, as I am able to work more on this (I'll be very busy for about 2 weeks with RL stuff: school~work~etc, but after that I'll hopefully have time to continue to work on this stuff).

1. I haven't yet tested this, but if any of you want to look at this to see if it would (or is close to being able to) work, and let me know if there's any problems with it's design in terms of coding, I'd be appreciative. Specifically, I am interested in knowing whether my "At Every X Years" ("every 4th year") coding stuff is crafted in a way that it'll work, as this took some thought on my part (lol), and so, I hope it'll be able to work! Let me know if I'm on the right track, if it can be done in a better way, or if I'm completely off track in designing my code for the stuff I'm attempting to craft.

2. also, I'm posting this for others (coding "noobs") to look at too, for them to see how to do things (or give them ideas of their own), crossing my fingers that this code design of mine can work, but even if not, I think it still provides some aspects to help out people with coding. Basically as an open source of my own feeble code work at doing date, time, age, "at every x years", and etc things in code.

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d83ba5bb-2e3c-4f31-80c9-3e88a2dc082c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<start type="script">
every_fourth_year_function
character_creation_function
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="character_object_type" />
<date_of_birth_integer type="string">"DoB: " + player.month_of_birth_integer + "/" + player.day_of_birth_integer + "/" + player.shortened_year_of_birth_integer</date_of_birth_integer>
<date_of_birth_string type="string">"DoB: " + player.month_of_birth_string + " " + player.day_of_birth_integer + ", " + player.year_of_birth_integer</date_of_birth_string>
</object>
</object>
<object name="global_data_object">
<inherit name="editor_object" />
<month_integer type="int">11</month_integer>
<day_integer type="int">24</day_integer>
<year_integer type="int">2013</year_integer>
<every_fourth_year_integer type="int">2012</every_fourth_year_integer>
<execution_count_integer type="int">0</execution_count_integer>
<every_fourth_year_string_list type="simplestringlist">2012</every_fourth_year_string_list>
<months_of_the_year_string_list type="simplestringlist">january;february;march;april;may;june;july;august;september;october;november;december</months_of_the_year_string_list>
<month_conversion_string_dictionary type="simplestringdictionary">january=1;1=january;february=2;2=february;march=3;3=march;april=4;4=april;may=5;5=may;june=6;6=june;july=7;7=july;august=8;8=august;september=9;9=september;october=10;10=october;november=11;11=november;december=12;12=december</month_conversion_string_dictionary>
<days_of_the_week_string_list type="simplestringlist">sunday;monday;tuesday;wednesday;thursday;friday;saturday</days_of_the_week_string_list>
<day_conversion_string_dictionary type="simplestringdictionary">sunday=1;1=sunday;monday=2;2=monday;tuesday=3;3=tuesday;wednesday=4;4=wednesday;thursday=5;5=thursday;friday=6;6=friday;sunday=7;7=sunday</day_conversion_string_dictionary>
<31_days_in_a_month_string_list type="siimplestringlist">1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31</31_days_in_a_month_string_list>
<30_days_in_a_month_string_list type="siimplestringlist">1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30</30_days_in_a_month_string_list>
<29_days_in_a_month_string_list type="siimplestringlist">1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29</29_days_in_a_month_string_list>
<28_days_in_a_month_string_list type="siimplestringlist">1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28</28_days_in_a_month_string_list>
</object>
<function name="character_creation_function"><![CDATA[
firsttime {
msg ("What is your name?")
get input {
player.alias = result
msg ("What is your age?")
get input {
player.age_integer = ToInt (result)
if (player.age_integer < 0) {
player.age_integer = 0
}
if (player.age_integer >= 0 and player.age_integer < 4) {
player.age_string = "baby"
} else if (player.age_integer >= 4 and player.age_integer < 13) {
player.age_string = "child"
} else if (player.age_integer >= 13 and player.age_integer < 20) {
player.age_string = "teen"
} else if (player.age_integer >= 20) {
player.age_string = "adult"
}
msg ("What is your date of birth?")
show menu ("Month of birth?", global_data_object.months_of_the_year_string_list, false) {
player.month_of_birth_string = result
player.month_of_birth_integer = ToInt (StringDictionaryItem (global_data_object.month_conversion_string_dictionary, player.month_of_birth_string))
if (player.month_of_birth_string = "january" or player.month_of_birth_string = "march" or player.month_of_birth_string = "may" or player.month_of_birth_string = "july" or player.month_of_birth_string = "august" or player.month_of_birth_string = "october" or player.month_of_birth_string = "december") {
show menu ("Day of birth?", global_data_object.31_days_in_a_month_string_list, false) {
player.day_of_birth_integer = ToInt (result)
}
} else if (player.month_of_birth_string = "april" or player.month_of_birth_string = "june" or player.month_of_birth_string = "september" or player.month_of_birth_string = "november") {
show menu ("Day of birth?", global_data_object.30_days_in_a_month_string_list, false) {
player.day_of_birth_integer = ToInt (result)
}
} else if (player.month_of_birth_string = "february") {
foreach (item_x, global_data_object.every_fourth_year_string_list) {
item_x_integer = ToInt (item_x)
if (global_data_object.year_integer = item_x_integer) {
show menu ("Day of birth?", global_data_object.29_days_in_a_month_string_list, false) {
player.day_of_birth_integer = ToInt (result)
}
} else if (global_data_object.year_integer <> item_x_integer) {
show menu ("Day of birth?", global_data_object.28_days_in_a_month_string_list, false) {
player.day_of_birth_integer = ToInt (result)
}
}
}
}
on ready {
msg ("Year of birth?")
get input {
player.year_of_birth_integer = result
if (player.year_of_birth_integer >= 2000) {
player.shortened_year_of_birth_integer = player.year_of_birth_integer - 2000
} else if (player.year_of_birth_integer < 2000) {
player.shortened_year_of_birth_integer = player.year_of_birth_integer - 1900
}
}
}
}
}
}
} otherwise {
}
]]></function>
<function name="every_fourth_year_function"><![CDATA[
if (global_data_object.execution_count_integer < 26) {
global_data_object.every_fourth_year_integer = global_data_object.every_fourth_year_integer + 4
list add (global_data_object.every_fourth_year_string_list, global_data_object.every_fourth_year_integer)
global_data_object.execution_count_integer = global_data_object.execution_count_integer + 1
every_fourth_year_function
}
]]></function>
<type name="character_object_type">
<age_integer type="int">0</age_integer>
<age_string type="string"></age_string>
<month_of_birth_string type="string"></month_of_birth_string>
<month_of_birth_integer type="int">0</month_of_birth_integer>
<year_of_birth_integer type="int">0</year_of_birth_integer>
<shortened_year_of_birth_integer type="int">0</shortened_year_of_birth_integer>
<day_of_birth_integer type="int">0</day_of_birth_integer>
<date_of_birth_integer type="string"></date_of_birth_integer>
<date_of_birth_string type="string"></date_of_birth_string>
</type>
</asl>


and here's my source that I am using:

http://uk.answers.yahoo.com/question/index?qid=20080710034216AA8yyPP

MJ user:

There are 365.25 days in a year.
365 in a non leap year and 366 in a leap every (every fourth year there is a 29th day in February)

We say 52 weeks because it's convenient even though it does only account for 364 days. Missing 1 day in a normal year and 2 days in a leap year. If you count up the days in all the months of a non leap year you will see there are 365

Jan 31
Feb 28
Mar 31
Apr 30
May 31
Jun 30
Jul 31
Aug 31
Sep 30
Oct 31
Nov 30
Dec 31

Equals 365 :)


The Pixie
25 Nov 2013, 08:08
Quest will not accept your code. You have four elements that have tag names beginning with numbers (31_days_in_a_month_string_list, etc.) and two objects with identical names (the error message does not say what that name is, so I wuill leave you to track down that one).

If it was me, I would get today's date first using JavaScript (see here and for example here), and ask for the year of the date of birth first (leap year if year % 4 = 1), then the month, and then the date. You can then calculate the player's age.

HegemonKhan
26 Nov 2013, 02:20
thanks for looking over my code, Pixie!

oops on the numbers, that can be easily dealt with (changed). Trying to remember that I can't use numbers first... that's more of a problem for me, lol.

two names used, that can be easily fixed too (hopefully easy to find, as my code isn't verbose at all, just got to spot it, lol).

I haven't started using~learning JS yet (even this inline parser stuff is a bit scary to me, lol), but I'll take a look at your links.

argh, I never even thought of using the % symbol for the 4th~leap year number...

----------

(I know my coding isn't complete nor without mistakes~problems, I just wanted to get this checked over before I do more)

(your clock library coding makes this look so easy to do... sighs, lol. I'd love to be able to see how computers' code looks for the date and time... it'd be really helpful. I've got a ton of appreciation for your clock library coding, and for computers' time and date coding as well)

though can~does my "every_fourth_year_function" work to do this as well? Can it generate the : 2012, 2016, ... x25 ..., 2212, and then from+with that, can this then work too:

} else if (player.month_of_birth_string = "february") {
foreach (item_x, global_data_object.every_fourth_year_string_list) {
item_x_integer = ToInt (item_x)
if (global_data_object.year_integer = item_x_integer) {
show menu ("Day of birth?", global_data_object.29_days_in_a_month_string_list, false) {
player.day_of_birth_integer = ToInt (result)
}

The Pixie
26 Nov 2013, 08:45
Here is some JavaScript:

function getDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
var date_today = "" + yyyy + ";" + mm + ";" + dd
ASLEvent("AskDOB", date_today);
}


That needs to go into its own file, say functions.js, which you add to your game via Advanced - JavaScript in the right pane. You call the function with e request script command, and the function then calls a Quest function called AskDOB. Here is an example of it in use:

<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="getdate">
<gameid>d914cd9d-e46b-49da-88c5-bc637a4a4bca</gameid>
<version>1.1</version>
<firstpublished>2013</firstpublished>
<months_of_the_year_string_list type="stringlist">
<value>january</value>
<value>february</value>
<value>march</value>
<value>april</value>
<value>may</value>
<value>june</value>
<value>july</value>
<value>august</value>
<value>september</value>
<value>october</value>
<value>november</value>
<value>december</value>
</months_of_the_year_string_list>
<start type="script">
request (RunScript, "getDate")
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<function name="AskDOB" parameters="date_today"><![CDATA[
date_list = Split (date_today, ";")
year = ToInt (StringListItem (date_list, 0))
month = ToInt (StringListItem (date_list, 1))
day = ToInt (StringListItem (date_list, 2))
msg ("It is " + year)
msg ("What year were you born?")
get input {
player.year_of_birth = ToInt (result)
msg ("You are " + (year - player.year_of_birth) + " years old (or will be soon).")
show menu ("Month of birth?", game.months_of_the_year_string_list, false) {
player.month_of_birth = ListIndexOf (game.months_of_the_year_string_list, result) + 1
msg ("What was the day of the month you born?")
get input {
player.day_of_birth = ToInt (result)
msg ("Your DOB is " + player.day_of_birth + "/" + player.month_of_birth + "/" + player.year_of_birth + ".")
if (player.month_of_birth = month) {
msg ("Your birthday is this month!")
if (player.day_of_birth = day) {
msg ("It is your birthday today!")
}
else if (player.day_of_birth > day) {
msg ("It is your birthday very soon!")
}
else {
msg ("You've just had your birthday!")
}
}
else if (player.month_of_birth > month) {
msg ("You have already had your birthday.")
}
else {
msg ("You have not had your birthday yet.")
}
}
}
}
]]></function>
<function name="ListIndexOf" parameters="list, thing" type="int">
res = -1
for (i, 0, ListCount (list) - 1) {
if (ListItem(list, i) = thing) {
res = i
}
}
return (res)
</function>
<javascript src="functions.js" />
</asl>