Open messengerbag opened 1 week ago
I guess I'll go check the manual for old examples with function.
EDIT: There are are 147 references, of which most are event handlers.
Do we want to start steering users away from function
right now? If so, I could start with references that aren't event handlers, since those are still created as function xxx()
by the editor and writing them differently in the manual could be confusing, unless we're also planning to update 3.x soon to discourage the legacy keyword.
About ags3 , check https://github.com/adventuregamestudio/ags/issues/1331#issuecomment-877709952
I think void in ags3 is actually int for compatibility because some old games returned something in a void
function and it was kept to avoid breaking old games.
Yes, I thought so. That's part of why I think AGS 4.0 is a good opportunity to fix it.
I think void in ags3 is actually int for compatibility because some old games returned something in a void function and it was kept to avoid breaking old games.
To clarify, today void
is a valid keyword in compiler and not an int
alias, but the engine "secretly" still returns a integer '0' from the functions of void type. This is done because old API was not declared as void
but as function
, even though it did not return anything meaningful, and unfortunately some users have used this return value by mistake.
Describe the problem The
function
keyword is a legacy of ancient AGS scripting. Many of the default functions that are called by the engine use it as their return type. Because it is implemented as an alias ofint
but is used even if the function doesn't actually return anything, it means that AGS script cannot properly distinguishint
andvoid
return types.It also creates inconsistency, with two/three different ways to write the same function. This arguably creates confusion and makes the AGS scripting language harder to learn.
Suggested change Remove
function
as a keyword. Change all function definitions to useint
orvoid
as appropriate, and make sure the editor uses these when creating event handlers. This also requires an update to the manual and to the templates.Optionally, update the compiler to require a correct return type (do not allow a bare
return;
if the return type is declared asint
, or areturn 1;
if the return type is declared asvoid
).Optionally, add a backwards script compatibility option to retain
function
as a keyword (still as an alias forint
). (Note that if the other optional part is implemented, this would still require users to change all functions that need to havevoid
as their return type, unless that is also disabled if the script compatibility option is set.)Alternative suggestion Alternatively, don't remove
function
as a keyword, but change all the built-in functions to eitherint
orvoid
as appropriate (including in the manual and templates), so thatfunction
never appears unless you specifically add it.