[ALL]Fix TickCount initialization

In normal versions of Eclipse(for those who have no idea what im talking about, the engine uses GetTickCount directly instead of checking to see if the value is = to or < than 0) the Tick value can go lower than 0 and cause the engine to crash from Longs not being able to use negative values.
To fix this it’s rather simple, and I’ll show you how! 😄

OK, so first thing you should do is decide to use timeGetTime instead because it will last longer, and its more accurate.

the next thing you should do is go into where you have your server/client loop and copy/paste this in:

Public Function GetTick() As Long

    Const MAX_INT As Long = 2147483647

    If GetTickCount < 0 Then
        GetTick = MAX_INT + GetTickCount
    Else
    GetTick = GetTickCount
    End If

End Function

after that, go into said loop and find where it says Tick = GetTickCount. and change that GetTickCount to just GetTick!
you’re for the most part done, you will have to find all the areas that are calling GetTickCount and change it to that GetTick function! this will ensure the value is ALWAYS a positive value to ensure that it won’t error after a long host(keeping the server up for days would eventually crash it due to said negative value).

Anywho, lemme know if you get confused by this tutorial and i’ll help you in any way I can!

Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.

But then again, VB6 programmers already are in hell and have survived it compared to people who program in other languages. (I’m talking about instability of VB6 and how it’s comparatively featureless)

@‘YourBestNightmare’:

Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.

I don’t see any problem here, it’s only being used within that sub specifically not to mention that’s like dims are horrible in subs, wtf are you on about.

@‘Growlith1223’:

@‘YourBestNightmare’:

Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.

I don’t see any problem here, it’s only being used within that sub specifically not to mention that’s like dims are horrible in subs, wtf are you on about.

You want to defend your code? Okay, leaving this thread, I have nothing to talk about with you then.

@‘YourBestNightmare’:

@‘Growlith1223’:

@‘YourBestNightmare’:

Constant in function. I have not touched VB6 for years, but I am sure you will go to programmer hell for doing this.

I don’t see any problem here, it’s only being used within that sub specifically not to mention that’s like dims are horrible in subs, wtf are you on about.

You want to defend your code? Okay, leaving this thread, I have nothing to talk about with you then.

you’re complaining over nothing then leave over nothing, why were you here to begin with?

I’d put this in modConstants, honestly.

Const MAX_INT As Long = 2147483647

Or replace it with

Dim MAX_INT as Long = 2147483647

It’s not a particularly good idea or best practice to declare constants inside a method, seeing how they can be run several times. A constant should only ever be declared ONCE during your program’s flow. Redefining a constant a couple hundred+ times per second is not a good idea, I’m surprised VB6 even lets you do that.

I’ve tested this and there was literally no change in performance nor cpu/memory usage. I done Const MAX_INT within the method because there’s no point in making it a global constant since this is the only thing using it. There was literally no ms change in doing what I’ve done so I went with it. god damn I finally release a tutorial in nearly 3 years and nothing but complaints.

It’s unlikely to make a difference in speed, seeing how it’s declared only within the scope of your method. Doesn’t mean you should not be able to take criticism on poor coding practices and improve though. Imagine if everyone just did their own thing “because it works right?” in critical software. There’s a reason coding standards were made and why best practices exist.

Criticism is not complaining.

So what you’re essentially saying is using my own standard is bad…? ok, fine this is my last tutorial lol.

EDIT: also I know complaints was the wrong word. either way, if I can’t use my own standard then there’s no point in posting tutorials anymore, I shouldn’t have to follow this “Coding standard” instead of my own. >_>

Thanks Growlith1223, my server would crash requiring a full reboot once a week. This seems to have fixed the issue though!

No problem! this has been an issue with the engine for years, i discovered this fix for it, basically this will convert the number to a positive, therefore will always be a positive value.

Thanks for sharing this Growlith, it looks like knightkid had me convinced. I’m going to give this a try now.

from my testing of having my comp up for about 1-2 months, any engine i have thrown this into has never crashed, there might be a mishap with it resetting back to 0 but it’s fairly easy to fix with a small skip of one cycle and to fix that desync, you would just need to reposition everyone

VB6 was good for awhile, .NET has finally matured and time to move on. 😛 Even though the IDE sucked, the speed and performance of VB6 was better for many years after Microsoft abandoned it.

Can’t you just use a .DLL like Thomas coded in a new way to handle the tick count using timeGetTime which utilizes a new method of keeping track of the time, rather than using the plain old GetTickCount. This is also better and harder to hack I have noticed.

you do realize that even .NET Environment.TickCount also has the issue of going negative?

also if you’re using getTickCount OR timeGetTime in .net then you need to learn how to code in .net
both getTickCount and timeGetTime have the issue of roll-backing into a negative value, ere-go crashing everything.

@‘Helladen’:

VB6 was good for awhile, .NET has finally matured and time to move on. 😛 Even though the IDE sucked, the speed and performance of VB6 was better for many years after Microsoft abandoned it.

Can’t you just use a .DLL like Thomas coded in a new way to handle the tick count using timeGetTime which utilizes a new method of keeping track of the time, rather than using the plain old GetTickCount. This is also better and harder to hack I have noticed.

But yet still continues to use VB6. You said in another thread that was deleted about moving on and going 3D and within about 2 hours of posting it you released a new update for mirage source on hitspark.

@‘BeNjO’:

But yet still continues to use VB6. You said in another thread that was deleted about moving on and going 3D and within about 2 hours of posting it you released a new update for mirage source on hitspark.

I am using Visual Basic 6 for now. The updater I made for Nin Online is in .NET - I can write in .NET and OO too. I just have a lot of work that I would throw away if I rewrote the engine in a new language. I am utilizing my resources effectively here, not restarting when there is no need. But yes, I am moving tools and such over to .NET and getting more experienced in the language.

@‘Growlith1223’:

you do realize that even .NET Environment.TickCount also has the issue of going negative?

also if you’re using getTickCount OR timeGetTime in .net then you need to learn how to code in .net
both getTickCount and timeGetTime have the issue of roll-backing into a negative value, ere-go crashing everything.

You can use unsigned ints or go for a long for the API calls. And, Enviorment.TickCount’s MSDN page provides a way of converting the negative to a >0 value.

I know that MSDN has a fix for it in .NET, this is what i’ve come up with for VB6.
and that doesn’t change the fact that it still rolls back to a negative value, hence why i made this tutorial for a VB6 side of TickCount. ._.

Log in to reply