c# Having trouble getting my head around a loop

Posts 1–4 of 4 · Page 1 of 1
c# Having trouble getting my head around a loop
Im currently working on a relog program for a game(oldie but goodie) Ultima Online. I got the addies and things for the account input and im able to read/write data into them. Ive attempted trying to figure out this loop for a week now and im about to throw my arms up and say the heck with it. Im positive its something simple that im just over thinking. but anyway heres some details on what im trying to accomplish.

Assume the following:
5 accounts
7 characters per account.

Needs:
-Every Hour the following needs to happen.

--Log in First account.
---Log in first character and do something(takes 60secs) then log out(takes you back to account sign in).
----Log in First account again
-----Log in second character.
------Repeat for each character on account(7 total).

--Log in Second account
---Log in first character and do something(takes 60secs) then log out(takes you back to account sign in).
----Log into Second account again
-----Log in second character.
------Repeat for each character on account(7 total).

--Repeat the pattern for each account.

Dont need help with any of the code other then figuring out the loop required. Any help would be great, example snippits wonderful!.
I'm going to write a quick pseudo-code for you.
Hopefully you can read it, I don't know C# but I do know C++.

Code:
#include <time.h>

int main() {
  while (true) { //Loop forever
     clock_t timer = clock();
     int seconds = (clock()/CLOCKS_PER_SEC)-(timer/CLOCKS_PER_SEC);
     int minutes = seconds/60; //Divided by 60 because if 60 seconds pass, that is 1 minute. 
     int hours = minutes/60; //Same conclusion as above. 
     
     if (hours == 1) {
          //Do stuff
      } else if (hours == 2) {
          //Do stuff
       }
       //etc...
      if (hours == 1 && minutes == 0 && seconds == 0) {
           //Change account
       }
       //Could also check the above for each multiple of 1:0:0 (h:m:s) by doing::
       //if (hours%1 == 1 && minutes == 0 && seconds == 0) {
       //The above is explained by (if the hour is 1,2,3,4,5,... And minutes are 0, and seconds are 0 -- then do stuff
  }
}
Hopefully this helped and I understood your question correctly.
Let me know if I wasn't clear enough or didn't answer your question!

-Luna
Using Timers
you explaining in c++ is not a big deal. Was originally gonna code this in c++, but since VS13 does not support he creation of managed c++ Windows forms any longer i decided to just use Pinvoke for the required methods using c#.
The loops themselves im using Forms.Timer(), the reason really is that it allows me to update my GUI without running into Xthread Exceptions(system.timers require delegates and such).

I tryed using counters for both Accounts and Characters and keeping watch with if statements. Its not the 1hour timer giving me the problems, its the little timers like the 60 seconds between the character logins, then the approx 8 mins it takes per account to fully log in all 7 chars.

So i would say my real problem is Getting the 1hour timer, the 60sec timer and the 8 min timer to all work in sync(logging in on each account 7 times (once for each character) log a character in and out(60secs) later, then switching to second account and repeating.
Ok figured it out,Ii filled a Account array each account holding a bool Finished, and charIndexer. Instead of multiple timers i created a thread and used it to loop through all my chars on the account increasing charIdexer++, for each account in the array checking to see if CharIndexer = threshold(input by user), adding sleep() when required. As always i was over thinking it. One other problem i discovered in the mix was my Input Class i made was double clicking to fast had to set to 3/10 sec.

Ill be releasing this here in a little bit, dont expect anything because its just for those who play UO and want to "test" it. I Know its lacking and it takes up you mouse controll,(nothing is silent clicking yet. If anything test when your are sleeping ). But Ill be Adding to this as time allows. But the entire purpose was for Sleep Macroing.

FYI im not actually controlling the character with this yet(plan to later on), but I'm using UOSteam and running the macro through it.
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Talk with us