- Messages
- 5,172
...well not exactly... but sort of.
TLDR: If you change a function, recompile all of your scripts that might be calling it.
Default arguments don't actually work how you'd expect. Instead of being available at runtime, they are filled in calling functions at compile time. This can end up causing all sorts of problems for scripts that are being publicly used, or even those you're using yourself.
Imagine you have this function:
Then you have another script that calls SomeFunction
When you compile the second script it becomes:
(well really it becomes a bunch of illegible hex, but this is what it would look like if you decompiled it again)
If you had compiled it before you added the default value to SomeFunction, then it would still look exactly like you wrote it - and can actually fire errors about not enough arguments. This can cause any call involving that function to be terminated. So it's pretty important you recompile everything after changing a function... even if you added a default value to your new argument.
This is something that took forever to click for me, and I still often forget it - much to our testing team's dismay who often have to wait for 3 or 4 alphas of a patch before I remember to recompile everything.
TLDR: If you change a function, recompile all of your scripts that might be calling it.
Default arguments don't actually work how you'd expect. Instead of being available at runtime, they are filled in calling functions at compile time. This can end up causing all sorts of problems for scripts that are being publicly used, or even those you're using yourself.
Imagine you have this function:
Code:
Function SomeFunction(Int aiNumber = 1)
if(aiNumber == 1)
Debug.MessageBox("We got a 1!")
else
Debug.MessageBox("Womp, womp.... we got nothing good.")
endif
EndFunction
Then you have another script that calls SomeFunction
Code:
Function MyOtherFunction()
SomeFunction()
EndFunction
When you compile the second script it becomes:
Code:
Function MyOtherFunction()
SomeFunction(1)
EndFunction
(well really it becomes a bunch of illegible hex, but this is what it would look like if you decompiled it again)
If you had compiled it before you added the default value to SomeFunction, then it would still look exactly like you wrote it - and can actually fire errors about not enough arguments. This can cause any call involving that function to be terminated. So it's pretty important you recompile everything after changing a function... even if you added a default value to your new argument.
This is something that took forever to click for me, and I still often forget it - much to our testing team's dismay who often have to wait for 3 or 4 alphas of a patch before I remember to recompile everything.
Last edited: