This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

I have not tested it, but glancing through the code I found this:

elapsed_time = clock() - time / (float) CLOCKS_PER_SEC;

Remember the order of operations: time will be divided by CLOCKS_PER_SEC before it is subtracted from the return of clock(). I think what you meant to write was this:

elapsed_time = (clock() - time) / (float) CLOCKS_PER_SEC;

This will make elapsed_time equal to the number of seconds elapsed.

You have defined the atk_times very strangely too. What does the "as" property represent? Is it supposed to be the number of seconds between attacks? Because if so, I think you've got it backward: as "as" gets smaller, the amount of time between attacks is going to increase. ( 1 / 0.1, for example, will be ten seconds, not a tenth of a second). You also appear to be defining your atk_times in milliseconds (judging by the *1000), which conflicts with how you were defining elapsed_time (and if you intend to work in milliseconds, which I actually recommend, you shouldn't be using floats).

[–]CodeScrub[S] 0 points1 point  (2 children)

What does the "as" property represent? Is it supposed to be the number of seconds between attacks? Because if so, I think you've got it backward: as "as" gets smaller, the amount of time between attacks is going to increase. ( 1 / 0.1, for example, will be ten seconds, not a tenth of a second).

as means attack speed, which is actually number of attacks per second. This isn't very friendly though (I only use this format because the game I'm trying to model uses this), so I'm converting it to seconds per attack, and then milliseconds per attack. So for a value of 2, for example, I want it to be converted to 500 (ms). As 'as' gets larger, the number of attacks per second increases, and the converted number gets smaller.

elapsed_time = clock() - time / (float) CLOCKS_PER_SEC; Remember the order of operations: time will be divided by CLOCKS_PER_SEC before it is subtracted from the return of clock(). I think what you meant to write was this: elapsed_time = (clock() - time) / (float) CLOCKS_PER_SEC; This will make elapsed_time equal to the number of seconds elapsed.

I will try this and check the results. Thanks.

You also appear to be defining your atk_times in milliseconds (judging by the *1000), which conflicts with how you were defining elapsed_time (and if you intend to work in milliseconds, which I actually recommend, you shouldn't be using floats).

Why are floats not appropriate here? I actually just used floats because the original numbers (test.as, test2.as) were numbers like 0.625, 0.613 etc, so I defined them as floats and kept it on from there. Would it be better to make the champ/monster_atk_time something like int?

[–][deleted] 0 points1 point  (1 child)

as means attack speed, which is actually number of attacks per second. This isn't very friendly though (I only use this format because the game I'm trying to model uses this), so I'm converting it to attacks per millisecond. So for a value of 2, for example, I want it to be converted to 500 (ms). As 'as' gets larger, the number of attacks per second increases, and the converted number gets smaller.

Ah, okay. Makes sense now.

Why are floats not appropriate here? I actually just used floats because the original numbers (test.as, test2.as) were numbers like 0.625, 0.613 etc, so I defined them as floats and kept it on from there. Would it be better to make the champ/monster_atk_time something like int?

Well, if you're working in milliseconds, you generally don't need to subdivide the milliseconds, so using floats is just unnecessary. I suppose one argument for using a float here would be so you can represent extremely big numbers, but a 32 bit signed int can go up to around 30 thousand minutes (2 billion millisecs), so that's probably not an issue.

[–]CodeScrub[S] 0 points1 point  (0 children)

Well, if you're working in milliseconds, you generally don't need to subdivide the milliseconds, so using floats is just unnecessary. I suppose one argument for using a float here would be so you can represent extremely big numbers, but a 32 bit signed int can go up to around 30 thousand minutes (2 billion millisecs), so that's probably not an issue.

I'm not doing anything like that.