RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Issue with TimeClock, Can someone Help? :)

Ravenal

Knight
so this would be correct?


PHP:
else if ( hours <= 0 && hours >= 0 )
			{
				day += 1;
			}
			worldTime = String.Format( "{0}/{1}/{2} B.T.", month, day, year );
			//worldTime = String.Format( "Disabled" );

			hours %= 12; 

            if ( hours == 0 ) 
            { 
                hours = 12; 
            } 
			int actualhours = hours % 24;
             
            clockTime = String.Format( "{0}:{1} {2}", hours, minutes, actualhours >= 12 ? "R.C." : "F.C." );
			//clockTime = String.Format( "Disabled" );
		}
 
It could be, if you weren't making hours do double duty.

I suggest you go through each part of the code and ask yourself what each variable's purpose is. If at any point you get different answers for the same variable then you need to rewrite at least that part of the code.
 

Ravenal

Knight
*feels if lecture* I hate it lol....

Anyway umm i am a visual person not a thinker :p Sorry.... Umm...

Can or there away you can show me what you mean as point out what my errors are causing, cuz basically i want it to be say 1/1/2000 AD....

when the hour hits Midnight it goes 1/2/2000 and then it stays there

And when it hits Midnight it changes to AM not PM Staying there PM all the time...
 
The problem is caused by the fact that you don't know what you want the variables to do. I suggest you write down what you want the variables to do, trace through the code, and find out where the variables are not doing what you want them to do.
 

Ravenal

Knight
either i am not understanding you or something, but I am a person of VISUAL i need to see what i am doing wrong, and how they work, if i don't i can't learn....

To see what i mean, i am getting books, i read them and see pictures of examples, This is how i learned, thats how i learned HTML and all the other stuff of C#, I learned by looking at other scripts and how they compile and work... If i don't see i can't learn.... :(
 

Ravenal

Knight
Okay now for this...

PHP:
hours %= 12; 

            if ( hours == 0 ) 
            { 
                hours = 12; 
            } 
	int actualhours = hours % 24;

I noticed how the if ( hours == 0 )


Then put hours = 12; making it 12 and hours %= 12; what that really mean?

so if i do....

actualhours = hours % 24; what does that really do??? i am just wondering..
 
:)

The fact that you can't even begin to describe what that code does is a fairly good indicator that it's wrong.

My suggestion is to come up with a basic set of goals for the code to accomplish and work from there. I understand thet you're visual, but programming usually isn't.
 

Ravenal

Knight
true :p

Let me think over it and see what i can do :p

but first can you tell me what this does?

PHP:
hours %= 12; 

            if ( hours == 0 ) 
            { 
                hours = 12; 
            } 
    int actualhours = hours % 24;
 
The % is the modulus operator. For two integers x and y, it does x / y and returns the remainder. So 3 % 2 is 1, 10 % 4 is 2, and so on.

So, what your code does is:

1) Takes the modulus of hours and 12 and assigns it to hours,

2) If hours equals 0 then it assigns 12 to hours, and

3) Assigns the modulus of hours and 24 to a newly-declared variable called actualhours.

No, that doesn't sound right for keeping time, does it?
 

Ravenal

Knight
okay so it should be this....

PHP:
int actualhours = hours % 24;
			hours %= 12;

			if ( hours == 0 )
				hours = 12;
             
            clockTime = String.Format( "{0}:{1} {2}", hours, minutes, actualhours >= 12 ? "R.C." : "F.C." );

when i took out this

PHP:
hours %= 12;

			if ( hours == 0 )
				hours = 12;

it showed the real R.C. so i am guessing I need to put the hours %= 12; after the 24 one...
 

Ravenal

Knight
Ignacio Vazquez-Abrams said:
The % is the modulus operator. For two integers x and y, it does x / y and returns the remainder. So 3 % 2 is 1, 10 % 4 is 2, and so on.

So, what your code does is:

1) Takes the modulus of hours and 12 and assigns it to hours,

