PLUGIN: Lua for AGS

Started by Denzil Quixode, Fri 04/09/2009 19:30:22

Previous topic - Next topic

Denzil Quixode

OK! It's time to publicise the new version of Lua for AGS.
I've updated the first post a bit and set up this place as the official site for now: http://lua-for-ags.wikispaces.com/

There's more details there but here are some of the main changes:

IDE Features
  • Nicer Lua code editor
  • Syntax check button on the toolbar (clicking it when you are editing a script that tells you whether there are any syntax errors)
  • Subfolders in "Lua Scripts" for easier organisation

    Accessing Lua From AGS-Script
  • Changed syntax to call Lua functions.
    Code: ags
    LuaValueList* lparams = Lua.NewValueList();
    lparams.Add(Lua.StringValue("test"));
    lparams.Add(Lua.IntValue(255));
    LuaValueList* lresults = Lua.Call("My_Function", lparams);
    int result = lresults.AsInts[1];

  • LuaValueLists also used for getting and setting global variables with Lua.GetVar() and Lua.SetVar()

    Accessing AGS-Script From Lua
  • "ags" table that contains the standard global AGS functions and some AGS global variables.
    Code: ags
    ags.GiveScore(100)
    ags.cEgo:Say("Woohoo!")

  • Ability to attach custom Lua fields and methods to individual AGS objects


    Misc.
  • The weight that Lua for AGS adds to a save game file has been reduced - the "baseline" (when you have not added any of your own functions or variables to Lua) is now just 1.5kb.

Joseph DiPerla

Woah! Awesome. I can see some top notch games being made with this...
Joseph DiPerla--- http://www.adventurestockpile.com
Play my Star Wars MMORPG: http://sw-bfs.com
See my Fiverr page for translation and other services: https://www.fiverr.com/josephdiperla
Google Plus Adventure Community: https://plus.google.com/communities/116504865864458899575

ThreeOhFour

A lot of this is a mystery to me, but from what I can understand there seems to be a lot of potential here.

Have you any plans to create something like a small demo game to help dull minded people like me understand what sort of capabilities this could provide?

Denzil Quixode

I do plan to, yeah, but I haven't been able to find the time yet.

It's sort of difficult making an effective demo. Unlike a plugin for 3D graphics or something, using Lua will not really make anything possible that used to be impossible - any single example of Lua being used to do something can always be replicated using AGS's standard scripting. The "demo" would really be in looking at how it was coded, not necessarily what it's like for the player.

Denzil Quixode

#24
Okay, I'm still working on a proper demo, but in the meantime here is a little "extra" demo to show how Lua could be used to help with debugging.

If you want to be able to do all sorts of little things (add specific inventory, teleport to a specific room, etc.) while debugging/playtesting your game, the usual thing is to set up a load of special key combinations, or a special GUI with a whole load of buttons, something like that. Either way, each new thing that you want to do in-game has to be specially coded, and if you realise you need a new one while playing you have to stop the game to code it in.

The alternative is to be able to type in and run Lua code while the game is running. This is just the standard "Demo Quest" that comes with AGS, with the addition of an interactive Lua prompt:


The game loads and plays as normal, but press Ctrl-L to show a prompt at the bottom of the screen that accepts Lua commands. You can also use the Page Up/Page Down keys to find older commands you've typed and repeat them.

For example, try:
Code: ags
print("Hello World from " .. _VERSION .. "!")




The prompt tries to be clever, in that if you just enter a value it will try to display it. For example, entering this does the same thing as the previous one:
Code: ags
"Hello World from " .. _VERSION .. "!"


Here are some other commands you can try:
Code: ags
ags.Debug(1,0)

Code: ags
ags.GiveScore(728)

Code: ags
ags.Mouse.GetPosition()

Code: ags
1 + 2

Code: ags
ags.cCris:Say("Hi, I'm %s!", ags.cCris:Name());

Code: ags
ags.cCris:ChangeRoom(16,170,180);

Code: ags
ags.cCris:GiveInventory(ags.iKey)

Code: ags
ags.StopMusic()

Code: ags
obey = ags.Overlay.CreateTextual(10,30,100,2,36,"OBEY!!!!")


As well as directly calling "raw" AGS functions like this, you could also write your own functions in Lua that never get called by the game, but are only meant for being called from this interface.

By the way, this prompt isn't a "standard" feature of the plugin, it's custom-written for this demo but is pretty simple and should be quite easy to integrate into any game.

