News:

MFG's Character of the Month: October 2026 Nominations

Main Menu

bad math

Started by Riptide, June 29, 2011, 12:25:38 PM

Previous topic - Next topic

Riptide

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 show)
;Blood Lust triggers
[State -2, varset]
type = varset
trigger1=GameTime/(lifemax-life)+(P2Life-1000)<=2
var(1)=2

[State -2, varset2]
type=varset
trigger1=GameTime/(lifemax-life)+(P2Life-1000)>=3
var(1)=1

Spoiler (click to show)
;Attack Modifier
[State -2,  AttackMulSet]
Type = AttackMulSet
trigger1 = time = 1
value = ifelse(var(1)=2,(life-lifemax*-1)/350,ifelse(var(1)=1,(life-lifemax*-1)/400,(life-lifemax*-1)/400))

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?

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...

Rajaa Retired

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.

Riptide

okay here's what was going on.

Spoiler (click to show)
condition 1) (lifemax-life)+(P2Life-1000)
when you have more life than your opponent
(1000-800)+ (500-1000)= -300 not to make this positive I added *-1

so it's gametime/300 if game time is 2000 ticks

2000/300=6.667

this fits into

[State -2, varset2]
type=varset
trigger1=GameTime/(lifemax-life)+(P2Life-1000)>=3
var(1)=1

where it's more than 3


condition 2) (lifemax-life)+(P2Life-1000)
when you have more life than your opponent
(1000-500)+ (800-1000)= 300 not to make this positive I added *-1

so it's gametime/-300 if game time is 2000 ticks

2000/-300=-6.667

which is less than 2

[State -2, varset2]
type=varset
trigger1=GameTime/(lifemax-life)+(P2Life-1000)<=2
var(1)=2

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.

Алексей

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.

-[Все слова это только слова.]-

Riptide

#5
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 show)

;CONDITION ONE
;you have less life than p2
;total is positive untill *-1
;ending negative or less than 2

[State -2, varset] ;blood lust off
type = varset
trigger1=1+GameTime/((lifemax-life)+(P2Life-1000)*-1)<=2
var(1)=1





;CONDITION TWO
;you have more life then p2
;total is negative untill *-1
;ending positive and hass to be more than 3

[State -2, varset2] ;blood lust on
type=varset
trigger1=1+GameTime/((lifemax-life)+(P2Life-1000)*-1)>=3
var(1)=2


;---------------------------------
;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))

Rajaa Retired

...

Quote from: Rajaa on June 29, 2011, 02:26:53 PM
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.


Riptide

I just altered my above post to show the new code.
there should be no division issues.

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.

Riptide

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?

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 ...

;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))

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).

Riptide

Quote from: Cybaster on July 01, 2011, 07:35:00 AM
You know "(P2Life-1000)*-1" is the same as (1000-P2Life) right ?

un-damageable ? You mean the opponent doesn't take damage anymore ?
Yeah ...

;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))

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 show)
[State -2, varset] ;blood lust off
type = varset
triggerall=(life-lifemax)!=0 && (enemy,life-enemy,lifemax)!=0
trigger1=GameTime/((lifemax-life)+(enemy,life-enemy,lifemax))>=3
var(1)=1





;CONDITION TWO
;you have more life then p2
;total is negative untill *-1
;ending positive and hass to be more than 3

[State -2, varset2] ;blood lust on
type=varset
triggerall=(life-lifemax)!=0 && (enemy,life-enemy,lifemax)!=0
trigger1=GameTime/((lifemax-life)+(enemy,life-enemy,lifemax))<=2
var(1)=2


;---------------------------------
;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)/375))

Rajaa Retired

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.

Riptide

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.

Cybaster

Your 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 !!!

Riptide

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.

Rajaa Retired

Quote from: Riptide on July 02, 2011, 06:44:36 AM
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.


Riptide

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.

Rajaa Retired

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.



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.