Author Topic: PLUGIN: Lua for AGS  (Read 34220 times)

Re: PLUGIN: Lua for AGS
« Reply #20 on: 08 Oct 2009, 19:42 »
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: Adventure Game Studio
  1. LuaValueList* lparams = Lua.NewValueList();
  2. lparams.Add(Lua.StringValue("test"));
  3. lparams.Add(Lua.IntValue(255));
  4. LuaValueList* lresults = Lua.Call("My_Function", lparams);
  5. 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: Adventure Game Studio
  1. ags.GiveScore(100)
  2. 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

  • Joseph DiPerla, Adventure Game Creator Wannabe!
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: PLUGIN: Lua for AGS
« Reply #21 on: 09 Oct 2009, 03:38 »
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

  • AGS Baker
  • Wild colonial boy.
    • Lifetime Achievement Award Winner
    •  
    • ThreeOhFour worked on a game that was nominated for an AGS Award!
      ThreeOhFour worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #22 on: 09 Oct 2009, 13:12 »
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?

Re: PLUGIN: Lua for AGS
« Reply #23 on: 09 Oct 2009, 14:20 »
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.

Re: PLUGIN: Lua for AGS
« Reply #24 on: 13 Oct 2009, 19:48 »
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: Adventure Game Studio
  1. 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: Adventure Game Studio
  1. "Hello World from " .. _VERSION .. "!"

Here are some other commands you can try:
Code: Adventure Game Studio
  1. ags.Debug(1,0)
Code: Adventure Game Studio
  1. ags.GiveScore(728)
Code: Adventure Game Studio
  1. ags.Mouse.GetPosition()
Code: Adventure Game Studio
  1. 1 + 2
Code: Adventure Game Studio
  1. ags.cCris:Say("Hi, I'm %s!", ags.cCris:Name());
Code: Adventure Game Studio
  1. ags.cCris:ChangeRoom(16,170,180);
Code: Adventure Game Studio
  1. ags.cCris:GiveInventory(ags.iKey)
Code: Adventure Game Studio
  1. ags.StopMusic()
Code: Adventure Game Studio
  1. 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.)
« Last Edit: 13 Oct 2009, 19:54 by Denzil Quixode »

Pumaman

  • Creator of AGS
  • Administrator
  • Mittens Monarch
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: PLUGIN: Lua for AGS
« Reply #25 on: 14 Oct 2009, 22:23 »
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: Adventure Game Studio
  1. ags.Debug(1,0)
Code: Adventure Game Studio
  1. ags.GiveScore(728)
Code: Adventure Game Studio
  1. 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!

Re: PLUGIN: Lua for AGS
« Reply #26 on: 15 Oct 2009, 00:03 »
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

  • Creator of AGS
  • Administrator
  • Mittens Monarch
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: PLUGIN: Lua for AGS
« Reply #27 on: 15 Oct 2009, 20:44 »
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

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
Re: PLUGIN: Lua for AGS
« Reply #28 on: 16 Oct 2009, 22:52 »
a 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
User was banned for this post.

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: PLUGIN: Lua for AGS
« Reply #29 on: 08 Dec 2010, 19:06 »
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?
 

Re: PLUGIN: Lua for AGS
« Reply #30 on: 08 Dec 2010, 20:56 »
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...)

Quote
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?
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

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
Re: PLUGIN: Lua for AGS
« Reply #31 on: 09 Dec 2010, 04:08 »
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! :=)
User was banned for this post.

Re: PLUGIN: Lua for AGS
« Reply #32 on: 09 Dec 2010, 10:33 »
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

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: PLUGIN: Lua for AGS
« Reply #33 on: 09 Dec 2010, 12:19 »
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?)
 

Re: PLUGIN: Lua for AGS
« Reply #34 on: 09 Dec 2010, 12:59 »
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.
« Last Edit: 09 Dec 2010, 13:06 by Denzil Quixode »

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: PLUGIN: Lua for AGS
« Reply #35 on: 09 Dec 2010, 14:23 »
Yes, you can call standard built-in functions and methods, and refer to built-in objects like GUIs, inventory items, etc.

I love you.

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
« Last Edit: 09 Dec 2010, 14:37 by Monsieur OUXX »
 

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
Re: PLUGIN: Lua for AGS
« Reply #36 on: 10 Dec 2010, 05:46 »
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.
User was banned for this post.

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: PLUGIN: Lua for AGS
« Reply #37 on: 10 Dec 2010, 10:34 »
The problems  (...)

Thanks fro the thourough answer!
 

Re: PLUGIN: Lua for AGS
« Reply #38 on: 10 Dec 2010, 17:30 »
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

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: PLUGIN: Lua for AGS
« Reply #39 on: 14 Dec 2010, 09:42 »
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.