Unexpected $end

I have a skill which I have used for 9 hours of game play. The formula looks like this.

Code:
if $game_player.region_id == 40;
if b.state?(23); b.add_debuff(6, 3); end;
base[20] + 4*a.level + a.mat*4 - b.mdf*1.5;
else;
base[20] + 4*a.level + a.mat*3 - b.mdf*1.5;
end

Now, however, I want to include a variable in the calculation of damage, so I have this.
Code:
if $game_player.region_id == 40;
if b.state?(23); b.add_debuff(6, 3); end;
base[20] + 4*a.level + a.mat*4 - b.mdf*1.5 * (v[245]/100);
else;
if b.state?(23); b.add_debuff(6, 3);
base[20] + 4*a.level + a.mat*3 - b.mdf*1.5 * (v[245]/100);
end

When I use the revised skill, however, I get the error message:

unexpected $end, expecting keyword_end

In my ignorance, I had assumed that when I revised the formula, I would leave the "end"s where they were.
I have no idea what is wrong here. Can anyone spot the mistake?

Thanks.
The error might be the v[245]. I've always had to use $game_variables[245] myself to access variable 245.
@bgillisp changing (v[245]) to ($game_variables[245]) still throws the same error.
Code:
if $game_player.region_id == 40;
   if b.state?(23); 
      b.add_debuff(6, 3); 
   end;
   base[20] + 4*a.level + a.mat*4 - b.mdf*1.5 * (v[245]/100);
else;
   if b.state?(23); 
     b.add_debuff(6, 3);
     base[20] + 4*a.level + a.mat*3 - b.mdf*1.5 * (v[245]/100);
   end
# "end" closing "else"? 
#unexpected <end> expected *keyword* end
end #*keyword* end, closing "if $game_player.region_id..."

use blocks, not colons.
you'll see the structure much easier.
@gstv87 That extra "end" solved the error message, but I am now only getting 1HP damage for that skill - I have a script which prevents Null damage and always gives a minimum of 1, so I am assuming that the 1HP damage is the result of that script.

For information, variable 245 is, at the moment, set to 100 (it will be increased by plot devices at different times) so I should be getting the 'normal' damage of around 220HP, as it is normal damage formula * 100/100
Is it that logic that I have wrong?

Thanks for the help so far.
try changing (v[245] / 100) to (v[245] * 0.01)
@gstv87 I'm still getting just 1HP
Code:
if $game_player.region_id == 40;
 base[20] + 4*a.level + a.mat*4 - b.mdf*1.5 * (v[245]/100);
else;
 base[20] + 4*a.level + a.mat*3 - b.mdf*1.5 * (v[245]/100);
end;
if b.state?(23);
 b.add_debuff(6, 3);
end;

copy/paste
@gstv87 Sadly no change.
Maybe I need to find a completely different way of increasing these skills by 10% rather than using a variable. But to be honest, I can't think of one.
that's impossible.
even if v[245] and base[20] are 0, a.level is still always greater than 1, and that's multiplied by 4.
try moving the "if b.state?" block to the top, and add a "return" instruction before the base[20]
there's no way it will output 1 that way.
if it does, there's something else negating that whole thing.
@gstv87 Sound the trumpets! Ring the bells!
That did it.

Thank you so very much for all your help with this. I deeply appreciate it.
If you guys are still wondering, it returned 0 from your damage formula because the result of the formula is always the formula's last method call's result.
You checking/adding a state at the end does not result in a valid number, therefore the formula itself would crash the game, but because a rescue is called with the value of 0 for all formulas, the damage formula returned 0 instead of a crash.

Always do additional things (such as adding/removing states) at the start of your damage formula, and do the real damage calculation at the end.
If you happen to do some of these additional things based on the damage itself, you first do the damage calculation, store it in a local variable, do your additional things after, and at the end use the stored local variable to denote the real damage value (using a return variable_name line at the end).
@Sixth Thanks for the explanation.

Original thread: https://forums.rpgmakerweb.com/threads/unexpected-end.86721/