Skip to content

fix ForgeFunction argument handling and firstParamCondition - #403

Merged
xNickyDev merged 3 commits into
tryforge:devfrom
Daaisukidayo:patch-1
Aug 15, 2026
Merged

fix ForgeFunction argument handling and firstParamCondition#403
xNickyDev merged 3 commits into
tryforge:devfrom
Daaisukidayo:patch-1

Conversation

@Daaisukidayo

Copy link
Copy Markdown
Contributor
  • Prevent function arguments from overwriting existing environment variables.
  • Restore previous environment variable values after the function finishes.
  • Preserve the first argument when using firstParamCondition.

@xNickyDevxNickyDev added patch not tested Bug has not been reproduced labels Aug 13, 2026
@Daaisukidayo

Daaisukidayo commented Aug 14, 2026

Copy link
Copy Markdown
ContributorAuthor

The code I used to test the function arguments:

$jsonLoad[number;0]$jsonLoad[obj;{"number": 0}]$env[number]// should return 0$env[obj;number]// should return 0 value from the 'obj' json$returnNum[1;2]// ForgeFunction should create environment variables 'number' and 'test', and then return 1, since it received this number$env[number]// should return 0 after the fix, because we manually created the 'number' variable earlier. Before the fix, it returned 1, because the argument environment variable was overwriting the previously created 'number' variable$env[obj;number]// should return 1 because we used $jsonSet inside the custom function$env[num]// shouldn't return anything because the 'num' variable was created inside the custom function$env[test]// shouldn't return anything. Before the fix, it returned '2' because ForgeFunction didn't "delete" the argument variables after execution

The custom function code:

exportdefaultnewForgeFunction({name: "returnNum",params: [{name: "number",type: ArgType.Number},{name: "test",required: false},],code: ` $jsonLoad[num;1] $jsonSet[obj;number;1] $return[$env[number]] `})

@Daaisukidayo

Daaisukidayo commented Aug 14, 2026

Copy link
Copy Markdown
ContributorAuthor

The code i've used to test firstParamCondition fix:

$test[true;0;1]// should return 'true, 0, 1'$test[false;0;1]// shouldn't return anything

The custom function code:

exportdefaultnewForgeFunction({name: "test",firstParamCondition: true,params: [{name: "test1"},{name: "test2"},{name: "test3"},],code: ` $return[$env[test1], $env[test2], $env[test3]] `})

@xNickyDevxNickyDev self-assigned this Aug 15, 2026
@xNickyDev

Copy link
Copy Markdown
Member

The code i've used to test firstParamCondition fix:

$test[true;0;1]// should return 'true, 0, 1'$test[false;0;1]// shouldn't return anything

The custom function code:

exportdefaultnewForgeFunction({name: "test",firstParamCondition: true,params: [{name: "test1"},{name: "test2"},{name: "test3"},],code: ` $return[$env[test1], $env[test2], $env[test3]] `})

Why should the custom function not execute at all when the condition is falsy? In my opinion, it would be more practical to let the first param return the resolved condition as boolean value which then can be used for custom statements and checks inside the code, instead of stopping function execution immediately. If this was the original implementation, I'd like to restructure this!

@Daaisukidayo

Daaisukidayo commented Aug 15, 2026

Copy link
Copy Markdown
ContributorAuthor

Why should the custom function not execute at all when the condition is falsy? In my opinion, it would be more practical to let the first param return the resolved condition as boolean value which then can be used for custom statements and checks inside the code, instead of stopping function execution immediately. If this was the original implementation, I'd like to restructure this!

I fixed only the part when the first param completely disappears if firstParamCondition is set to true.
Example (not related to the prev examples):

params: [{name: 'number',type: "Number",required: true,},],firstParamCondition: true,

The param number now can no longer be accessible through $env[number].
If we try to call the function : $func[true]
Calling custom function `func` requires 1 argument, received 0
If we try $func[true;5]
Function `$func` expects 1 arguments at most at 1:17 (index file)

If this was the original implementation, I'd like to restructure this!

Yeah, this was the original implementation

Comment threadsrc/structures/forge/ForgeFunction.ts
@xNickyDevxNickyDev added blocked and removed not tested Bug has not been reproduced blocked labels Aug 15, 2026
Comment threadsrc/structures/forge/ForgeFunction.ts
@xNickyDev

Copy link
Copy Markdown
Member

LGTM, thanks a lot for your contribution! 🙏

@xNickyDev
xNickyDev merged commit 5863a37 into tryforge:devAug 15, 2026
6 checks passed
@Daaisukidayo
Daaisukidayo deleted the patch-1 branch August 15, 2026 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Daaisukidayo@xNickyDev