YesNoOk
avatar

bad math (Read 799 times)

Started by Riptide, June 29, 2011, 12:25:38 pm
Share this topic:
bad math
#1  June 29, 2011, 12:25:38 pm
  • avatar
  • ****
I'm trying to create a damage dealing modifier and a transformation state.

The modifier changes the attack damage based on the amount of life lost in P1.

The transformation state modifies the damage modifier and changes some animations. I don't have everything set up yet
but I have plugged it into the attack mod. The transformation is triggered by the amount of game tics divided by the amount of damage on P1 and P2. basically I wanted this transformation to auto trigger if you are playing well against a vicious  opponent. ( P1 and P2 are loose a lot of life in a short amount of time)  Here's the code

Spoiler, click to toggle visibilty

Spoiler, click to toggle visibilty

I'm getting a flood of divide by zero and some funky damage values. The damage doesn't seem to be increasing with less life either. Am I doing this right?
Re: bad math
#2  June 29, 2011, 01:37:06 pm
  • *****
  • Nothing ever ends
    • Portugal
    • www.justnopoint.com/loona
It's been ages since I last messed with Mugen math, but isn't (life-lifemax*-1) the same as (life+lifemax) ?

I'm assuming multiplication takes precedence over subtraction like in every other equation I can think of...
Re: bad math
#3  June 29, 2011, 02:26:53 pm
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
GameTime/(lifemax-life)+(P2Life-1000)<=2

At the start of a match, the denominator of that equation will be 0, that's the source of your debug error. You can't divide by zero.

If you want to make the damage based on the amount of life lost, then divide lifemax by life and use that value as the multiplier for your attack. What you have their now will triple or quadruple your damage when your variable is equal to 2 or 3. Your variable will equal to 2 or 3  at any given time. If it's not one, it's the other. You should be able to tell that with your two varsets. It seems like you only need one or none for what you want to do.

Also, I don't think gametime resets between matches, you might want to replace it for a variable that's always adding 1 to itself.
Re: bad math
#4  June 30, 2011, 08:58:58 am
  • avatar
  • ****
okay here's what was going on.

Spoiler, click to toggle visibilty

That is the transformation trigger

There are two variable because the character in normal mode has a damage mod that is altered after the transformation.
Condition 1 is transformed Condition 2 is normal

I thought it would be easier to use the attack modifier than to use a var. The amount of damage will only go a little past double (2.5) even in the most extreme cases which would be having life at 1.
I guess I could divide it but I think it will get too high.


Regardless the main problem is that transformation trigger. Divide by zero seems to be unavoidable but I could use
1+GameTime/(lifemax-life)+(P2Life-1000)<=2
that still gave me a flood of divide by zero
But you said you don't think gametime resets I haven't decided if it's good or bad.

I don't know what to do something went wrong somewhere.
Re: bad math
#5  June 30, 2011, 03:14:07 pm
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
Rajaa is correct. GameTime does not reset per round. What he means you use is a variable, possibly a VarAdd that you'd set up State -2. The VarAdd would be emulating GameTime, but with a reset, provided you're using a variable that will reset after the round is over.

-[Все слова это только слова.]-
Re: bad math
#6  July 01, 2011, 06:00:54 am
  • avatar
  • ****
even if I use a variable I may still get a division by zero error. The math I think I'm using is correct but I'm not sure how mugen processes it.
I've changed everything to make more sense as I think I may have messed up the math a little.
I can't see why I'm still getting  division by zero spam. I'm not dividing by zero.
Two this code makes the character either immortal or do no damage.
I don't know whats happening or even why this is happening.
 :wall:
I actually want to keep using gametime because I decide that this can only be triggered in the first round and early at that.
so gametime is about the same as using a non resetting variable.

Spoiler, click to toggle visibilty
Last Edit: July 01, 2011, 06:22:16 am by Riptide
Re: bad math
#7  July 01, 2011, 06:06:42 am
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
...

GameTime/(lifemax-life)+(P2Life-1000)<=2

At the start of a match, the denominator of that equation will be 0, that's the source of your debug error. You can't divide by zero.

Tell mugen not activate the varset if the denominator is equal to zero. Keep syntax in mind.

Re: bad math
#8  July 01, 2011, 06:23:13 am
  • avatar
  • ****
I just altered my above post to show the new code.
there should be no division issues.
Re: bad math
#9  July 01, 2011, 06:39:55 am
  • ******
  • Limited time to use Infinite power !
    • France
    • network.mugenguild.com/cybaster/
