This is a bit of a rambling post about potential future features of the plugin. I'd love to hear feedback, particularly from people who can see potential possibilities here, or would at least be interested in experimenting with them.
One idea that I had early on but never quite got around to sorting out is compile-time scripts.
The idea here is that, when you hit compile, the editor itself sets up a Lua state and runs a special script.
Any changes made to the Lua state by this script would be preserved and loaded when the game is run, in the same way that the Lua state is saved and loaded when save games are used.
As a trivial example, if the compile-time script was this:
Code: Lua
...then a string with the date that the game was compiled would be accessible as the global variable compiled_on in run-time scripts.
Again, that's a trivial example, I know that if having the compile date was such a useful thing it would just be added to AGS. But the more interesting possibilities are to do some heavyweight pre-processing - if there is a lot of set-up involved right at the start, you could do it at compile time rather than run-time, so the start-up time could be reduced, and you would not need to include a whole bunch of code that would only ever be run at the start, reducing the amount of Lua code left around bulking up the game data and save-game files.
You could even access files in the project source folder. For example, to get the total number of times the game has been compiled, you could store this number in a project file and update it each time. I'm sure there are lots of other possibilities to accessing files in the project folder from a compile-time script.
But maybe it shouldn't always be necessary to do that, and we can do better. Say that when the compile-time script gets run, there is a special project table available. This table is only available to compile-time scripts, not run-time scripts, and it is special in that its contents get preserved between compilations. So, another trivial example of a compile-time script:
Code: Lua
Now, the run-time scripts can access compiled_count.
Note that compiled_count is copied to a global variable, because the project table itself won't be available.
The reason for that is that, in real-world examples, I imagine the project table would mostly be used for storing cached partial precalculations and other things that don't need to be in the final game data.
Maybe it should be an option though, so if you do something like this:
Code: Lua
...the project table (or a copy of it made at compile-time, technically) will available at run-time.
Taking the idea of Lua scripts running in the Editor even further - how about using Lua to script lightweight editor plugins?
The idea is to have a new collection of Lua scripts, called something like editor action scripts. These are not project-specific but would be stored in a subfolder of the AGS editor home directory. (Actually there could be project-specific ones as well, if that's useful.) Unlike the compile-time scripts, what these scripts do to the Lua state is not preserved for the run-time scripts. They might be able to access the project table described earlier, though.
These scripts can be run from within the editor whenever you like, by right-clicking and selecting "Run" from the dropdown menu. (Possibly they could be optionally bound to hotkeys, too.)
These editor action scripts would have access to a special global object called editor. This is an interface to the state of the editor, able to read and change things in the current project in the same way a full-fledged .NET editor plugin can. It would also have a few special dialogs, so you can pop up a message box with custom text, ask a Yes/No question, get the user to enter a string, or get the user to select a certain game item from the current project (sprite, character, etc.) with a selector dialog.
There is a project called LuaInterface that allows arbitrary .NET objects to be scripted by Lua, e.g.:
Code: Lua
The editor action scripts could use this too.
One idea that I had early on but never quite got around to sorting out is compile-time scripts.
The idea here is that, when you hit compile, the editor itself sets up a Lua state and runs a special script.
Any changes made to the Lua state by this script would be preserved and loaded when the game is run, in the same way that the Lua state is saved and loaded when save games are used.
As a trivial example, if the compile-time script was this:
compiled_on = os.date('Compiled on %Y-%m-%d')
...then a string with the date that the game was compiled would be accessible as the global variable compiled_on in run-time scripts.
Again, that's a trivial example, I know that if having the compile date was such a useful thing it would just be added to AGS. But the more interesting possibilities are to do some heavyweight pre-processing - if there is a lot of set-up involved right at the start, you could do it at compile time rather than run-time, so the start-up time could be reduced, and you would not need to include a whole bunch of code that would only ever be run at the start, reducing the amount of Lua code left around bulking up the game data and save-game files.
You could even access files in the project source folder. For example, to get the total number of times the game has been compiled, you could store this number in a project file and update it each time. I'm sure there are lots of other possibilities to accessing files in the project folder from a compile-time script.
But maybe it shouldn't always be necessary to do that, and we can do better. Say that when the compile-time script gets run, there is a special project table available. This table is only available to compile-time scripts, not run-time scripts, and it is special in that its contents get preserved between compilations. So, another trivial example of a compile-time script:
if type(project.compiled_count) == 'number' then
project.compiled_count = project.compiled_count + 1
else
project.compiled_count = 1
end
compiled_count = project.compiled_count
Now, the run-time scripts can access compiled_count.
Note that compiled_count is copied to a global variable, because the project table itself won't be available.
The reason for that is that, in real-world examples, I imagine the project table would mostly be used for storing cached partial precalculations and other things that don't need to be in the final game data.
Maybe it should be an option though, so if you do something like this:
project.runtime_access = true
...the project table (or a copy of it made at compile-time, technically) will available at run-time.
Taking the idea of Lua scripts running in the Editor even further - how about using Lua to script lightweight editor plugins?
The idea is to have a new collection of Lua scripts, called something like editor action scripts. These are not project-specific but would be stored in a subfolder of the AGS editor home directory. (Actually there could be project-specific ones as well, if that's useful.) Unlike the compile-time scripts, what these scripts do to the Lua state is not preserved for the run-time scripts. They might be able to access the project table described earlier, though.
These scripts can be run from within the editor whenever you like, by right-clicking and selecting "Run" from the dropdown menu. (Possibly they could be optionally bound to hotkeys, too.)
These editor action scripts would have access to a special global object called editor. This is an interface to the state of the editor, able to read and change things in the current project in the same way a full-fledged .NET editor plugin can. It would also have a few special dialogs, so you can pop up a message box with custom text, ask a Yes/No question, get the user to enter a string, or get the user to select a certain game item from the current project (sprite, character, etc.) with a selector dialog.
There is a project called LuaInterface that allows arbitrary .NET objects to be scripted by Lua, e.g.:
luanet.System.Windows.Forms.MessageBox.Show("hi")
The editor action scripts could use this too.