2) If hours equals 0 then it assigns 12 to hours, and

3) Assigns the modulus of hours and 24 to a newly-declared variable called actualhours.

No, that doesn't sound right for keeping time, does it?

Can i tell you that this step right here! MADE ME LEARN SOMETHING I NEVER LEARNED, THANK GOD! and So much, now that it works correct, but now the umm :CRIES: the Date, how would i apply this??? :GULP: umm i mean
 

Ravenal

Knight
okay whew, all that clock time thing works well, but 1 problem, I tried some things on the date thing...

PHP:
public static void WorldTime( Mobile from, out string worldTime, out string clockTime )
		{
			int hours;
			int minutes;
			Server.Items.Clock.GetTime(from.Map, from.Location.X, from.Location.Y, out  hours, out  minutes); 			
			int day = 41; // Default Day;
			int month = 10; // Default Month;
			int year = 22556; // You can change the year to whatever you want
			
			if ( month == 11 )
			{
				day = 1;
				month = 1;
				year -= 1;
			}	
			if ( day == 42 )
			{
				month += 1;
				day = 1;
			}
			if ( hours >= 0 )
			{
				day += 1;
			}
			
			//worldTime = String.Format( "{0}/{1}/{2} B.T.", month, day, year );
			worldTime = String.Format( "Disabled" );

Problem is now it will add it if the hour is above 0 then add 1 day to it, it successfully adds it, but now the problem is, I want it to go back if the player is in like for example 0 0 0 and the time is 11pm and the day is 10. If i go say 1000 1000 0 and it is 1am it should say that the day is 11 not 10... and when i go back to 0 0 0 location it goes back to 10, but the problem is it stays 11 now and doesn't return back to 10 before the problem was this...

if ( hours == 0 )
{
day += 1;
}

and when that i had that when i hit 1am it went back to 10, and when it hit between midnight to 1am, it would then go to 11, but when i go to 11am it goes to 10, it seems like if the hour is == 0 then give this day, if the hour is not that day then go back to normal, which makes sense... But it seems like i need to do hours is >= 0 then add the day, if the hour is <= 0 then it should go back to the normal day... What can i do to get this?
 
The problem is that in order to advance the date you need to have a before-and-after view of the time, which your code isn't doing. I recommend you take a look in Clocks.cs and deconstruct how it's being done in there.
 

Ravenal

Knight
if i change this

Code:
private static DateTime WorldStart = new DateTime( 1997, 9, 1 );

to this

Code:
private static DateTime WorldStart = new DateTime( 22548, 1, 1 );

what does it do??? in Clocks...

PHP:
using System;
using Server;

namespace Server.Items
{
	public enum MoonPhase
	{
		NewMoon,
		WaxingCrescentMoon,
		FirstQuarter,
		WaxingGibbous,
		FullMoon,
		WaningGibbous,
		LastQuarter,
		WaningCrescent
	}

	[Flipable( 0x104B, 0x104C )]
	public class Clock : Item
	{
		private static DateTime m_ServerStart;

		public static DateTime ServerStart
		{
			get{ return m_ServerStart; }
		}

		public static void Initialize()
		{
			m_ServerStart = DateTime.Now;
		}

		[Constructable]
		public Clock() : this( 0x104B )
		{
		}

		[Constructable]
		public Clock( int itemID ) : base( itemID )
		{
			Weight = 3.0;
		}

		public Clock( Serial serial ) : base( serial )
		{
		}

		public const double SecondsPerALMinute = 4;
		public const double MinutesPerALDay = SecondsPerALMinute * 24;

		private static DateTime WorldStart = new DateTime( 1997, 9, 1 );

		public static MoonPhase GetMoonPhase( Map map, int x, int y )
		{
			int hours, minutes, totalMinutes;

			GetTime( map, x, y, out hours, out minutes, out totalMinutes );

			if ( map != null )
				totalMinutes /= 10 + (map.MapIndex * 20);

			return (MoonPhase)(totalMinutes % 8);
		}

		public static void GetTime( Map map, int x, int y, out int hours, out int minutes )
		{
			int totalMinutes;

			GetTime( map, x, y, out hours, out minutes, out totalMinutes );
		}

		public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
		{
			TimeSpan timeSpan = DateTime.Now - WorldStart;

			totalMinutes = (int)(timeSpan.TotalSeconds / SecondsPerALMinute);

			if ( map != null )
				totalMinutes += map.MapIndex * 320;

			totalMinutes += x / 16;

			hours = (totalMinutes / 60) % 24;
			minutes = totalMinutes % 60;
		}

		public static void GetTime( out string generalString, out string exactTime )
		{
			GetTime( null, 0, 0, out generalString, out exactTime );
		}

		public static void GetTime( Mobile from, out string generalString, out string exactTime )
		{
			GetTime( from.Map, from.X, from.Y, out generalString, out exactTime );
		}

		public static void GetTime( Map map, int x, int y, out string generalString, out string exactTime )
		{
			int hours, minutes;

			GetTime( map, x, y, out hours, out minutes );

			// 00:00 AM - 00:59 AM : Witching hour
			// 01:00 AM - 03:59 AM : Middle of night
			// 04:00 AM - 07:59 AM : Early morning
			// 08:00 AM - 11:59 AM : Late morning
			// 12:00 PM - 12:59 PM : Noon
			// 01:00 PM - 03:59 PM : Afternoon
			// 04:00 PM - 07:59 PM : Early evening
			// 08:00 PM - 11:59 AM : Late at night

			if ( hours >= 20 )
				generalString = String.Format( "It's late at frusk *Night*" ); // It's late at night
			else if ( hours >= 16 )
				generalString = String.Format( "It's early in the dusk *Evening*" ); // It's early in the evening
			else if ( hours >= 13 )
				generalString = String.Format( "It's the Middawn *AfterNoon*" ); // It's the afternoon
			else if ( hours >= 12 )
				generalString = String.Format( "It's Noon *Noon*" ); // It's around noon
			else if ( hours >= 08 )
				generalString = String.Format( "It's rising to morrow *Morning*" ); // It's late in the morning
			else if ( hours >= 04 )
				generalString = String.Format( "It's early of Dawns *Early Morning*" ); // It's early in the morning
			else if ( hours >= 01 )
				generalString = String.Format( "It's the middle of frusk *Middle Night*" ); // It's the middle of the night
			else
				generalString = String.Format( "'Tis the chiming hour. 12 Midfrusk *Midnight*" ); // 'Tis the witching hour. 12 Midnight.

			hours %= 12;

			if ( hours == 0 )
				hours = 12;

			exactTime = String.Format( "{0}:{1:D2}", hours, minutes );
		}

		public override void OnDoubleClick( Mobile from )
		{
			string generalString;
			string exactTime;

			GetTime( from, out generalString, out exactTime );

			SendLocalizedMessageTo( from, 1042971, generalString );
			SendLocalizedMessageTo( from, 1042958, exactTime ); // ~1_TIME~ to be exact
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			if ( Weight == 2.0 )
				Weight = 3.0;
		}
	}

	[Flipable( 0x104B, 0x104C )]
	public class ClockRight : Clock
	{
		[Constructable]
		public ClockRight() : base( 0x104B )
		{
		}

		public ClockRight( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}

	[Flipable( 0x104B, 0x104C )]
	public class ClockLeft : Clock
	{
		[Constructable]
		public ClockLeft() : base( 0x104C )
		{
		}

		public ClockLeft( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
		}
	}
}
 
awakenlands said:
if i change this

Code:
private static DateTime WorldStart = new DateTime( 1997, 9, 1 );

to this

Code:
private static DateTime WorldStart = new DateTime( 22548, 1, 1 );

what does it do??? in Clocks...
It implodes your shard.

ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemDateTimeClassTopic.htm

Download and install the .NET 1.1 Framework SDK (see my sig), then open that URL in IE.
 
Top