% symbol explanation

HegemonKhan
I'm currently trying to work on learning+developing my own coding for time+date, and have looked at Pixie's Clock Library that uses the "%" (percent) symbol, but I don't quite understand what it exactly does (or how it's doing what it does).

The reason is that my coding is surely a lot more messy (big "if~switch" code chunks, lol) without being able to implement this "%" symbol, than if I were able to implement this "%" symbol into my coding.

I'm not sure how to google it either, as I don't know what programming language it falls under (or just which one Pixie is using for the "%" symbol in his~her Clock Library).

I tried searching for it, first using xml but its usage that I found and read about is not what I need, then I tried using javascript, and its usage returns the remainder from a division calculation. Is this what is being done in Pixie's Clock Library, or is there still some other programming language that uses the "%" symbol for whatever might be going on in Pixie's Clock Library?, since I can't quite realize what is going on with the "%" symbol just by looking at the code, as I'm not that great with understanding math stuff too, sighs.

So, if someone, could explain to me how the "%" symbol functions~does~works or what it is doing exactly in Pixie's Clock Library, I'd be very appreciative! And, also if you could tell me what programming language it is being used by (or which it belongs to ~ whatever), so I can google it myself in the future (should I need to) to re-learn it (if I forget or something, lol), I'd also be appreciative, as well. I don't want to try to google every single programming language to try to find which it belongs to or is being used by, lol~heh...

-----------

Pixie's Clock Library:

viewtopic.php?f=18&t=2580

<library>
<!--

A simple module that lets you track game time in your game.

Feel free to modify this code as you wish.

The Pixie
the_pix@hotmail.com

-->


<object name="game_clock">
<inherit name="editor_object" />
<time type="int">0</time>
<changedtime type="script">
if (HasString(player, "clock")) {
player.clock = TimeAsString()
}
</changedtime>
</object>
<command name="clock">
<pattern>clock</pattern>
<script>
msg ("You look at your watch: It's " + TimeAsString())
</script>
</command>
<turnscript>
<enabled />
<script>
if (game_clock.oldroom =player.parent){
IncTime (1)
} else {
IncTime (5)
game_clock.oldroom =player.parent
}
</script>
</turnscript>

<function name="PartOfDay" type="int">
tmp = game_clock.time % (60 * 24)
return (tmp / 60 / 6)
</function>
<function name="IsDusk" type="boolean">
hour = (game_clock.time / 60) % 24
return (hour = 18)
</function>
<function name="IsNight" type="boolean">
return (PartOfDay() = 0)
</function>
<function name="IsMorning" type="boolean">
return (PartOfDay() = 1)
</function>
<function name="IsAfternoon" type="boolean">
return (PartOfDay() = 2)
</function>
<function name="IsEvening" type="boolean">
return (PartOfDay() = 3)
</function>
<function name="BusinessExit" parameters="exit, time, opening">
if (IsBusinessClosed(opening)) {
msg ("That way is closed at this time of day.")
}
else {
MoveObject (player, exit.to)
IncTime (time - 1)
}
</function>
<function name="LongExit" parameters="exit, time">
MoveObject (player, exit.to)
IncTime (time - 1)
</function>
<function name="IsBusinessClosed" parameters="opening" type="boolean">
c = Mid(opening, PartOfDay() + 1, 1)
return (c = "n")
</function>
<function name="TimeAsString" type="string"><![CDATA[
minutes = game_clock.time % 60
hours24 = (game_clock.time / 60) % 24
hours = hours24 % 12
if (hours = 0) {
hours = 12
}
days = game_clock.time / (60 * 24) + 1
if (minutes < 10) {
s = "Day " + days + ", " + hours + ":0" + minutes
}
else {
s = "Day " + days + ", " + hours + ":" + minutes
}
if (hours24 < 12) {
return (s + " am")
}
else {
return (s + " pm")
}
]]></function>
<function name="IncTime" parameters="addendum">
game_clock.time = game_clock.time + addendum
</function>
<function name="GetTime" type="int">
return (game_clock.time)
</function>
</library>

jaynabonne
That is the "modulo operator", also known as "modulus operator", also known as the "mod operator" or just "mod". It returns the remainder after division (rather than the quotient).

Let's say you have an ever increasing number of hours. You can see how many days have passed by dividing by 24. And the remainder (which '%' calculates) is the current hour (0-23) in the current day:

days = hours / 24 (as an integer)
hour = hours % 24

Let's say 30 hours have elapsed. Then days would be 1, and hour (which is the remainder of 30 / 24) would be 6. So it would be 6AM one day hence.

You typically use mod where you have something cyclic, though it's not limited to that. Time is a good application, since seconds go from 0-59 and then repeat, minutes go from 0-59 and then repeat, hours go from 0-24, etc.

