Time and Date Coding: a Syntax~Format Question

HegemonKhan
I'm going to take a stab at 'date and time' coding again (as it seems to be one of the foundational systems for many of the rest of your game's systems), so in research on it, as best as I've been able to find and understand, in terms of accuracy of it:

http://en.wikipedia.org/wiki/Leap_year

in the reading of ...

wiki wrote:Algorithm:

The following pseudocode determines whether a year is a leap year or a common year in the Gregorian calendar (and in the proleptic Gregorian calendar before 1582). The year variable being tested is the integer representing the number of the year in the Gregorian calendar, and the tests are arranged to dispatch the most common cases first. Care should be taken in translating mathematical integer divisibility into specific programming languages.

if (year is not divisible by 4) then (it is a common year)
else
if (year is not divisible by 100) then (it is a leap year)
else
if (year is not divisible by 400) then (it is a common year)
else (it is a leap year)


... , this is accurate for AD years, but for BC years, some alteration is needed (absolute_year_used_in_algorithm = BC_year - 1, maybe?):

1 AD -> common
0 AD (or 0 AD = 1 BC: ???) -> leap
1 BC (or it's 2 BC: ???) -> common

so for BC, do I need to do this (and~or is it the correct equation):

year_used_in_algorithm = AbsoluteOf (BC_year - 1) // or is it possibly: BC_year - 2, as I really hate math! :evil:

--- all my 'AbsoluteOf' means~refers to, is that we just ignore the negative value that given to BC years, as it's not important for the algorithm

???

----------

anyways, my quest syntax question:

can I do this:

if (not IsInt (year_integer / 4)) {
year_type = "common"
} else if (not IsInt (year_integer / 100)) {
year_type = "leap"
} else if (not IsInt (year_integer / 400)) {
year_type = "common"
} else {
year_type = "leap"
}


or do I need to do this instead:

(HK edit: removed the quotes on 'true~false', thank you Jay for spotting this mistake of mine!)

if (IsInt (year_integer / 4) = false) {
year_type = "common"
} else if (IsInt (year_integer / 100) = false) {
year_type = "leap"
} else if (IsInt (year_integer / 400) = false) {
year_type = "common"
} else {
year_type = "leap"
}


or, are both of these formats incorrect of the given algorithm from the wiki ???

jaynabonne
Of those two, I'd prefer the former. If you use the latter, you wouldn't have false in quotes.

The other way to do it (which is clearer to me, but I'll admit might not be for others) is to use mod instead. Something like:


<function name="IsDivisible" parameters="n,divisor" type="boolean">
return (n % divisor = 0 )
</function>

Then:

if (not IsDivisible(year_integer, 4)) {
year_type = "common"
} else if (not IsDivisible(year_integer, 100)) {
year_type = "leap"
} else if (not IsDivisible(year_integer, 400)) {
year_type = "common"
} else {
year_type = "leap"
}

Make it as readable as possible (to avoid errors or sanity issues when you look back on the code months from now).

jaynabonne
Regarding BC, I'd say implement it if you need it. No sense in pulling your hair out over stuff you won't ever use if not.

If you are going to go that far back, then beware that in September 1752, eleven days were dropped from the calendar when the switch was made from the Julian to the Gregorian calendar.

Silver
Way above my head all of that. Are you building a time machine, HK? :lol:

HegemonKhan
ya... I've created twisting dual wormholes (warped space) (though to produce this effect, if we had the technology, still probably would require more energy than exists in the universe ~ it doesn't solve the energy problem), ultra-magnetic shielding, went back in time, becoming the husband of my great great great grandmother (ie impregnating her), thus creating my family tree of future generations (though this is ignoring that you'd just be creating a new separate time line branch, stuck in it, and thus unable to go back to your own time line, which would thus mean you never went back in time to begin with, thus not impregnating your great great great grandmother, thus meaning that you never would have existed to begin with: the HK's 'beyond the grandfather paradox', hehe) ... laughs :D

oh... we're not really talking about time travel... hehe :wink:

P.S.

actually, speaking of 'Time Machines', this 'old' (2002) movie adaptation of H.G. Well's 'The Time Machine', actually is pretty good (except it got stupid with the lame but timeless hollywood love of tribals against a more tech-advanced "evil war-ish culture enemy', sighs. hollywood's 'avatar' syndrome):

http://www.imdb.com/title/tt0268695/?ref_=nv_sr_1

--------

I think I understand your preferred method Jay, but the math+code (of what you're doing) is just a bit too difficult for me to grasp, so I'll just stick with my 'IsInt', as it is an already 'built-in' check for the divisions, and finally I get to say back to~at Jay: "No need to re-invent the wheel", as he often says to me, as I usually try to craft my own code, trying not to directly copy others code (well I use their structure ~ as I'm not good enough with code to figure out my own structural way of doing things, this is advanced coding ~ having good knowledge of code methods to know how to create your own structure~design of code for doing something, but I otherwise try to do it my own way as much as is possible).

-------

If I do try to make a calender system... it'll be much more simple... and even a simple calender system might be way far too advanced for me to do anyways. I'll see what I can do... first I got to see if I can get the basic time and date stuff working (which I was having trouble with long ago when I was trying t do this priorly).

---------

nah, I'm just revisiting time and date coding (I tried this long before you showed up, but I messed up on the scripting and couldn't figure out how to get it to work, well, I'm trying again, seeing if I can get it to work this time, as I'm getting sick of working on just character creation, and to do any other system in the game, I really need to get a time and date system implemented first, as many systems rely directly or indirectly upon it)

Silver
It sounds complicated, not least because if you have seasons etc then you'll need dynamic descriptions for everything covering times of day and climate. Well that's based on the real world (or the UK specifically), I suppose it could all exist in a frozen/desert world with a static climate so you'd just be dealing with night and day.

Silver
But then if it existed in a fantasy world, then surely you could devise your own calendar also.

HegemonKhan
creating my own unique world is much harder (for me anyways), than using what already exists with our real world.

And, I will be using seasons, I want to make a full time and date system, for people to use (if I succeed at it ~ lol, I'll make it as a library for anyone to use for their games). Pixie got his~her 'Clock Library', but my ambition is a bit more than what it provides, and 'm still having trouble understanding how it works (the way Pixie does it is still too advanced for me to understand how it works), so I'm trying to create my own code.

jaynabonne
If mod is too much, then just change it to this:

<function name="IsDivisible" parameters="n,divisor" type="boolean">
return (IsInt(n, divisor))
</function>

They're actually equivalent, and the IsInt approach may be clearer.

I'd still keep the usage of the isDivisible function to hide that messy detail and make the main code more readable and understandable.

Silver
HegemonKhan wrote:creating my own unique world is much harder (for me anyways), than using what already exists with our real world.


I don't know why. No leap year shenanigans, or missing dates when it changed from bob to whatshisname (! you're a fountain of knowledge, Jay).

There's ten months in a year. There's twenty days in a month. There's twenty hours in a day. You see where I'm going? Simple maths (it's plural in UK English for some reason, I guess because Mathematics is plural :P ) and then you create your own lore, which names the months etc.

HegemonKhan
well, truth be told, it's also for just coding practice (err, challenge~project), for me, too ;)

it's a good next step for me in trying to get better at coding, via trying to tackle real world 'time and date' coding, as indeed there is some complex (for me) coding issues with it to solve.

----------

besides... we Americans, like our Norse math (base 12), and hate modern world's metric (base 10), and quite frankly, actually base 12 *IS* extremely practical:

3 and 4 (factors of 12), is much more useful than 2 and 5 (factors of 10), hehe :D

astronomy+time: basically anything with a curve or angle, as angles~degrees around a circle is 360, which 12 is a factor of, and probably a ton more practical uses too. Metric isn't as useful~great as it seems when you actually explore into the more important uses of physical (geometry+) mathematics.

Besides, what's the big deal with doing a conversion anyways, just look up what the conversion is (if you can't remember them), easy (you're not making the equation any harder by having to convert units).

--------

@Jay:

thanks Jay, I think I mostly get it now, just not quite able to grasp how the 'boolean_return (year % n = 0) -> if (IsDisible (year, n))' corresponds to checking in-whether it is an integer or double resultant value.

nevermind... I just finally comprehended how it works, lol... my brain though isn't quite at this level of thinking... as I finally just got it... lol:

if (remainder = 0), then (IsDivisble = true)

took me a long time to just now figuring this out, lol. (still a bit outside of my brain's intelligence level, as I got to think really hard to understand it, lol)

Silver
Fair dos - as a coding exercise that totally makes sense. I should push myself like that. However, I'm learning stuff on a need-to-know basis. Which won't make me a coding mastermind anytime soon, but will get my game finished a bit quicker. I do read all the other threads though ( I've read every single one dating back to last April, presently ) because I'm interested in what Quest can do in terms of things I haven't thought of.

HegemonKhan
ach... I forgot the big hurdle of why I quit trying this... lol

the big hurdle is trying to deal with what day it is (mon,tues,wed,thurs,fri,sat,sun) upon switching months via an increase in days ... I have no idea how to figure this out... I guess I could do it.. but it would be super simple and thus uber uber uber ugly. I'm more stuck with the needed math method of a design~formula~equation, which the code design is based upon, then with the coding itself, laughs. I really hate math! :evil:

ya, it is day 1 of the month, but what day (mon, tues, etc) is that ??? I'd need to figure out a starting point using an existing calender, example: 3-1-15 = mon, okay... but now I need the math formula for determining every other day, as to what day (mon, tues, wed, etc) it is, lol...

I really have a huge amount of appreciation of how we're able to take for granted 'date and time' on our devices... some really smart person figured out how to do it (math+code) for us... lol.

I guess it's back to research, to try to find this math equation~formula~algorithm or method of calender creation (on this date, it is 'mon', for example)

sighs... maybe... I need to put 'time and date' off, as this is a bit too advanced for me... need to try to move on to doing other easier things first... like maybe a combat system, magic system, item~inventory system, skills~perks~abilities system, level up system, pedia system, or whatever... I forgot how complex and advanced time and date was... lol.

I use a String Dictionary for the calender itself... but that's once I figured out what days are what... I guess I could just use an existing calender and plug in the data, but that would take a really long time and a lot of work... depending on how much time passes in game... laughs. That's why I need the math formula... as it's totally unpractical to manually plug in all the data...

jaynabonne
Have you taken a look at this?

http://en.wikipedia.org/wiki/Determinat ... f_the_week

There are some simple methods toward the bottom (one is a three line C function) that could be easily adapted to Quest. Of course, they only apply after 1752...

HegemonKhan
laughs, thank you for saving me the time of trying to find~research for the documentation, laughs. Now... as to whether I'm going to be able to understand this... and code it in... is another matter... hehe. First... I need to read it though... lol.

I'll never be scared of any coding again (coding is so simple compared to) ... just looking at all this math... SCARY, SO SCARY, HK pees in his pants, SCARED !!!!, laughs.

Coding with no math involved~required = WONDERFUL
Coding with math involved~required = AWFUL, HK hates math! :evil:

Silver
HK, I'm sure you have your own reasons, and your enthusiasm is encouraging, but why do you want to shoot to this level of coding? If days matter to your game there's other ways of doing it. But I suspect it's the least important thing for people wanting to play interactive fiction. Did you read the wiki article on Suspension of Disbelief? Nobody questioned or cared why Rambo's bullets never ran out, or why Superman can fly. They'd be even less bothered about what the clock says.

HegemonKhan
it would have in-game usage (for examples: day vs night events, when shops are open, dynamic NPCs moving around, weather, spell + skills duration, game world events like a town getting destroyed or taken over or a new town built hehe, etc etc etc), though this is for an ambitious TES RPG that I'll never ever make, lol. It's really just about learning right now as much as I can (and maybe slowly getting at least some simple RPG made and playable, lol).

I just want to learn and get practice with making (coding) the RPG elements~aspects, so that I've learned the tools (coding designs) for making some level of a TES RPG.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums