Everytime I use this formula I get -damage.....can someone look at it??
damage = rand(1,src.attack)*src.strmod - rand(1,M.defense)*M.endmod
ID:161517
![]() Apr 27 2008, 5:42 pm
|
|
You can have it output the attack (which would be rand(1, src.attack)*src.strmod) and the defense (which would be rand(1,src.defense)*M.endmod), but if you ask me, the way you are doing it with random numbers is stupid, and it's no wonder you are getting negative numbers.
|
It's not stupid, so long as it properly handles negative numbers. It's a far sight better than what most people would come up with on their first try.
|
CaptFalcon33035 wrote:
You can have it output the attack (which would be rand(1, src.attack)*src.strmod) and the defense (which would be rand(1,src.defense)*M.endmod), but if you ask me, the way you are doing it with random numbers is stupid, and it's no wonder you are getting negative numbers. Then if its so stupid, please let me know how you would do it. |
damage=rand(1,10)*(attack/M.defense)*(strmod/M.endmod) I assume judging from your damage formula that you use a health var that peaks out at 100(%) and never increases, due to the fact that your damage formula would create a percentile damage. The one above is between 1 and 10% damage per hit assuming the two have equal strength and endurance. But of course thats easily changeable. And you dont need a "src." in your entire code. The compiler automatically assumes its "src.". Dragon Ball Finale does not have even 1 src. in its entire code. It'll make it a lot shorter not having them either. If you want to mass replace hit ctrl+H and enter "src." without apostraphies on the first line then leave the second one blank and select "all files" on the bottom. I swear it wont screw up anything in fact itll make it better. |
Dragonn wrote:
damage=rand(1,10)*(attack/M.defense)*(strmod/M.endmod) I assume judging from your damage formula that you use a health var that peaks out at 100(%) and never increases, due to the fact that your damage formula would create a percentile damage. The one above is between 1 and 10% damage per hit assuming the two have equal strength and endurance. But of course thats easily changeable. Well, I'd say that's debatable, the usefulness of src. Some people have the habit of assinging the same name to variables, so if there's a local variable with the same name, the compiler will not assume that it is "src.". Also, in some ways, it makes code a little more clear. You can see at a glance whether a line of code modifies the actual object or if it's just modifying a local or global variable. If I see variablename = 5 in the middle of a procedure, I'd have to check the entire procedure for that variablename to know whether or not it's modifying the src. Anways, it's a matter of preference. For example, personally, I try to not repeat variable names, but I know coders who use the same variable name several times in the same procedure, it really doesn't make a difference. I see no practical reason for a find&replace to remove it. If it's already in there, what's the point of removing them? The code really is not much clearer, and it's not more effective, and I doubt it has any effect on performance. |
Of course there's a chance, especially against stronger foes!
Look up min() and max(), they'll help you out a lot, especially max().
max(0,var) will make it so 0 is always the lowest value (max() picks the highest #. Anything below 0 will have 0 picked.)