Help with, I think, a math problem
I have the following code:
Code:
I want it so that it will last near infinity. I dont want to keep adding a snippet of code every 10 as I will have quite a lot of code. I was wondering if there was a way so that it could check every 10 until near infinity, without using so much code. |
Code:
How ever this doesn't save much code neither :p What are you trying to make? Might be easier for us to simplify our code |
Ive got a variable which goes up as time passes, and I wanted to execute some code whenever it reached certain intervals, ie every 10. Also, I wanted it to announce like, if it reached 20, it would say You have reached 20. I just didnt want to repeat the same basic code snippet 100's or 1000's of times.
|
just divide the count by 10 and make sure there's no remainder.
if you want to announce a message every nth iteration, divide by that number. |
It's called modulus, the remainder of a fraction.
In this case it checks if there isn't a remainder, so you know it is a multiplication of 10 Code:
|
Thanks Maximus, that looks like what I needed. Ill try it out later.
All I need to know now is, how do I check this value when it reaches 10, 20. I tried client_prethink, but it executed the code at least 4 times, when I only wanted it done once. I also tried a repeating set_task to check every 0.9 seconds, but for some reason that didnt work. In the following code, the time thats printed is always 0. So what am I doing wrong? Code:
|
With the exception of my one computer science class that taught me some SQL, SQL is not my strongpoint. However,
The only thing I see that seems to be of issue is that I don't know if your table "time" has been initialized in the SQL database. It seems that would cause problems. |
Yes, I do initialize it. I just didnt include that code.
Code:
I know its connecting, as the correct time is added to the database. No errors at all. |
Code:
Shouldn't you use new? Code:
Don't you want to print their total time? Code:
If you are planning on releasing this I would suggest using nvault instead. I have found there are very few people that have or understand mysql and most that do do not have it locally on their game server and it causes lag issues. ***edit*** Do you also know that the time you are storing is in seconds and that number can get huge and make no sense? Here is a sugegstion Code:
Using a peice of that code you could check by minutes/hours/days to see if it is divisable by 10 and do something if it is. |
Maybe I should have posted the whole code.
I have store_time as a global variable, so I dont need the 'new' part. Also with the client_print time, I just put that there for testing, to see if it was actually returning something other than 0. Im going to remove it when everything is working. And yes, I know they are seconds. Thanks anyway, I just need some way of checking when they reach certain times, as for some reason, time[id] returns 0, even though I know the database has a time value in it for my steamid. |
| All times are GMT -4. The time now is 20:14. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.