It will still generate mistakes
As Rajaa said : you're dividing by "lifemax-life", which obviously gives back zero at the beginning of the round, since your character's life IS lifemax at the beginning.
Also, P2life-1000 is not very good, since you're assuming that P2's lifemax is 1000, which is not always the case. It's better to use something like "enemy,life-enemy,lifemax".

Please check the results of your operations using displayclipboard, especially if you know your Math is not great.
Also, your "*-1" stuff doesn't make much sense, especially with your explanations.

To correct the division by zero problems, you can add some triggerall=(life-lifemax)!=0 && (enemy,life-enemy,lifemax)!=0
Or you could use the fraction life/lifemax and modify your operations from there to get correct values.

Something like (assuming var(1) is used to count time, as your gametime thing, but with actual resetting at the beginning of the round) :
var(1) * (life/lifemax - (enemy,life)/(enemy,lifemax)) >= 200
would probably give the same results as what you want.
Re: bad math
#10  July 01, 2011, 07:28:37 am
  • avatar
  • ****
I'll use a redirect on P2 then.

* -1 is to change the difference from lifemax-life to a positive number so i'm not multiplying the attack by a negative number.
Once I add triggerall=(life-lifemax)!=0 && (enemy,life-enemy,lifemax)!=0 that will stop the spam. For some reason I thought it was coming from gametime.

But even with all this why does the character become un-damageable?
Re: bad math
#11  July 01, 2011, 07:35:00 am
  • ******
  • Limited time to use Infinite power !
    • France
    • network.mugenguild.com/cybaster/
You know "(P2Life-1000)*-1" is the same as (1000-P2Life) right ?

un-damageable ? You mean the opponent doesn't take damage anymore ?
Yeah ...
[mcode]
;Attack Modifier
[State -2,  AttackMulSet]
 Type = AttackMulSet
 trigger1 = time = 1
 value = ifelse(var(1)=1,(lifemax-life)/350,ifelse(var(1)=2,(lifemax-life)/400,((lifemax-life)*-1)/375))
[/mcode]
Look at the last part of the code :
Quote
((lifemax-life)*-1)/375
This is equal to (life-lifemax)/375
Since lifemax > life whatsoever, this value is always negative (or equal to zero at maximum).
Re: bad math
#12  July 01, 2011, 08:38:00 am
  • avatar
  • ****
You know "(P2Life-1000)*-1" is the same as (1000-P2Life) right ?

un-damageable ? You mean the opponent doesn't take damage anymore ?
Yeah ...
[mcode]
;Attack Modifier
[State -2,  AttackMulSet]
 Type = AttackMulSet
 trigger1 = time = 1
 value = ifelse(var(1)=1,(lifemax-life)/350,ifelse(var(1)=2,(lifemax-life)/400,((lifemax-life)*-1)/375))
[/mcode]
Look at the last part of the code :
Quote
((lifemax-life)*-1)/375
This is equal to (life-lifemax)/375
Since lifemax > life whatsoever, this value is always negative (or equal to zero at maximum).

(P2Life-1000)*-1 the -1 is supposed to be applied after adding (lifemax-life)+(P2Life-1000) so that the product is positive or negative to fit the conditions <=2 or >=3
I forgot to remove the -1 from ((lifemax-life)*-1)/375
Now that the spam has been fixed it's still making the opponent not take damage.
The new code removes the need to use * -1 but something still must have not gone right.




Spoiler, click to toggle visibilty
Re: bad math
#13  July 01, 2011, 04:40:59 pm
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
Get a calculator or something and start doing this simple multiplication and division for yourself.

This is really simple math and I'm getting the impression that you're just throwing some equations together and hoping-wishing-praying for things to work. Multiplying by -1 for no apparent reason and adding 1 to gametime; that stuff makes no sense for what you're trying to do and that's not how you fix things.

Do the math steps one by one; do the calculations; get the actual values you're dealing with; then make your code based off of what you know, not what you hope.
Re: bad math
#14  July 02, 2011, 06:31:52 am
  • avatar
  • ****
I'm working on that but by all means no character should become invincible. There is nothing in the code....
hum.....the attack multiplier. multiplies the attack power points....uggah

I need something that takes the attack power multiplies them and then adds it to the current attack power.
is there any other reference to attack power
 AttackMulSet is not the right controller for what I'm trying to do.

can attack  in the data section take a variable
or can I do Attack=ifelse(var(1)=1,(lifemax-life)/350,ifelse(var(1)=2,(lifemax-life)/400,((lifemax-life)*-1)/375))+100

or something like that because in the end I need to add the fractions of extra attack power to the normal attack amount
I think the character is invincible because the multiplied attack power is very low at the beginning of the game.

