numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
200 stars 118 forks source link

JME functions with parameters: Error computing referenced variable #847

Closed ugoertz closed 2 years ago

ugoertz commented 2 years ago

I am seeing some weird behavior for custom JME functions (defined in the "Extensions & scripts" section or in an extension via jme.variables.makeFunction) with parameters. I get an Error computing referenced variable error message in the "Variables" section for those variables whose definition invokes the function. Example question Maybe related to this commit: https://github.com/numbas/Numbas/commit/88b1c1ae1740f776e55203f6b95e9f3f4d362a57 ?

christianp commented 2 years ago

Someone on the numbas-users mailing list reported the same bug. I'll repeat what I said there:

When working out what variables a custom function depends on, it looks at the list of parameters you've defined, and then the expression for the body of the function. The routine to find variables in the body normalises names, but the names of the parameters weren't normalised. Because you put your parameter names in capitals, it thought that lower-case 'c' was an external variable. 'a' and 'b' were OK because you've defined question variables 'A' and 'B', which are also normalised properly.

I've fixed this, and it looks like your question works now.

christianp commented 2 years ago

Your names weren't in capitals, but nevertheless it seems to be working now, so I must have just fixed whatever was wrong!