(Also I've just noticed the game stops with an error if you try to save. This is something to do with the plugin not being able to handle Text Window GUIs I think, I will try to get this fixed asap.)

Pumaman

Quote from: Denzil Quixode on Tue 13/10/2009 19:48:06
The alternative is to be able to type in and run Lua code while the game is running. This is just the standard "Demo Quest" that comes with AGS, with the addition of an interactive Lua prompt:

Here are some other commands you can try:
Code: ags
ags.Debug(1,0)

Code: ags
ags.GiveScore(728)

Code: ags
ags.Mouse.GetPosition()


That's really useful -- it's something I've been meaning to add natively to AGS for ages but never got around to it, and a lot of people have been asking for this run-time scripting ability.

Great work!

Denzil Quixode

Quote from: Pumaman on Wed 14/10/2009 22:23:59
That's really useful -- it's something I've been meaning to add natively to AGS for ages but never got around to it, and a lot of people have been asking for this run-time scripting ability.

Great work!
Thank you!

One noticeable that you can't do now is call your own script functions (as in, functions you write yourself in the main script). I know that the plugin docs say that calling script functions from a plugin function just isn't supported, but is that something that could ever be overcome?

Pumaman

The CallGameScriptFunction and QueueGameScriptFunction plugin API commands are provided for this purpose, though admittedly they are a bit restrictive with what they allow at the moment.


monkey0506

Quote from: Pumaman on Wed 14/10/2009 22:23:59a lot of people have been asking for this run-time scripting ability.

Chris now you've got me trying to implement this directly within AGS...I've been toying around with the idea a bit. And by "toying around" I of course mean I have nearly a thousand lines of code (not including my Stack module which I'm using) and...the results are interesting (to me in any case). I've gotten loads of functions now running from my simple TextBox console.

It's notably much less versatile than the plugin of course, and there's a lot yet to be done. For example I have no idea how I could possibly convert a String containing the script name of a GUI or InventoryItem into the actual script object. For characters I was able to use the hidden scrname property. But for everything else I think manual registration of the variables would be required.

Also my console isn't equipped yet for multiple function calls per line and can therefore only accept literal parameters. It provides no type-checking and allows implicit type conversion. And the error handling is terrible.

But it's an interesting concept. Who knows, I might even release the code... :P

Monsieur OUXX

Bump.

Has anyone started using the plugin seriously?
Have you hit any serious issue?

Is it convenient to try controlling AGS from LUA (using that "ags" object DQ mentionned), or is the only working strategy to call LUA from AGS?
(and by the way it must be slow every time AGS calls a LUA function?)

For short : how mature is the plugin?
 

Denzil Quixode

Quote from: Monsieur OUXX on Wed 08/12/2010 19:06:36
Has anyone started using the plugin seriously?
(...)
For short : how mature is the plugin?
I am only aware of one person who has seriously tried to use the plugin, apart from me. I'd say it's therefore still very immature, because it does not have a big proof-of-concept game. (I was hoping to make one, but you know how it is...)

QuoteIs it convenient to try controlling AGS from LUA (using that "ags" object DQ mentionned), or is the only working strategy to call LUA from AGS?
It really depends how you want to use it, unfortunately (I think this is the big problem with the plugin, there is no definitive way to use it.)

Quote(and by the way it must be slow every time AGS calls a LUA function?)
Depends what you mean by slow. It's certainly slower than calling an AGS function but I think you should be able to make quite a lot of Lua calls every frame (assuming 40 fps) before it causes any slowdown.

(Also, this is a very picky thing but:- unlike "AGS", "Lua" doesn't stand for anything, it's just a name, so it's more correct to call it "Lua" rather than "LUA".)

monkey0506

My hard-drive crash manifested whilst using the plugin. Probably not related..but for simplicity's sake..I've decided to just stick to AGS for now. ;P (Considering it took me several weeks to recover from that crash..due to my own lack of backups! :=)

Denzil Quixode

Okay, nobody is using the plugin then :P Oh well. Very sorry to hear about your HD woes, monkey - I've been there...

Monsieur OUXX

Damn I want to use that plugin.
I want to bind AGS with Blender Game Engine :-)

I didn't understand your answer: "It really depends how you want to use it, unfortunately"
Is it unrealistic to hope controlling AGS from the Lua script exactly the same way you'd control your game from the AGS script? Have you bound all AGS objects in your Lua plugin? (That is: Can I iterate through objects, characters, rooms... Can I read the game's parameters... Can I call AGS functions such as "Changeroom".. etc?)
 

Denzil Quixode

#34
Quote from: Monsieur OUXX on Thu 09/12/2010 12:19:11
Is it unrealistic to hope controlling AGS from the Lua script exactly the same way you'd control your game from the AGS script? Have you bound all AGS objects in your Lua plugin? (That is: Can I iterate through objects, characters, rooms...
Can I read the game's parameters... Can I call AGS functions such as "Changeroom".. etc?)
Yes, you can call standard built-in functions and methods, and refer to built-in objects like GUIs, inventory items, etc. The main thing you can't do is directly call your own AGS-script functions, or get/set your own AGS-script variables - there simply isn't any way to do that through the AGS plugin system, currently. You also can't directly control other plugins.

See this page for more info about what you can do through the ags table: http://lua-for-ags.wikispaces.com/agsTable - there's a table that shows the Lua equivalent to things you do in AGS script.

Monsieur OUXX

#35
Quote from: Denzil Quixode on Thu 09/12/2010 12:59:05
Yes, you can call standard built-in functions and methods, and refer to built-in objects like GUIs, inventory items, etc.

I love you.

Quote from: Denzil Quixode on Thu 09/12/2010 12:59:05
The main thing you can't do is directly call your own AGS-script functions, or get/set your own AGS-script variables

That shouldn't be too much of a problem. Duplicating needed modules by translating them into Lua shouldn't be too much work.
And I don't need any other plugins, since I'll be using AGS only for Point-n-click events and character localization. All the rendering (graphics, sounds, physics) will be done by the Blender Game Engine.

By the way, for those who wonder what's my plan -- I want to do pretty much the same as the Character3D plugin, except that I want to break the barriers imposed by the custom mesh editor, the complex engine (Irrlicht), and the limited plugin/Irrlicht mapping
 

monkey0506

The problems with not being able to use custom AGS functions/variables from Lua scripts can be overcome by simply writing them as Lua functions/variables instead. In order to make any use of them they have to be fired off from some AGS-based event anyway, so it's not really an issue.

I was actually doing precisely this..

Some of the AGS methods the plugin provides are a bit wonky to actually use, which I probably would have commented on if I were developing with it further.

But, I had almost fully converted my custom Verbcoin script into Lua..the only things in the AGS script files were calls to the Lua scripts..so it's very useful as-is.

Also, some of the Lua scripting is difficult to use and/or inconsistent with the way AGS handles things. For example, it's impossible in Lua to set the player's active inventory to nil (this crashes the game). Presumably this would be equivalent to setting player.ActiveInventory = null..and I couldn't think of any work-around for this scenario..short of just using AGScript.

Monsieur OUXX

 

Denzil Quixode

Quote from: monkey_05_06
Some of the AGS methods the plugin provides are a bit wonky to actually use, which I probably would have commented on if I were developing with it further.
Like the way you have to use attributes as if they were methods? It actually would have been possible not to do that... but at the cost of potentially making performance a  bit worse, because of the internal magics needed. I'm not sure I made the right decision.

Quote from: monkey_05_06
Also, some of the Lua scripting is difficult to use and/or inconsistent with the way AGS handles things. For example, it's impossible in Lua to set the player's active inventory to nil (this crashes the game). Presumably this would be equivalent to setting player.ActiveInventory = null..and I couldn't think of any work-around for this scenario..short of just using AGScript.
This sounds like an outright bug. It's something I simply forgot to try in my own testing,  I guess. I won't be able to sort it out until next week.

Also, reeading your other comments about having to convert your module made me realise that maybe what would be really useful here would be a special splitscreen utility for the plugin where you can copy and paste AGS script into the left hand side,  click a "Convert" button and it will generate equivalent Lua code on the right hand side. I will look into that too.

Monsieur OUXX

Quote from: Denzil Quixode on Fri 10/12/2010 17:30:45
a "Convert" button and it will generate equivalent Lua code on the right hand side. I will look into that too.

I've tried several times to write a formal Grammar (and the Parser + Code Generator that goes with it) for AGS' scripting language, using a mainstream tool (lately, I was playing with ANTLR ( http://www.antlr.org/). I never found the time and energy to finish them.

Is it the way you plan on writing your "converter"? I think that would be an extremely powerful artefact to put in the hands of AGS developers. It would initiate a whole lot of new wrappers, converters, Plugin "workarounds", etc.
 

SMF spam blocked by CleanTalk