GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Function arguments names restriction

Open f0nar opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

Describe the bug

I found funny issue I am sure it is not super priority task but I think it is useful to know

The key is that we cannot use any name as parameters for expression and condition functions (possibly action too, I didnt check it yet)

I created function of expression and condition type with parameter named "Number" and return type "Number". Once I used it I receive error that Number is not function. The key is that after gdevelop function transpilation we receive js function with parameters named as ones in gdevelop. So we will have parameter Number of number type and later you are trying to use global Number function to process returned value. Here is the issue)

I think it is might be super unobvious for guys who didnt have coding experience.

I see three solutions:

  • Change parameters naming during transpilation. E.g. Number -> Number / #Number / par_Number and so on or wrap them with object and pass like { Number } (later usage param.Number)
  • Somehow wrap all global enteties usage. Use it through window variable or wrap with object and pass like context
  • Make list of reserved names and disallow user to use them with UI warning

Steps to reproduce

  1. Create custom extension
  2. Add function of expression and condition type
  3. Add to it parameter with "Number" name
  4. Make it return Number
  5. In function eventsheet create js code block and add there
const numberParam = eventsFunctionContext.getArgument("Number");
eventsFunctionContext.returnValue = Math.random() * 100;
  1. Use defined function in scene eventsheet

GDevelop platform

Desktop

GDevelop version

5.3.194

Platform info

No response

Additional context

No response

f0nar avatar Jun 04 '24 11:06 f0nar