Ogame Resource Ticker

By Oliver Jensen Last update Jul 20, 2009 — Installed 3,477 times.

Buggy

in
Subscribe to Buggy 12 posts, 2 voices



Vess Scriptwright

Great idea but the script is horrendously buggy and doesn't work.

1) It does not get correctly the hourly production rates from the Resources page. As far as I can see, the problem is that it looks for the 10th tr element - while the necessary information is in the 11th element. Easily fixable.

2) It presumes that numbers can have only one dot. I guess you've never had more than a million resources on any of your planets? ;) Easily fixable by making the replace() functions use a regular expression (/\./g) instead of a literal string ('.').

3) The variables m, c and d are unused. Easily fixable.

4) The last one I couldn't fix. The script does not detect planet switching and keeps incrementing with the resource production rate of the last planet, the Resources page of which has been examined. Worse, it keeps "ticking" the resources on a moon - even though nothing is produced there, and visiting the moon's Resources page doesn't solve the problem. :-( You really have to keep in the cookies the production rate for each planet, detect the current planet and account for non-producing "planets" like moons.

Until the last problem is fixed, the script is, sadly, unusable and misleading to me, so I won't be able to use it.

 
Vess Scriptwright

Correction about 1). The level of production is neither the 10th, nor the 11th "tr" element. In fact, it is not at a constant place. That table can have a different number of rows, depending on how many kinds of mines are built. It can have as few as 9 rows (no mines, no Solar Panels, no Solar Sats) or as many as 15 (the 3 types of mines, Solar Panel, Fusion Reactor, Solar Sats).

You should look for a row, the first cell of which contains the text ":" (e.g., "Total:" in English) - that's the hourly production row from which you should take the various rates.

 
Oliver Jensen Script's Author

Vess, thank you very much for your input. I joined Ogame about 5 days ago so I didn't realize a lot of this stuff changes location.

1) Whoops, I guess It-Works-For-Me testing doesn't quite cut it, huh. Fixed.
2) Oh, I thought that replace would replace all '.'s - This is pretty much the first time I'm using javascript and I assumed it'd act like php's str_replace. And yeah, I've never had more than a million resources ;) Fixed.
3) Heh my bad, thanks for catching it. Fixed.
4) I'll fix the planet issue as soon as I get a second one so that I can test it. As for moons, could you please tell me what's different about the page when you're looking at one so I can just disable it on moons? Thanks!

 
Vess Scriptwright

Turns out, there's nothing special about the moons - issue 4) was related to issue 1). Simply, a moon has no Solar Panels, no Fusion Reactors, no mines, no Solar Sats - so the resource production was in a place the script didn't expect and the resources were ticking with the speed of the last visited planet resource page.

Looking at your fixed source, a few more remarks.

1) Now you're looking for "Total:". I know that's safer - but also makes the script language-dependent. If you look just for ":", it will work everywhere. The new version also looks for "Metal:", "Crystal:" and "Deuterium:" which is also language-dependent. I am thinking of something along the lines

if (location.search.split ('?') [1].split ('&') [0] == 'page=resources')
{
var fields;
var element = document.getElementById ('ressourcen').getElementsByTagName ('tr');
for (var i = 0; i < element.length; i++)
{
if (element [i].innerHTML.match (':'))
{
fields = element [i].getElementsByTagName ('font');
break;
}
}
mrate = fields [0].innerHTML;
crate = fields [1].innerHTML;
drate = fields [2].innerHTML;
document.cookie = 'rates=' + mrate + ':' + crate + ':' + drate;
}

2) The @include should be a bit more generic (http://uni*.ogame.*/game/index.php*), in order for the script to work on other language servers. However, you should also put a couple of @exclude lines (for http://uni42.ogame.org/* and http://uni6.ogame.de/*) because these two sites use the new OGame interface which has a completely different format and a built-in resource ticker.

3) Another problem which I don't know how to fix. The ticking of the resources tends to screw up the countback clocks of the flights in progress. That is, these clocks reach 0 on the screen faster than they should and when you think that the fleet has arrived and refresh the page, you see that it still has some time left to go.

 
Oliver Jensen Script's Author

Hi

Regarding the language issues, these are going to be a problem:
I've fixed the "Total:" to match for the first ':' it finds like you suggested, and broadened the include URLs etc. However, fixing searches for 'Metal:', 'Crystal:' and 'Deuterium:' is trickier, as it does this to figure out how much time is still needed before you'll be able to build or research something, and since those values are in a single line of text, without specific words I would have no way of differentiating 100 metal and 100 crystal from 100 metal and 100 deut. Any ideas?

Regarding the multiple planets thing, that should be fixed now :) I still only have one so I can't really test it like I should but it appears to be working - it stores a cookie per planet named rates[coords]

Thanks again for all your help!

 
Vess Scriptwright

Regarding the screwing up with the flight timers - it could be caused by the fact that your script updates each resource when it is supposed to have increased by 1. These are a lot of asynchronous updates. A better approach might be to update the resources every second by the amount they are supposed to have increased during this second. But I am not sure that this will fix the problem and it might lead to discrepancies with the reality, since the resources update by tiny fractions of a unit every second, especially when the mines are of lower level. This should be experimented with. One possibility is to see how StdOgame does the resource ticker. Unfortunately, I don't use it, so I'm not familiar with it.

 
Oliver Jensen Script's Author

I've had a look at StOgame and I'm pretty sure they're doing it the way I'm doing it - resources tick up by 1 whenever they're supposed to. Also I don't think this would cause any timing issues as when I had the Time Until Available timers in this script as well they were unaffected.

Are you certain that the issue you're talking about is caused by this script?

 
Vess Scriptwright

That's funny - I looked at StOgame too and IMO it definitely updates all the resources every second, instead of whenever a resource increases by one. :)

And, yes, I'm 100% sure that it was your script that distorted the local timers - although I am not sure that it was the updating method that was the reason. When I disabled it, everything started working just fine again.

 
Oliver Jensen Script's Author

I can't replicate your timing issue, and neither can anyone in my alliance, so I'm thinking perhaps it's a problem on your end... and since I really don't have much to go on, unless other people start complaining about this one I'm going to have to leave it unresolved.

 
Vess Scriptwright

Does anyone from your alliance have mines high enough to produce more than 1 unit of resource per second? Perhaps this is why the clock gets distorted on my side... Could you please try to produce a version that updates all the three resources every second, instead of only one resource whenever this resource increments by one? I'll test it here and see if the problem goes away.

 
Oliver Jensen Script's Author

Sure, I'll get that together in a day or two and link you to it. Hopefully we'll get this thing stamped out.

Thank again for helping me make my scripts useable! I really appreciate it =)

 
Oliver Jensen Script's Author

Please see this link for a version that updates the values every second:
http://userscripts.org/scripts/show/49727

Let me know if this solves your problems. Thanks!