my javascript to deduct gold not working..

Hi,

The code is to check if actor have the 100 gold required, display message if not enough gold
and if enough gold, play a SE and deduct the gold.

If the actor have the gold, it will deduct it. But it will not check for not enough gold and not display message and instead carry on to allow further action even when actor do not have enough gold.. it did not show error message either.

I have also set the correct variables to use which is 7.

$gameVariables.setValue(7,100)
invgold=$gameVariables.value(7);
if($gameParty.gold() < invgold){
$gameMessage.add("Gold is not enough")
this._index = this._list.length
}else{
AudioManager.playSe({"name":"Coin","volume":90,"pitch":100,"pan":0})
$gameParty.loseGold(invgold)
}


Can someone help ?
Thanks!
I have fixed it. pls ignore
Wondering why you're doing this in script? It works fine in event commands.

Also not sure why you're setting a variable, retrieving the variable into another, and then using it in the test and command.

Original thread: https://forums.rpgmakerweb.com/threads/my-javascript-to-deduct-gold-not-working.109010/