Conquer Club

A question for all you scriptwriters

Archival storage to keep things organized and uncluttered. Can't find what you need? Search for old topics here.

Moderator: Tech Team

Forum rules
Please read the Community Guidelines before posting.

Re: A question for all you scriptwriters

Postby Draconian_Intel on Mon Sep 01, 2008 12:19 am

Ok, I now have more questions.

Both Games Filter and Saved Searches have a function called
Code: Select all
function getElementsByClassName (oElm, strTagName, strClassName)
, and they both work surprisingly similar, with the same arguments and everything. I'm wondering if there is a library of common functions or anything like that where this might have come from. If not, then to the creators of those scripts, can I use that function?

Also in this same function, both scripts have the line:
Code: Select all
 var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s)");

but as far as I can tell, that variable is never used. I'm not really sure what a RegExp is, so if I'm missing something obvious please tell me. If it is just left over code from a previous version or something, then please let me know that as well.
Image
Corporal Draconian_Intel
 
Posts: 79
Joined: Sat Jun 21, 2008 11:00 pm

Re: A question for all you scriptwriters

Postby yeti_c on Mon Sep 01, 2008 2:41 am

getElementsByClassName is a function that I inherited from the original writer of BOB - since then I've tweaked it slightly too...

But you're more than welcome to use it - if you want the tweaked version - take it from BOB.

C.

- I'll let Chip explain about regexp's (or Regular Expressions).
Image
Highest score : 2297
User avatar
Lieutenant yeti_c
 
Posts: 9624
Joined: Thu Jan 04, 2007 9:02 am

Re: A question for all you scriptwriters

Postby Draconian_Intel on Mon Sep 01, 2008 4:08 pm

Ok, thanks yeti.
Image
Corporal Draconian_Intel
 
Posts: 79
Joined: Sat Jun 21, 2008 11:00 pm

Re: A question for all you scriptwriters

Postby Draconian_Intel on Tue Sep 02, 2008 9:10 pm

Ok, I changed my mind on what I was going to write, and so I am writing a script that changes the clock from how much time is left in the turn, to when the turn will end. It's pretty useless, just a way to practice my coding.

Anyway, I can't seem to figure out a certain bug, so after many hours of trying, I thought I would post it here to see if anyone with more experience could spot it. I don't have a way to host the script right now, so I will just put it here.
Code: Select all
// ==UserScript==
// @name           Conquer Club Clock Modifier
// @include        http://www.conquerclub.com/game.php?game=*
// ==/UserScript==

function extractTime (timeLeft, hoursLeft, minutesLeft, secondsLeft)
{
    var tempTimeLeft = timeLeft;
    var subTimeLeft = "";
    var spaceLocation = 0;
    var i = 0;

/*****
I believe I have identified the problem as two parts:
1. Replacing the line feeds (its line feed because the ASCII value is 10 when I use
   tempTimeLeft.charCodeAt();) in the clock string.
2. Seperating the string so that I can use parseInt() on them to get the clock values. (This
   might be solved with #1.
*****/

    tempTimeLeft.replace("\s","_");
alert(tempTimeLeft);
    spaceLocation = tempTimeLeft.indexOf("_");
alert(tempTimeLeft);
    for(var i=0;i<spaceLocation;i++)
    {
   subTimeLeft.concat(tempTimeLeft[i]);
    }
    hoursLeft = parseInt(subTimeLeft,10);
    tempTimeLeft.replace(subTimeLeft, "");

    spaceLocation = tempTimeLeft.indexOf("_");
    for(var i=0;i<spaceLocation;i++)
    {
   subTimeLeft.concat(tempTimeLeft[i]);
    }
    minutesLeft = parseInt(subTimeLeft,10);
    tempTimeLeft.replace(subTimeLeft, "");

    spaceLocation = tempTimeLeft.indexOf("_");
    for(var i=0;i<spaceLocation;i++)
    {
   subTimeLeft.concat(tempTimeLeft[i]);
    }
    secondsLeft = parseInt(subTimeLeft,10);
    tempTimeLeft.replace(subTimeLeft, "");

    alert(hoursLeft + " " + minutesLeft + " " + secondsLeft);   
}

function carryMinOrSec(time)
{
    time=time-60;
}

function carryHr(time)
{
    time=time-24;
}

function setTime (endTime, hoursLeft, minutesLeft, secondsLeft)
{
    if(secondsLeft + endTime.getSeconds() >= 60)
    {
   carryMinOrSec(secondsLeft);
   minutesLeft += (endTime.getminutes()+1);
    }

    endTime.setSeconds(secondsLeft + endTime.getSeconds());

    if(minutesLeft + endTime.getMinutes() >= 60)
    {
   carryMinOrSec(minutesLeft);
   hoursLeft += (endTime.getHours()+1);
    }

    endTime.setMinutes(minutesLeft + endTime.getMinutes());

    if(hoursLeft + endTime.getHours() >= 24)
    {
   carryHr(hoursLeft);
   if(endTime.getDay() == 6)
   {
       endTime.setDay(0);
   }
   else
   {
       endTime.setDay(endTime.getDay+1);
   }
    }

    endTime.setHours(hoursLeft + endTime.getHours());
}

var timeLeft = document.getElementById('clock').innerHTML;
var hoursLeft = 0;
var minutesLeft = 0;
var secondsLeft = 0;

extractTime(timeLeft, hoursLeft, minutesLeft, secondsLeft);

var endTime = new Date();

setTime(endTime, hoursLeft, minutesLeft, secondsLeft);

var Day = "";
switch(endTime.getDay())
{
    case 0:
   Day="Sunday";
   break;
    case 1:
   Day="Monday";
   break;
    case 2:
   Day="Tuesday";
   break;
    case 3:
   Day="Wednesday";
   break;
    case 4:
   Day="Thursday";
   break;
    case 5:
   Day="Friday";
   break;
    case 6:
   Day="Saturday";
   break;
}

newTime="Turn will end at " + endTime.getHours() + ":" + endTime.getMinutes() + ":" + endTime.getSeconds() + " " + Day;

document.getElementById('clock').innerHTML=timeLeft + "<br />" + newTime;


The problem is getting the time into variables from the clock's reading. I have put in comments in the function extractTime() showing where I think the problem is. If there is another way to go about extracting the time, I am open to that as well, this was just the only way I found.

Obviously, I will answer any questions about the code so that you have a better shot at fixing it, and thanks in advance for any help.
Image
Corporal Draconian_Intel
 
Posts: 79
Joined: Sat Jun 21, 2008 11:00 pm

Previous

Return to Tool Archives

Who is online

Users browsing this forum: No registered users