this is the best way to explain it.
Re: bad math
#15  July 02, 2011, 06:38:08 am
  • ******
  • Limited time to use Infinite power !
    • France
    • network.mugenguild.com/cybaster/
Your code :
Code:
 value = ifelse(var(1)=1,(lifemax-life)/350,ifelse(var(1)=2,(lifemax-life)/400,(lifemax-life)/375))

Let's imagine var(1)=1, so you're supposed to have an attackmulset > 1 if I'm correct.
Imagine you have 850 life left when this happens.
value = (1000-850)/350 = 150/350 = 0.428

First, this is NOT what you want apparently...
Secondly, you're dividing by 350, which is an integer, and mugen will cast the result of the operation to an integer, which will give back zero.
You have to divide by a float number to get a float number as result, ie> divide by 350.0

Also, answer your new question (meaning what I wrote before is partially wrong), just use an attackmulset = 1 + value_you_calculated.

Finally : DISPLAY YOUR VARIABLES, ATTACKMULSET AND OTHER RESULTS IN DISPLAYCLIPBOARD, TO MAKE SURE OF WHAT YOU GET AS RESULTS !!!
THIS IS HOW ONE MUST DEBUG HIS STUFF WHEN IT INVOLVES MATHS !!!
Re: bad math
#16  July 02, 2011, 06:44:36 am
  • avatar
  • ****
thanks for the tip that was half the problem. I'm setting STCB now.

however I'm wondering if stuff in the data section can take expressions or variables. there are some other things I want to do.
Re: bad math
#17  July 02, 2011, 06:47:25 am
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
however I'm wondering if stuff in the data section can take expressions or variables. there are some other things I want to do.
Try it yourself and see what happens.

Re: bad math
#18  July 02, 2011, 07:06:28 am
  • avatar
  • ****
might as well. :S
nope it's a game crasher.
how would I modify a character speed. I didn't see a speed multiplier in the docs or even a
( I'm thank full that there is a defense multiplier )



the expressions are working like I wanted them to work though some tweaking is needed.
thank you for showing me how to set up and check math expressions and check them correctly.
Re: bad math
#19  July 02, 2011, 07:12:05 am
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
To modify a character's speed, you would need to speed up the animations. You have a choice between making duplicate animations or making some kind of code with the changeanim state controller.


Re: bad math
#20  July 02, 2011, 07:12:35 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
And the defence multiplier is broken and only takes effect on the second hit of a combo.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: bad math
#21  July 02, 2011, 09:51:35 am
  • avatar
  • ****
I mean change the walking or running speed, but it looks impossible.

defiance mul is broken  :-\
It could still be of some use but not much.

I radically changing the trigger code. I have it set so the var only changes when the P1, P2 life ratio in in a certain range

but I have a problem which is hard to describe. The transformation is limited(triggerall) by you being between 100 Hp below to 200Hp above P2 and the gametime being above 40 seconds.

However I want to trigger the transformation( trigger1) only when both p1 and p1's life is below a certain number and either the gametime is above like 55.
Or more accurately: If P1 and P2's life drops quickly in a small amount of time.

I don't know how to code the more accurate trigger. I can't think of anything to use to do this.
Re: bad math
#22  July 02, 2011, 10:16:27 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Create a helper that lasts for your period of time. At the start have it save p1 and p2's life to a variable. At the end, have it check their life against that variable. If the value is within the range you want, use parentvarset

time = 0
var(1) = parent, life
var(2) = parent, life

type = parentvarset
triggerall = time = 190
trigger1 = var(1) - parent, life > 100
trigger1 = var(2) - enemy, life > 100
value = transformation variable

You could probably do it MORE elegantly tbh. But a helper frees up the 2 variables and discounts any worries about the value of gametime, or using time itself or even creating a var counter. And if it freezes during opponent superpause, so what, so would your character.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: bad math
#23  July 02, 2011, 10:43:14 am
  • avatar
  • ****
hum.... but what if I wanted to check any part of the round for a drastic change in life in P1 and P2.

like if both characters were doing nothing then suddenly started fighting.
Re: bad math
#24  July 03, 2011, 06:19:44 am
  • avatar
  • ****
is there a way to use gametime to fire off the helper like every 30 tics to check for drastic drops in life remove it and call it again
in 30 tics.

So I could have the helper check constantly instead of checking only once during the round?

I know it's complicated but what are some other ways of making this work.
Re: bad math
#25  July 03, 2011, 06:23:16 am
  • ******
  • I hang out tough. I'm a real boss.
    • USA
    • litotichues.com/
Read up on %, the mod operator.

GAMETIME%30 = 0

=

Trigger every 30 tics starting from gametime = 0.