If 250 seconds had elapsed, that would be 4 minutes and 10 seconds. And 250 % 60 gives you the 10.

HegemonKhan
ah, thank you Jayna! So, Pixie's usage of the % symbol is doing the "operator modulo" (whatever, meh. I guess it's latin, but it sounds stupid, lol ~ so I don't like it, lol), the remainder functionality, and I presume this is using the javacript language, or are there multiple languages that use the % symbol as the modulo too?

the xml's usage had nothing to do with remainder functionality (operator modulo):

http://stackoverflow.com/questions/4414 ... ent-symbol

it uses the % symbol for some variable usage or something, I think... (haven't really read up on this too much yet): %a

<string formatted="false">%a + %a == 2%a</string>

I think the basic command line prompt on computers (run -> cmd.exe), also uses the % symbol in this same way as the xml, with something to do with variables (I have been trying to learn this "language", cmd.exe, as I figured I'd start with one of the simpliest for trying to learn another language, lol. Though, it's a bit too simplistic~limited and thus a bit of effort to learn to do stuff with it, on top of trying to decipher what the commands and their switches do, along with the correct syntax ~ format, GRRR!, lol. Looking at other programming languages makes me appreciate Alex' quest coding, in how noob-friendly it is! :D)

anyways, (was going off on a tangent, lol), thank you, as I now know it is indeed the modulo usage. Now, I just need to be able to follow how Pixie is using it in his~her Clock Library... it's used a bit more complex'ly... it'll take me awhile to get it... as I'm not that good with math stuff... heh.

I get it's math usage at the basic level (again thank you, for the very clear+concise explanations you give in your posts!):

days = hours / 24 (as an integer)
hour = hours % 24

starting_hours = 30
days = 1
hour = 6

it'll just take me a bit to understand the jump to how Pixie is using it... hehe. I wish I was better with math stuff... sighs.

-----------

and yes, this % symbol (operator modulo) will definately make the coding much cleaner, than my simplistic but large "if" script blocks, lol:

(I've just started on this stuff ~ before posting about how to use the % symbol... so this is very preliminary... below)

<library>

<!-- Libraries -->

<!-- Templates -->

<!-- Verbs -->

<!-- Commands -->

<!-- Functions -->

<!-- Turn Scripts -->

<turnscript name="global_events_turnscript"><![CDATA[
if (global_data_object.second_integer = 60) {
global_data_object.minute_integer = global_data_object.minute_integer + 1
global_data_object.second_integer = 0
}
if (global_data_object.minute_integer = 60) {
global_data_object.hour_integer = global_data_object.hour_integer + 1
global_data_object.minute_integer = 0
}
if (global_data_object.hour_integer = 24) {
global_data_object.day_integer = global_data_object.day_integer + 1
global_data_object.hour_integer = 0
}
if (global_data_object.day_integer >= 0 and global_data_object.day_integer < 7) {
global_data_object.week_integer = 0
} else if (global_data_object.day_integer >= 7 and global_data_object.day_integer < 14) {
global_data_object.week_integer = 1
} else if (global_data_object.day_integer >= 14 and global_data_object.day_integer < 21) {
global_data_object.week_integer = 2
} else if (global_data_object.day_integer >= 21 and global_data_object.day_integer < 28) {
global_data_object.week_integer = 3
}
switch (global_data_object.month_integer) {
case (0 or 2 or 4 or 6 or 7 or 9 or 11) {
if (global_data_object.day_integer = 31) {
global_data_object.month_integer = global_data_object.month_integer + 1
global_data_object.day_integer = 0
global_data_object.week_integer = 0
}
}
case (3 or 5 or 8 or 10) {
if (global_data_object.day_integer = 30) {
global_data_object.month_integer = global_data_object.month_integer + 1
global_data_object.day_integer = 0
global_data_object.week_integer = 0
}
}
case (1) {
if (global_data_object.day_integer = 28) {
global_data_object.month_integer = global_data_object.month_integer + 1
global_data_object.day_integer = 0
global_data_object.week_integer = 0
}
}
}
global_data_object.second_integer = global_data_object.second_integer + 1
global_data_object.global_turns = global_data_object.global_turns + 1
]]></turnscript>

<!-- Timers -->

<!-- Object Types -->

<!-- Attributes -->

<!-- Strings -->

<day_string type="string"></day_string>
<month_string type="string"></month_string>

<clock_time type="string">global_data_object.hour_integer + ":" + global_data_object.minute_integer + ":" + global_data_object.second_integer</clock_time>
<date_time type="string">global_data_object.month_integer + 1 + "/" + global_data_object.day_integer + 1 + "/" + global_data_object.year_integer</date_time>

<!-- Booleans -->

<!-- Integers -->

<global_turns type="int">0</global_turns>

<second_integer type="int">0</second_integer>
<minute_integer type="int">0</minute_integer>
<hour_integer type="int">0</hour_integer>

<day_integer type="int">0</day_integer>
<week_integer type="int">0</week_integer>
<month_integer type="int">0</month_integer>
<year_integer type="int">0</year_integer>

<!-- Doubles -->

<!-- Lists -->

<!-- String Lists -->

<months_of_the_year type="simplestringlist">january;february;march;april;may;june;july;august;september;october;november;december</months_of_the_year>
<days_of_the_week type="simplestringlist">monday;tuesday;wednesday;thursday;friday;saturday;sunday</days_of_the_week>

<!-- Object Lists -->

<!-- Dictionaries -->

<!-- String Dictionaries -->

<!-- Object Dictionaries -->

<!-- Script Dictionaries -->

<!-- Scripts -->

<!-- Inherited -->

<inherit name="editor_object" />

<!-- Objects -->

<!-- Objects -->

<!-- Data Objects -->

<object name="global_data_object">

<inherit name="editor_object" />

<global_turns type="int">0</global_turns>

<day_string type="string"></day_string>
<month_string type="string"></month_string>

<months_of_the_year type="simplestringlist">january;february;march;april;may;june;july;august;september;october;november;december</months_of_the_year>
<days_of_the_week type="simplestringlist">monday;tuesday;wednesday;thursday;friday;saturday;sunday</days_of_the_week>

<clock_time type="string">global_data_object.hour_integer + ":" + global_data_object.minute_integer + ":" + global_data_object.second_integer</clock_time>

<second_integer type="int">0</second_integer>
<minute_integer type="int">0</minute_integer>
<hour_integer type="int">0</hour_integer>

<date_time type="string">global_data_object.month_integer + 1 + "/" + global_data_object.day_integer + 1 + "/" + global_data_object.year_integer</date_time>

<day_integer type="int">0</day_integer>
<week_integer type="int">0</week_integer>
<month_integer type="int">0</month_integer>
<year_integer type="int">0</year_integer>

</object>

</library>


(and, now I can utilize the % symbol, or soon ~ it's still a bit complicated when you're trying to make a whole time+date system even while now understanding what is and how the % symbol works ~ anyways, hehe)

ya, see that big "if" turnscript script block? the % symbol is very much appreciated, lol :D Hopefully with enough ingenuity from myself, I can make that big "if" turnscript script block dissapear, hehe :D

HegemonKhan
yeah! the math inept (struggling) HK has finally understood how the % symbol usage works in Pixie's Clock Library, as seen by my feeble use of visual examples in understanding it, as seen below, lol:

MJ wrote:

Source:

http://uk.answers.yahoo.com/question/in ... 216AA8yyPP

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 [HK Edit: from 19th to 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
Sept 30
Oct 31
Nov 30
Dec 31

Equals 365 :)


<!-- My Own Notes -->

(putting this into~as code will be the easy part, lol. Whereas, understanding this stuff, was the hard part, ya I got it understood now but it took me a long time, I HATE MATH!, heh)

// (turns / 1) % 60 = seconds
// turns % 60 = seconds
// 000 % 60 -> 000 / 60 = 0 -> 0 x 60 = 000 -> 000 - 000 = 00
// 001 % 60 -> 001 / 60 = 0 -> 0 x 60 = 000 -> 001 - 000 = 01
// 059 % 60 -> 059 / 60 = 0 -> 0 x 60 = 000 -> 059 - 000 = 59
// 060 % 60 -> 060 / 60 = 1 -> 1 x 60 = 060 -> 060 - 060 = 00
// 061 % 60 -> 061 / 60 = 1 -> 1 x 60 = 060 -> 061 - 060 = 01
// 119 % 60 -> 119 / 60 = 1 -> 1 x 60 = 060 -> 119 - 060 = 59
// 120 % 60 -> 120 / 60 = 2 -> 2 x 60 = 120 -> 120 - 120 = 00
// 121 % 60 -> 121 / 60 = 2 -> 2 x 60 = 120 -> 121 - 120 = 01

// (turns / 60) % 60 = minutes
// 0059 / 60 = 00 -> 00 % 60 -> 00 / 60 = 0 -> 0 x 60 = 00 -> 00 - 00 = 00
// 0060 / 60 = 01 -> 01 % 60 -> 01 / 60 = 0 -> 0 x 60 = 00 -> 01 - 00 = 01
// 0061 / 60 = 01 -> 01 % 60 -> 01 / 60 = 0 -> 0 x 60 = 00 -> 01 - 00 = 01
// 0119 / 60 = 01 -> 01 % 60 -> 01 / 60 = 0 -> 0 x 60 = 00 -> 01 - 00 = 01
// 0120 / 60 = 02 -> 02 % 60 -> 02 / 60 = 0 -> 0 x 60 = 00 -> 02 - 00 = 02
// 0121 / 60 = 02 -> 02 % 60 -> 02 / 60 = 0 -> 0 x 60 = 00 -> 02 - 00 = 02
// 3599 / 60 = 59 -> 59 % 60 -> 59 / 60 = 0 -> 0 x 60 = 00 -> 59 - 00 = 59
// 3600 / 60 = 60 -> 60 % 60 -> 60 / 60 = 1 -> 1 x 60 = 60 -> 60 - 60 = 00
// 3601 / 60 = 60 -> 60 % 60 -> 60 / 60 = 1 -> 1 x 60 = 60 -> 60 - 60 = 00
// 3660 / 60 = 61 -> 61 % 60 -> 61 / 60 = 1 -> 1 x 60 = 60 -> 61 - 60 = 01

// hours_24 (military time)
// (turns / 3600) % 24 = hours_24
// 03599 / 3600 = 00 -> 00 % 24 -> 00 / 24 = 0 -> 0 x 24 = 00 -> 00 - 00 = 00 (midnight)
// 03600 / 3600 = 01 -> 01 % 24 -> 01 / 24 = 0 -> 0 x 24 = 00 -> 01 - 00 = 01 (am)
// 03601 / 3600 = 01 -> 01 % 24 -> 01 / 24 = 0 -> 0 x 24 = 00 -> 01 - 00 = 01 (am)
// 03660 / 3600 = 01 -> 01 % 24 -> 01 / 24 = 0 -> 0 x 24 = 00 -> 01 - 00 = 01 (am)
// 07200 / 3600 = 02 -> 02 % 24 -> 02 / 24 = 0 -> 0 x 24 = 00 -> 02 - 00 = 02 (am)
// 43200 / 3600 = 12 -> 12 % 24 -> 12 / 24 = 0 -> 0 x 24 = 00 -> 12 - 00 = 12 (noon)
// 82800 / 3600 = 23 -> 23 % 24 -> 23 / 24 = 0 -> 0 x 24 = 00 -> 23 - 00 = 23 (pm)
// 86400 / 3600 = 24 -> 24 % 24 -> 24 / 24 = 1 -> 1 x 24 = 24 -> 24 - 24 = 00 (midnight)
// 90000 / 3600 = 25 -> 25 % 24 -> 25 / 24 = 1 -> 1 x 24 = 24 -> 25 - 24 = 01 (am)

// hours_12 (civilian time)
// hours_24 % 12 = hours_12
// 00 % 12 -> 00 / 12 = 0 -> 0 x 12 = 00 -> 00 - 00 = 00 (midnight)
// 01 % 12 -> 01 / 12 = 0 -> 0 x 12 = 00 -> 01 - 00 = 01 (am)
// 11 % 12 -> 11 / 12 = 0 -> 0 x 12 = 00 -> 11 - 00 = 11 (am)
// 12 % 12 -> 12 / 12 = 1 -> 1 x 12 = 12 -> 12 - 12 = 00 (noon)
// 13 % 12 -> 13 / 12 = 1 -> 1 x 12 = 12 -> 13 - 12 = 01 (pm)
// 23 % 12 -> 23 / 12 = 1 -> 1 x 12 = 12 -> 23 - 12 = 11 (pm)
// 24 % 12 -> 24 / 12 = 2 -> 2 x 12 = 24 -> 24 - 24 = 00 (midnight)

// if (hours_24 = 12) {
// -> hours_12 = 12 (noon)
// } else if (hours_24 = 00) {
// -> hours_12 = 12 (midnight)
// }

// days_365 (day out of the year)
// (turns / (3600 x 24)) % 365 = days_365

// days_31 (day out of the months: January, March, May, July, August, October, and December)
// (turns / (3600 x 24)) % 31 = days_31

// days_30 (day out of the months: April, June, September, and November)
// (turns / (3600 x 24)) % 30 = days_30

// days_28 (day out of the month: February)
// (turns / (3600 x 24)) % 28 = days_28

// due to that a year is actually equal to 365.25 days
// for every 4th year, there's an extra (+1) day (or 29 days) in February
// days_29 (day out of the month: February)
// (turns / (3600 x 24)) % 29 = days_29


-------------------------

obviously, I'll use large increments of "turns", lol.

Or, I've even been thinking about using maybe a Timer instead for the "turns" attribute... if a Timer can count~add by seconds (I haven't really looked at Timers at all, except way back when I did the tutorial ~ which I can't remember about, lol)

also, how large of number sizes can quest handle? is there any limit upon a number's size?

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

Support

Forums