Stumped by syntax error in formula

Hi everyone! I'm working on customizing Yanfly's TP manager and I've entered the following formula into a box (init_tp, but irrelevant):

40+level+(agi*0.2)+((def+res)*0.4)

but when I enter any part of the game that has anything to do with initial TP, the following error is thrown:

YEA TP Manager:589:in `eval': (eval):1: syntax error, unexpected ')', expecting

';' or '\n'

40+level+(agi*0.2)+((def+res)*0.4)

                                              ^ (SyntaxError)

        from YEA TP Manager:589:in `maxtp'

 

The "^" points at the asterisk before the 0.4 in the console error report. I have no idea what's causing this, as an earlier formula worked fine. The number of "(" is the same as ")" and I don't see any obvious syntax errors. Can anyone with more experience in Ruby tell me what's wrong? Thanks in advance.

 
I don't know that specific error, but just looking at your formula I believe that you stumbled about one of the "quirks" of Ruby/RGGS: spaces between symbols and signs are important and must not be deleted...

An easier example from a while back; X = 1 - 1 will work, but X = 1 -1 produces a syntax error in several cases, because in the second case, -1 is a negative number and ruby will no longer find any mathematical operand between the two numbers 1 and -1. Only in the first case the minus is eval'ed to the minus operand instead of the negative sign of a number.

Just write that formula with spaces and check if the error is solved....
The problem is the `def` being treated as the "def method" kind of def instead of `def as in defense`.

I ran into this issue before and resolved it by forcing people to either write things like

Code:
a.def
or if formula variables aren't available, something like

Code:
self.def
should work as well since the formula should be evaluated in the context of the battler (for any of those method names to make sense).
Thanks, Tsukihime, your advice worked  🙂 . I didn't think of def also standing for defining a function.
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/stumped-by-syntax-error-in-formula.17673/