[Solved]Spend MP if player has it, else is text

Not a good title, but is the shortest version I can think of.

Well, here I am again, asking for some help.
I was trying to do an event where the player must use a specific skill and, if he had enough mana (in that case, 30MP) he would spend it; otherwise a textbox will open explaining there's missing mana and the skill wouldn't cast.

For this, I made a Conditional Branch to check if the player has the skill and inside of it I used a script call command to check the mana thing.

The script:

Code:
var a = $gameActors.actor(1)
var mana = a.mp

if mana <= 30 {
$gameMessage.setFaceImage('AChars 1',0);
$gameMessage.setBackground(1);
$gameMessage.setPositionType(1);
$gameMessage.add("Esil: Não tenho mana suficiente.");
}
else {

a.loseMp(30)

Dunno if It's OK, but the script don't even makes the player to lose mana.
You're missing a } at the end of the script. Are you like really missing it or you forgot to copy paste it?
Also, you don't loseMp. You gainMp with negative parameter if I remember correctly.
Also, "if" conditions need to be in (brackets). Putting that all together:
Code:
var a = $gameActors.actor(1)
if (a.mp <= 30) {
  $gameMessage.setFaceImage('AChars 1',0);
  $gameMessage.setBackground(1);
  $gameMessage.setPositionType(1);
  $gameMessage.add("Esil: Não tenho mana suficiente.");
} else {
  a.gainMp(-30);
  // skill effects go here
}

Note that this can all be done with eventing (Control Variables > Game Data > Actor > MP):
Code:
◆Control Variables:#0001 check = MP of Actor1
◆If:check ≤ 30
  ◆Text:None, Window, Bottom
  :    :Esil: Não tenho mana suficiente.
  ◆
:Else
  ◆Change MP:Actor1, - 30
  ◆Comment:etc
  ◆
:End
Thank you guys. It's working now :^)

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-spend-mp-if-player-has-it-else-is-text.113341/