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

PLUGIN: Lua for AGS
« on: 04 Sep 2009, 19:30 »
Edit: I decided to update my original post for the new version rather than trying to have several threads, or post updated versions throughout this one. Sorry if this confuses anyone, it just seemed like the best option.


Hello!

This is my first plugin. It is quite experimental, but I'm fairly pleased with the way it's gone so far. I've developed it against version 3.1.2SP1 (build 3.1.2.82) and haven't had a chance to try it with other versions, so I'm not sure how well it works with them.

Download it here:


The purpose of the plugin is to allow you to write parts of your game's code in Lua, an alternate scripting language to AGS-Script. It is intended for people who are already fairly comfortable with scripting and are interested in trying something a bit different.

The files included in the package are five DLLs - AGS.Plugin.Lua.dll, AGSPlugin.SciLexer.dll, agslua.dll, lua51.dll and lua5.1.dll. Copy all of them into the AGS application home directory. Once you have these DLLs in place and you fire up AGS, there will be a new icon in the project tree called simply "Lua", and also a new entry in "Plugins" called "Lua Run-Time Component". Both of these are disabled by default, and should have no effect until you choose to activate them for a particular game. You need to have both of them active or inactive or you will probably get odd errors. (I'd recommend trying it first on a demo game rather than something important, just in case.)


To create your first Lua script, expand the "Lua" icon, right-click on the "Lua Scripts" icon inside it and select "New Lua script...". Choose a suitable name for it in the window that pops up, and click "Create".


Okay, you will now have to enter some Lua code. How to write Lua itself is not something I'll go into too deeply just yet, but to get you started:
  • Lua has strings, numbers and boolean values, just like in AGS-Script. (However, there is only one "kind" of number, rather than int, short, float etc.)
  • You do not need to declare the type of your variables - i.e. just 'a = 5' is fine, you do not need to tell Lua that 'a' is a number.
  • However, you do need to declare that a variable should be local to a function, by putting 'local' before it the first time you use it, e.g. 'local a = 5'. Otherwise, you are setting the value of a global variable called 'a' that other functions could overwrite.
  • In Lua, zero is not considered to be "false". For example, in Lua if you write "if (0) then ... end", the inside of the block is run - compare this to AGS-Script, Javascript and other "C"-based languages where "if (0) { ... }" will not run the statements inside the block. (That is a fakey example, a more realistic one is that you might have a function that returns 0 or 1 to indicate success or failure.) The only values considered "false" are the boolean value false, and nil (which is basically what Lua calls null).
  • You do not need to end your statements with a semicolon - but you can if you want;
  • Blocks start and end with words, instead of C-style { } curly braces:
  • function funcname(param1,param2,param3)  [...]  end
  • if [condition] then  [...]  elseif [condition] then  [...]  else  [...]  end
  • while [condition] do  [...]  end
  • If you want a series of if-else-if conditions, you will most likely want to use use elseif (all one word) rather than "else if", which is valid but not what you might expect.
The scripts are saved in a subfolder of your game project directory called "lscripts". You can right-click on the "Lua Scripts" icon and select "Refresh" to reflect changes to the lscripts directory made outside of the AGS Editor.

Once you have written a Lua script, you will want to run it as the game is starting up. If you don't do this, any functions you define inside the script will not be available later on. Open the GlobalScript.asc file and add Lua.RunScript("test.lua"); into the game_start() function (replace "test.lua" with the name of your script if you called it something different):

Code: Lua
  1. function game_start()
  2. {
  3.   Lua.RunScript("test.lua")
  4.   // (... the rest of your initialisation code ...)
  5. }

Okay. Now to test calling your function. Go to a room script and in the handler function for some activity (looking at a hotspot or something), add:

Code: Lua
  1. function hHotspot1_Look()
  2. {
  3.   LuaValue* result = Lua.Call("hello");
  4.   player.Say(result.AsString);
  5. }

What this does is to call the Lua global function "hello", convert the return value to a string, and pass it to player.Say(). It is the equivalent of player.Say(hello());, if hello() was an AGS function rather than a Lua one.

Okay! You are now ready to try compiling and running your game. Hopefully, your player character will say the string returned from the Lua function. (If not, please let me know!)

If you are wondering how using this plugin affects things:
  • A file called lscripts.dat will be created in your "Compiled" folder. This file contains all of the files from the lscripts directory. It is from this that Lua.RunScript() is actually loading them, not from the original source code files. This file is not a plain-text file and should provide enough protection to stop casual curious people from snooping in your scripts (it's not strongly encrypted or anything, but it doesn't make it easy).
  • Save games are bigger - by a few dozen kilobytes, even if you don't define your own functions. The more you add into the Lua "universe", the bigger this will get. But it should remain sensible - let me know if it seems to be making your save files really huge.

I have put up a page explaining more about what you can do with the plugin here: http://lua-for-ags.wikispaces.com/UsingLuaForAGS Link not working
« Last Edit: 01 Mar 2015, 05:05 by Dualnames »

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
    • Kweepa worked on a game that was nominated for an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #1 on: 04 Sep 2009, 20:30 »
Wow, nice work!
How does the speed compare with AGS scripting?
I can see this being pretty useful for data management.
Still waiting for Purity of the Surf II

Re: PLUGIN: Lua for AGS
« Reply #2 on: 04 Sep 2009, 20:39 »
I have not yet had time to properly benchmark them against each other, but Lua is considered very fast for a dynamically-typed language. It probably is still not fast enough to do real-time graphics effects that need to do lots of pixel manipulation every frame or something, but still, it should be fast enough for you not to be able to tell the difference most of the time.

Re: PLUGIN: Lua for AGS
« Reply #3 on: 06 Sep 2009, 15:47 »
Edit: This post used to be some out-of-date information about calling Lua functions from AGS.
See this Wiki page for the most up-to-date info on that: http://lua-for-ags.wikispaces.com/LuaValueLists
« Last Edit: 27 Sep 2009, 17:24 by Denzil Quixode »

Pumaman

  • Creator of AGS
  • Administrator
  • Mittens Monarch
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: PLUGIN: Lua for AGS
« Reply #4 on: 06 Sep 2009, 22:06 »
This is pretty neat work!

Quote
I realise that what I haven't demonstrated yet is any compelling reason why you would want to have the option of writing part of your game in Lua.

Yes, I think this would be useful :) 
If it allows things like resizable collections to be easily supported then that would be quite cool.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: PLUGIN: Lua for AGS
« Reply #5 on: 07 Sep 2009, 01:14 »
I realise that what I haven't demonstrated yet is any compelling reason why you would want to have the option of writing part of your game in Lua. In time I hope to be able to do this, but for now you may have to just trust me on that.

Grim Fandango was scripted in Lua. Therefore, obviously, working in Lua will enable you to make games as good as Grim Fandango.

Done and done!

Re: PLUGIN: Lua for AGS
« Reply #6 on: 07 Sep 2009, 15:59 »
Haha  ;D. It's true that Grim Fandango was scripted in Lua, and other games like Psychonauts, and I believe companies like Telltale and PopCap use it in the frameworks for their games. It's popular because it's very small and light, very cleanly coded so it compiles on almost anything, very permissively-licensed (you can use it freely in commercial and non-commercial things without paying for it or agreeing to release any of your own code) and very fast (again, for a dynamic scripting language, not compared to C++ or something).

Okay, this is the first in a short series of posts I'm gonna do about some of Lua's features. This is partly an introduction of how to use Lua, and partly explanation of what I think Lua is good at & valuable for. So, if you're interested in learning Lua, don't solely rely on these, as I might be skipping things that you'd like to know in favour of things I think are cool. All feedback is welcome! :)

Edit: Moved to http://lua-for-ags.wikispaces.com/DataDefinition
« Last Edit: 27 Sep 2009, 14:41 by Denzil Quixode »

SSH

  • Flying round the world at the speed of haggis
    • I can help with scripting
    •  
    • SSH worked on a game that was nominated for an AGS Award!
      SSH worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #7 on: 07 Sep 2009, 17:35 »
This is so great: it lets me make TWO terrible puns in one blog post!

http://ags-ssh.blogspot.com/2009/09/lua-of-temptress.html

Re: PLUGIN: Lua for AGS
« Reply #8 on: 07 Sep 2009, 18:23 »
Hey, thanks, SSH! Much appreciated.

(Also, it's funny you should mention puns - Lua was created in Brazil, named after the Portuguese word they use for "moon". Apparently it was originally intended to replace a previous scripting language they were using called "Simple Object Language", or "SOL" - and "sol" is also the Portuguese word for "sun"...)

(...I know way too much about this.  :P)

Re: PLUGIN: Lua for AGS
« Reply #9 on: 07 Sep 2009, 19:33 »
« Last Edit: 27 Sep 2009, 15:10 by Denzil Quixode »

Ascovel

  • Mittens Serf
  • The eyes of Rooster Cockburn
    • I can help with story design
    •  
    • Ascovel worked on a game that was nominated for an AGS Award!
      Ascovel worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #10 on: 07 Sep 2009, 21:10 »
Somehow I always thought Lua was something made internally at LucasArts specifically for Grim Fandango.

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
    • Edmundito worked on a game that was nominated for an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #11 on: 08 Sep 2009, 01:41 »
Actually, what happened was that the lead programmer for Grim Fandango found that Lua was just what they were looking for to replace the SCUMM language, and it's apparently recorded as the first game to use the language (for game scripting) (see: http://www.lua.org/history.html and word search for "grim fandango"). Now days it's pretty much becoming the adopted standard for professional game scripting* because it's easy to integrate into anything and it also it's lightweight enough to work with consoles like the Wii.

---

Very interesting work, Denzil! I always wondered myself what it would be like if AGS switched to a more standardized language, and something that's late-binding based. I have done Lua integration in the past, and there's a couple of things that bugged me overall that are huge "gotchas" when you learn:

1. Counting starts at 1, not 0. Oh my!
2. Unless you defined a variable local inside a function it will be global, like JavaScript.
3. There's no decent debugger implementation that can be plugged in. You have to write your own.

That being said, adding this sort of scripting could be the missing piece for a project that I was working on in AGS earlier... actually, can you distribute a game with open Lua scripts? As in I got my agsgame.exe file somewhere, and I let the player write their own script. Is that possible?

---

* Not to say that there are other scripting languages like UnrealScript, Lisp, or Python, but Lua is very widely adopted.... I mean, WoW uses it!
« Last Edit: 08 Sep 2009, 01:44 by Edmundito »
Start using the Tween 2 Module!

Re: PLUGIN: Lua for AGS
« Reply #12 on: 08 Sep 2009, 02:08 »
I have done Lua integration in the past, and there's a couple of things that bugged me overall that are huge "gotchas" when you learn:

1. Counting starts at 1, not 0. Oh my!
I agree, it's a bummer. There's not a lot you can do except get used to it and warn people as quickly as possible. Hopefully it not a deal-breaker for too many people. (Some people try to hack Lua to go from 0, but I'm not going down that route.)
Quote
2. Unless you defined a variable local inside a function it will be global, like JavaScript.
Yeah, I was annoyed about this too, but it turns out that making variables local by default is an even worse choice, because of the way Lua does variable-scoping (which is really good, and honestly not worth sacrificing to avoid having to write "local" all over the place, IMHO). Maybe in some future version they will be clever enough to find a solution for it, but it really is a more complicated situation than just a bad design choice.
Quote
3. There's no decent debugger implementation that can be plugged in. You have to write your own.

That being said, adding this sort of scripting could be the missing piece for a project that I was working on in AGS earlier... actually, can you distribute a game with open Lua scripts? As in I got my agsgame.exe file somewhere, and I let the player write their own script. Is that possible?
Sure - The standard Lua functions loadstring() and loadfile() are available to compile script strings/files into new functions.
« Last Edit: 08 Sep 2009, 18:06 by Denzil Quixode »

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 #13 on: 08 Sep 2009, 17:58 »
Awesome work DQ!!!!! Probably one of the top 5 most useful plugins.
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

Re: PLUGIN: Lua for AGS
« Reply #14 on: 08 Sep 2009, 19:00 »
Thanks for the support  :) It's still quite early days though. What I really want to do is start making AGS functions available to the Lua scripts (I mean the in-built AGS functions, not the ones you define yourself in the global/room scripts - I don't think there is a way to call those from a plugin) and add objects to the Lua universe that represent AGS characters, inventory items etc. These objects would support the standard methods (for a character: Say, WalkTo, etc.) but also, allow you to add your own custom methods and fields.

For example, eventually you should be able to do this (Lua):

Code: Adventure Game Studio
  1. -- get an AGS character object from a special "ags" table managed by the plugin
  2. local cEgo = ags.cEgo
  3.  
  4. -- add a new custom method to it (note the colon instead of a dot - this is Lua "method" syntax)
  5. function cEgo:Greeting()
  6.         -- "self" inside a Lua method is like "this" in AGS-Script, Javascript etc. - like an invisible parameter
  7.         -- that refers to the parent object (in this case, cEgo, although we could reuse this function for different
  8.         -- characters)
  9.         self:Say("I feel... odd...")
  10.         self:Say("Lua... is... controlling me...")
  11. end

...and then, you would also be able to call these Lua methods from AGS-Script, in a similar way to calling a global function using Lua.Call:

Code: Adventure Game Studio
  1. function room_AfterFadeIn()
  2. {
  3.     cEgo.LuaMethod("Greeting", null, null);        // Call cEgo:Greeting() with no parameters or return values
  4. }

(This is speculative, it isn't implemented yet, but I think it should all be possible.)
« Last Edit: 09 Sep 2009, 02:02 by Denzil Quixode »

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 #15 on: 08 Sep 2009, 21:07 »
Lots of hard work ahead of you. But if you get LUA to work with AGS like that, you will have made AGS the most powerful Windows Engine on the market. Now all thats needed is a port of the Run-time plugin so that it would work on the Linux and MAC versions when/If they catch up.

---

ERRRR. The freeware/swapware market that is.
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

Re: PLUGIN: Lua for AGS
« Reply #16 on: 16 Sep 2009, 14:01 »
I am hoping to get a new version out in the next couple of days. In the meantime I'm going to return to that question of why using Lua in AGS would ever be useful. One Lua feature that I haven't mentioned yet is coroutines. I'm not going to describe what they actually are here, or how to directly create and use them - instead, I'm going to try to outline something quite tricky to do in AGS that could be easier to do with Lua, and (for now) just say that coroutines are the magic that would let it work.



Say you're making a game where the PC is a member of crew on board a space ship. You want to give the impression in-game that the crew is a real community of people having independent lives. You don't want the NPCs to just stand/sit around, waiting for the PC to approach them before they do anything. They may move around, from room to room, start conversations of their own that you can eavesdrop on (or wander away from, if you're not interested). If you interrupt people in the middle of a conversation, they might carry it on where they left off, later. And so on.

An important part of being able to achieve that is being able to easily set up a chain of simple events that run like a cutscene, but unlike a cutscene, you don't want the game to block while it's going on - there might even be several of these things going on simultaneously in the same room, and the PC should be free to walk around and do stuff. Let's call them non-blocking cutscenes.

So, how would you implement that? Let's start with a fairly simple chain of events like: an NPC walks across the room to a particular point, pauses a second, runs an animation loop, walks across to another point, pauses again, faces the PC, says something, then walks out of the room. The best way I can see how to do it is to split this up into a sequence of steps, give them all a number, and do a big if-else-if block in the main script's repeatedly_execute() function, where each step waits for the previous one to finish before continuing. Something like this:

Code: Adventure Game Studio
  1. //(AGS Script)
  2.  
  3. // Counter to keep track of where we are in the sequence
  4. int SEQUENCE_1_STEP = 0;
  5. // Timer ID to use when waiting for NPC to finish pausing
  6. #define PAUSE_TIMER  10
  7. // Overlay for background speech
  8. Overlay* bgSpeechOverlay;
  9.  
  10. function repeatedly_execute() {
  11.         // Set SEQUENCE_1_STEP to 1 to kick things off
  12.         if (SEQUENCE_1_STEP == 0) {
  13.                 // do nothing
  14.         }
  15.         else if (SEQUENCE_1_STEP == 1) {
  16.                 // Walk over to a point...
  17.                 cNPC.Walk(50, 100, eNoBlock);
  18.                 SEQUENCE_1_STEP = 2;
  19.         }
  20.         else if (SEQUENCE_1_STEP == 2) {
  21.                 if (!cNPC.Moving) {
  22.                         // ... pause ...
  23.                         SetTimer(PAUSE_TIMER, 80);
  24.                         SEQUENCE_1_STEP = 3;
  25.                 }
  26.         }
  27.         else if (SEQUENCE_1_STEP == 3) {
  28.                 if (IsTimerExpired(PAUSE_TIMER)) {
  29.                         // ... run an animation ...
  30.                         cNPC.Animate(3, 1, eOnce, eNoBlock);
  31.                         SEQUENCE_1_STEP = 4;
  32.                 }
  33.         }
  34.         else if (SEQUENCE_1_STEP == 4) {
  35.                 if (!cNPC.Animating) {
  36.                         // ... walk across to another point ...
  37.                         cNPC.Walk(240, 80);
  38.                         SEQUENCE_1_STEP = 5;
  39.                 }
  40.         }
  41.         else if (SEQUENCE_1_STEP == 5) {
  42.                 if (!cNPC.Walking) {
  43.                         // ... pause ...
  44.                         SetTimer(PAUSE_TIMER, 80);
  45.                         SEQUENCE_1_STEP = 6;
  46.                 }
  47.         }
  48.         else if (SEQUENCE_1_STEP == 6) {
  49.                 if (IsTimerExpired(PAUSE_TIMER)) {
  50.                         // ... face the PC ...
  51.                         cNPC.FaceCharacter(cEgo, eNoBlock);
  52.                         SEQUENCE_1_STEP = 7;
  53.                 }
  54.         }
  55.         else if (SEQUENCE_1_STEP == 7) {
  56.                 if (!cNPC.Animating) {
  57.                         // ... say something ...
  58.                         bgSpeechOverlay = cNPC.SayBackground("...are you responsible for this?");
  59.                         SEQUENCE_1_STEP = 8;
  60.                 }
  61.         }
  62.         else if (SEQUENCE_1_STEP == 8) {
  63.                 if (!bgSpeechOverlay.IsValid) {
  64.                         bgSpeechOverlay = null;
  65.                         // ... then walk out of the room.
  66.                         cNPC.Walk(0, 150, eNoBlock);
  67.                         SEQUENCE_1_STEP = 9;
  68.                 }
  69.         }
  70.         else if (SEQUENCE_1_STEP == 9) {
  71.                 if (!cNPC.Moving) {
  72.                         cNPC.ChangeRoom(10);
  73.                         SEQUENCE_1_STEP = 0;
  74.                 }
  75.         }
  76. }

So that's the first one done. In about sixty lines of code, with an int and an Overlay* to keep track of. We've also used up one of only 20 available timers. It is starting to look daunting to have dozens of these throughout the game. Now, obviously, you can start trying to make it a bit more managable by moving this code out of repeatedly_execute() into a new script, dedicated to these non-blocking cutscene things, and have repeatedly_execute() just call a handler function for each one in turn. You can try to squish each if-else-if step to be on a single line, to try and make it easier to see what's going on throughout the sequence at a glance, but that will probably end up making it even less readable. In order to get around that limited number of timers, you could try using another int variable, that you decrement every turn during the right SEQUENCE_x_STEP until it reaches zero. But it's starting to get annoying just naming all these variables.
 
It's also no fun tinkering with the sequences, since adding or removing steps means changing all of the SEQUENCE_x_STEP numbers after that point, which takes ages and it's easy to make a mistake. Then there's one sequence where you'd like to repeat part of it in the middle three or four times before continuing, but there's no way of doing it that feels right. You could just copy and paste the steps, then fix up all the SEQUENCE_x_STEP numbers (time-consuming, since there's quite a lot of steps involved - and also, what if you decide later you want to change the number of loops, or alter the steps inside the loop...?). Or, you could create another decrementing int variable, one that counts down the number of loops and decides whether to send SEQUENCE_x_STEP "back in time" to the beginning of the loop or not (which would hurt code-readability even more, as you have to read it back carefully to see where the loop starts and finishes - also, if you want to run the whole sequence multiple times, it's easy to forget to reset this loop variable, so the looped part only plays once the next time...)



Okay, enough hypothetical lecturing, I'm sure you get the picture - this is a case where you'd probably end up compromising quite heavily, to avoid making too much work for yourself, and to keep the code from getting unmanageable. So how could Lua help?

(First of all, this isn't yet possible with the currently-released version, because you can't call AGS system functions from Lua. But you will be able to in the next one.)

I would write a Lua script for handling non-blocking cutscenes, that adds:
  • NonBlockingCutscene_Start(), a function that kicks off a new nonblocking cutscene
  • NonBlockingCutscene_Wait(), a special version of Wait() for non-blocking cutscenes (it only works inside one)
  • several Character extender methods for non-blocking-cutscene versions of standard Character methods - i.e. Character:NonBlockingCutscene_Walk(), Character:NonBlockingCutscene_Animate(), etc.
  • NonBlockingCutscenes_Update(), a function that keeps all currently-running cutscenes ticking over (to be called once every frame)
I won't give you the code for this script now, but it really isn't that long or complex - I will include something like it as an example script in a later version of the plugin.

Only one new line in repeatedly_execute() would be necessary:

Code: Adventure Game Studio
  1. //(AGS Script)
  2. function repeatedly_execute() {
  3.         Lua.Call("NonBlockingCutscenes_Update", null, null);
  4.         // (... rest of repeatedly_execute ...)
  5. }
  6.  

...and the implementation of a single cutscene using this system would be something like:

Code: Adventure Game Studio
  1. --(Lua)
  2. function ags.cNPC:MyCutscene()
  3.  
  4.         NonBlockingCutscene_Start(function()
  5.                 ags.cNPC:NonBlockingCutscene_Walk(50, 100)
  6.                 NonBlockingCutscene_Wait(80)
  7.                 ags.cNPC:NonBlockingCutscene_Animate(3, 1)
  8.                 ags.cNPC:NonBlockingCutscene_Walk(240, 80)
  9.                 NonBlockingCutscene_Wait(80)
  10.                 ags.cNPC:NonBlockingCutscene_FaceCharacter(ags.cEgo)
  11.                 ags.cNPC:NonBlockingCutscene_Say("...are you responsible for this?")
  12.                 ags.cNPC:NonBlockingCutscene_Walk(0, 150)
  13.                 ags.cNPC:ChangeRoom(10)
  14.         end)
  15.  
  16. end
  17.  

When you want to start this cutscene from AGS Script, you would call the "MyCutscene" Lua method on cNPC, like this:

Code: Adventure Game Studio
  1. //(AGS-Script)
  2. cNPC.LuaMethod("MyCutscene", null, null);
  3.  

Changing it to loop over part of the sequence a couple of times, using a for-loop:

Code: Adventure Game Studio
  1. --(Lua)
  2. function ags.cNPC:MyCutscene()
  3.  
  4.         NonBlockingCutscene_Start(function()
  5.                 -- repeat this bit 3 times before continuing
  6.                 for i = 1, 3 do
  7.                         ags.cNPC:NonBlockingCutscene_Walk(50, 100)
  8.                         NonBlockingCutscene_Wait(80)
  9.                         ags.cNPC:NonBlockingCutscene_Animate(3, 1)
  10.                         ags.cNPC:NonBlockingCutscene_Walk(240, 80)
  11.                         NonBlockingCutscene_Wait(80)
  12.                 end
  13.                 ags.cNPC:NonBlockingCutscene_FaceCharacter(ags.cEgo)
  14.                 ags.cNPC:NonBlockingCutscene_Say("...are you responsible for this?")
  15.                 ags.cNPC:NonBlockingCutscene_Walk(0, 150)
  16.                 ags.cNPC:ChangeRoom(10)
  17.         end)
  18.  
  19. end
  20.  

Part of my goal for this plugin is to make it as unobtrusive as possible, so you can use it for just one section of the game (even just one NPC) and just ignore it the rest of the time, if you wish. I don't pretend that Lua will make it easier to write any part of a game, but I believe it does have the potential to make some very cool things much easier.
« Last Edit: 16 Sep 2009, 14:38 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #17 on: 16 Sep 2009, 18:03 »
I just thought of another example. One thing that I think is quite common is you'll have a list of messages in response to some action, and you'd like to select one each time according to a pattern, like:
  • Pick each one in turn, until the last one, then just keep showing that one
  • Pick each one in turn, then return to the first when you go past the end
  • Pick one at random

This is how you might implement the first one in AGS:

Code: Adventure Game Studio
  1. //(AGS-Script)
  2.  
  3. int MESSAGE_INC = 0;
  4. #define LAST_MESSAGE 5
  5. String NextMessage() {
  6.         if (MESSAGE_INC < LAST_MESSAGE) {
  7.                 MESSAGE_INC = MESSAGE_INC + 1;
  8.         }
  9.         if (MESSAGE_INC == 1) {
  10.                 return "I don't want to.";
  11.         }
  12.         if (MESSAGE_INC == 2) {
  13.                 return "I really don't want to.";
  14.         }
  15.         if (MESSAGE_INC == 3) {
  16.                 return "I really REALLY don't want to.";
  17.         }
  18.         if (MESSAGE_INC == 4) {
  19.                 return "Okay. Oh, wait, no.";
  20.         }
  21.         if (MESSAGE_INC == 5) {
  22.                 return "No.";
  23.         }
  24. }
  25.  
It's easily possible, but you do have to deal with numbers all the time, which feels sort of unnecessary. If you want to add or remove one early on in the list, you have to go through fixing the rest of the numbers, and remembering to set LAST_MESSAGE as well.

The second pattern is really just a minor change to the first one, so I won't bother with that. What about random order?
Code: Adventure Game Studio
  1. //(AGS-Script)
  2. String RandomMessage() {
  3.         int rand = Random(4);
  4.         if (rand == 0) {
  5.                 return "Boring.";
  6.         }
  7.         else if (rand == 1) {
  8.                 return "Irrelevant.";
  9.         }
  10.         else if (rand == 2) {
  11.                 return "Mind-numbing.";
  12.         }
  13.         else if (rand == 3) {
  14.                 return "Yawn.";
  15.         }
  16.         else if (rand == 4) {
  17.                 return "It's a picture of Gordon Brown.";
  18.         }
  19. }
Still dealing with a lot of numbers, although it's never a pain to add more in this case, since order doesn't matter.



With Lua, I would first write a script that adds "selector factories" - special reusable functions that do the grunt work of implementing these patterns for you - and then use them to create NextMessage and RandomMessage (which will be ordinary Lua functions that you can call with Lua.Call()):

Code: Adventure Game Studio
  1. --(Lua)
  2.  
  3. NextMessage = selector.oneshot({
  4.         "I don't want to.";
  5.         "I really don't want to.";
  6.         "I really REALLY don't want to.";
  7.         "Okay. Oh, wait, no.";
  8.         "No.";
  9. })
  10.  
  11. RandomMessage = selector.random({
  12.         "Boring.";
  13.         "Irrelevant.";
  14.         "Mind-numbing.";
  15.         "Yawn.";
  16.         "It's a picture of Gordon Brown.";
  17. })
  18.  

With the message lists written like this, you can very easily add, remove, and reorder the items, and also, change one selector pattern to another. Again - nothing that is impossible to do in AGS-Script - but you probably wouldn't bother.

(Like the NonBlockingCutscene stuff in the previous example, selector.oneshot and selector.random are not standard existing functions, I will include a script that implements them in the next version.)
« Last Edit: 16 Sep 2009, 18:17 by Denzil Quixode »

SSH

  • Flying round the world at the speed of haggis
    • I can help with scripting
    •  
    • SSH worked on a game that was nominated for an AGS Award!
      SSH worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #18 on: 16 Sep 2009, 19:38 »
Of course with this example you could also use my MultiResponse module ;)

Re: PLUGIN: Lua for AGS
« Reply #19 on: 16 Sep 2009, 20:28 »
Ah, oops  :-[. Sorry, SSH - I haven't actually tried a lot of modules or plugins myself before, so I'm not really aware what else is already out there. I should probably do that before I try to give more examples...

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
  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    •  
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

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
  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    •  
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! :=)

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
  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    •  
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.

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.
 

Re: PLUGIN: Lua for AGS
« Reply #40 on: 14 Dec 2010, 17:06 »
Hmm, I hadn't even heard of ANTLR before... interesting. Actually I happen to already have most of a hand-written C# parser done already, which creates an object-based representation of AGS Script. I would be happy to extract it from the project I was making it for and fix it up into a reusable middleware DLL that people can use in their own plugins. (I'd release it as open source, too, why not.) I need a few days though - my main laptop is in for repairs at the moment and that's got all my plugin stuff on it...

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 #41 on: 14 Dec 2010, 20:53 »
Look up GOLD Parser Generator as well. That seems to be a good one. If you like in the General Forum, I posted a topic on it yesterday.
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

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 #42 on: 16 Dec 2010, 13:14 »
I happen to already have most of a parser done already. I would be happy to extract it from the project I was making it for and fix it up into a reusable middleware DLL.

DO IT!  :D :D :D

<3
 

Re: PLUGIN: Lua for AGS
« Reply #43 on: 18 Dec 2010, 13:05 »
I happen to already have most of a parser done already. I would be happy to extract it from the project I was making it for and fix it up into a reusable middleware DLL.

DO IT!  :D :D :D

<3
OK, I've started a project at http://spags.googlecode.com/ (SPAGS: Script Parser for AGS :P). If you can use SVN you should be able to get it. It includes a project for a test plugin SPAGSTest that creates a file called scripts_dump.txt in the game's project directory (select the SPAGS > Dump Scripts menu item) which isn't very useful on its own but hopefully demonstrates what the parser has understood. Also the source code for that plugin should hopefully be instructive for how to use SPAGS itself - though things might change a bit in the future, it's still very much a work in progress. Also currently it only handles global scripts, not yet room scripts or dialog scripts - but it should be able to handle any global script that would compile normally.

When it's a bit more mature I'll make a thread about it in the technical forum, but I'm still tinkering with it for now.
« Last Edit: 18 Dec 2010, 13:14 by Denzil Quixode »

monkey0506

  • AGS Project Tracker Admins
  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    •  
Re: PLUGIN: Lua for AGS
« Reply #44 on: 18 Dec 2010, 16:01 »
You should seriously consider renaming it "SPAGHETTI!"..the YTPers would love you.

Re: PLUGIN: Lua for AGS
« Reply #45 on: 18 Dec 2010, 20:21 »
I've had a peek at the code and it's not too dissimilar to how the conversion works in XAGE, i.e. Tokenising the AGS scripts and then spitting it out in a new format.  I have no experience with LUA so I'm unfamiliar with the format, but it's interesting to see the corresponding structure in scripts_dump.txt.  Excellent work as usual, Mr. Quixode :)
XAGE - Cross-Platform Adventure Game Engine (alpha)

Re: PLUGIN: Lua for AGS
« Reply #46 on: 18 Dec 2010, 21:03 »
Thanks! The scripts_dump.txt output isn't anything related to Lua, by the way, it's just an arbitrary format for demonstrative purposes but doesn't really have any use as it is.

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 #47 on: 05 Sep 2011, 15:32 »
SPAGS (SPAGS: Script Parser for AGS :P).

Bump.

@Denzil: Is this going forward?
In other words:
- did you run tests on many arbitrary scripts (i.e. from random modules from the forum) to see if they get parsed properly?
- do you get many "false positive" tests (regarding alleged syntax errors in the scripts) ?

 

Re: PLUGIN: Lua for AGS
« Reply #48 on: 05 Sep 2011, 16:04 »
I ran it on as many Module scripts as I could find (from the appropriate forum), hoping that they would cover complex and exotic uses of AGS script. That is the best source of freely-available non-trivial source code that I was able to find.

There may well be cases where it parses a script successfully where the real parser would fail (for example, I think assigning to a property of a struct* returned by a function probably works, where the real parser chokes) - but at as far as I know it should parse all correct scripts correctly. I have not looked at it in a while, though.

If you have some examples of scripts that you think I should look at, let me know.

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 #49 on: 05 Sep 2011, 16:22 »
If you have some examples of scripts that you think I should look at, let me know.

That wasn't the goal of my post, but come to think of it, I did some extensive use of macros in AGSH (see the link in my signature), and I remember I found onr or 2 glitches in the original parser at the time. I haven't checked if the download links in the AGSH thread are broken or not.

Anyway it doesn't really matter. Your parser seems to be solid by now. COOL.
 

Re: PLUGIN: Lua for AGS
« Reply #50 on: 12 Mar 2012, 15:57 »
I've finally had the chance to use this plugin in my new project and, boy, it's awesome! Goodbye, restrictions of AGS scripts! Welcome, content that can be modified while running the game and reloaded with the press of a button (requires custom code, but still)! Thanks so much for the plugin, Denzil!

I don't know if you're still willing to maintain it after all these years but here are some things I've noticed:

EDITOR
- Renaming scripts results in duplicate files. (At least inside the editor.)

ENGINE
- Why aren't the game.variables available to the scripts?
- ags.getplayer() doesn't seem to work properly. I tried to get the current room number by calling ags.getplayer():Room() but it returned a table. Calling ags.cEgo:Room() worked just fine.


--edit--

And now suddenly, I keep getting an error that goes something like this: "[Lua] attempting to concatenate a table value". No line number, nothing. And it seems like the error happens after a successful function call from AGS to Lua and before the next call. Maybe it's a bug in the plugin? I'm out of ideas.

If it helps, I've created many different classes (table, metatable, etc.) before this but now that I'm trying to make an Inventory class, it just keeps crashing. Doesn't matter if it's a class or a plain table but sometimes I can define some functions into it and sometimes I can't. Sometimes the error goes away for a while after I comment out some class method call. Very weird.

--edit2--

Maybe it has something to do with the serialization of the Lua state? The crash has always occurred after game_start but before any other events that call the scripts. That's when the default restart point is saved, right?

--edit3--

Probably the same thing that happens sometimes with the editor. I try to compile the game and it says it can't write the exe since it's in use, even though it isn't. After one or more tries it works just fine. Just a moment ago I started the game and it crashed with the error (see above). Then I tried to start the game again. I didn't modify anything but now it started ok. So yeah, what the hell...

--edit4--

Worked around the crash by delaying script loading to the first on_event call. Saving the game produces the crash sometimes, so it's still a very big problem.

And one other thing.. How can I set ActiveInventory to null? ags.cEgo:ActiveInventory( nil / false ) crashes the game because the value isn't an InventoryItem.
« Last Edit: 16 Mar 2012, 20:50 by AJA »

Re: PLUGIN: Lua for AGS
« Reply #51 on: 20 Mar 2012, 01:27 »
I've finally had the chance to use this plugin in my new project and, boy, it's awesome! Goodbye, restrictions of AGS scripts! Welcome, content that can be modified while running the game and reloaded with the press of a button (requires custom code, but still)! Thanks so much for the plugin, Denzil!
You're welcome! :)
Quote
I don't know if you're still willing to maintain it after all these years but here are some things I've noticed:
I'm willing to maintain it! I just kinda... haven't been  :-\

Some of the bugs that you describe I think - not certain - but I think they are already fixed in the development version, but it just never got turned into a release version. Either way I will try to sort out a new proper release version soon (and feel free to yell at me if I take too long again :)).

Quote
Why aren't the game.variables available to the scripts?

This might be a restriction of the plugin API. Accessing struct fields is a different thing internally to accessing properties (which are really just getter/setter methods).

Quote
The crash has always occurred after game_start but before any other events that call the scripts. That's when the default restart point is saved, right?
Yeah, I think so.

Re: PLUGIN: Lua for AGS
« Reply #52 on: 20 Mar 2012, 02:00 »
I'm willing to maintain it! I just kinda... haven't been  :-\

Understandably. :)


Some of the bugs that you describe I think - not certain - but I think they are already fixed in the development version, but it just never got turned into a release version. Either way I will try to sort out a new proper release version soon (and feel free to yell at me if I take too long again :)).

I tried saving the game with the dev version you sent me and it hasn't crashed so far! Great! Thanks! :D

The getplayer function is still acting oddly, though. Calling ags.getplayer():Room() to get the room number actually calls my Lua defined table called Room. :-\ And the editor bug is still there too.


Quote
Quote
Why aren't the game.variables available to the scripts?

This might be a restriction of the plugin API. Accessing struct fields is a different thing internally to accessing properties (which are really just getter/setter methods).

Good point.


I'm thinking of releasing the framework I've written in Lua once I've finished my game. Maybe that'll get more people interested in the plugin. The framework pretty much removes any need for scripting in AGS; you don't even have to link events to their handlers, just the AGS objects to their Lua counterparts.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #53 on: 29 Mar 2012, 14:42 »
I like this idea.. I will give it a spin.

Is there anything that you would like to be added to the plugin API in order to improve the functionality of the plugin?

Re: PLUGIN: Lua for AGS
« Reply #54 on: 30 Mar 2012, 10:51 »
For the editor plugin, one problem I remember is there is no way to investigate audio clips through the IGame interface. (There's some other things that are missing from IGame, but I needed them for a custom exporter plugin, not the Lua plugin: which character is the player character, global messages, text parser information, property schema, lip sync information.)

For the runtime plugin, there are things that work but it would be great if they could be more official/documented: the way you have to pass "float" arguments/return values, for example. And getting the address of global variables using the function for getting the address of functions.

Re: PLUGIN: Lua for AGS
« Reply #55 on: 07 Apr 2012, 15:32 »
It would be nice if we could od simple Lua to AGS script function calls using the CallGameScriptFunction and QueueGameScriptFunction plugin API functions. Even though it's limited you can at least pass the proper parameters by reading them from Lua inside the AGS script function. Right?

And what about the undocumented bool Character.on property? That would be useful to easily hide the player character.


-edit-
Oh, Lua + AGS, how have I ever been able to live without you?

Anybody ever wanted to do something like this?

Code: Adventure Game Studio
  1. player.Say( "Who's that behind the door? Hello?" );
  2. dude.Say( "It's me. The dude." );
  3.  
  4. cutToRoom( ROOM_ON_THE_OTHER_SIDE_OF_THE_DOOR );
  5.  
  6. // Now we're in the other room and the script continues running...
  7. dude.Say( "I'm right here, can't you see me?" );
  8. player.Say( "Oh, there you are." );
  9.  
  10. cutToRoom( ORIGINAL_ROOM );
  11.  
  12. // And we're back...
  13. player.Say( "Well, that was fun." );
  14.  

Well, you can! I'll share all the neat stuff I've hacked up in my AGS-Lua framework sometime in June, once I'm finished with my game. Just don't expect everything to be consistent and pretty. :P
« Last Edit: 07 Apr 2012, 22:11 by AJA »

ShadowStalker

  • I am doom2.fan/ShadowStalker/Chronos Ouroboros
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with web design
    •  
Re: PLUGIN: Lua for AGS
« Reply #56 on: 08 Apr 2012, 07:38 »
I can't use Run without debugger it gives me an error:
---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x0281E51E ; program pointer is -23, ACI version 3.21.1115, gtags (0,0)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.



Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK   
---------------------------
this only happens if i have the Project tree node activated and the run-time plugin activated :(
EDIT:i use version 3.21
« Last Edit: 08 Apr 2012, 07:40 by ShadowStalker »

Re: PLUGIN: Lua for AGS
« Reply #57 on: 09 Apr 2012, 20:34 »
It would be nice if we could od simple Lua to AGS script function calls using the CallGameScriptFunction and QueueGameScriptFunction plugin API functions. Even though it's limited you can at least pass the proper parameters by reading them from Lua inside the AGS script function. Right?
I did attempt something like this, but it looks like I commented it out. You would call Lua.RegisterGlobalScriptFunction("myfuncname", <number of parameters>); in AGS script and it would add ags.myfuncname(...) to the Lua side, but there must have been some problem with it.
Quote
And what about the undocumented bool Character.on property? That would be useful to easily hide the player character.
That is another struct field, rather than a property with getter/setter methods. I am very unsure about getting/setting fields seeing as it's getting to the point of poking into arbitrary memory.

Re: PLUGIN: Lua for AGS
« Reply #58 on: 02 May 2012, 00:33 »
Any chance there'll be a fix for the nil/null problem I mentioned earlier, Denzil?

I ran into another case where it was a bit troublesome: You can't actually cancel FollowCharacter calls since you can't call ags.cEgo:FollowCharacter(nil). That just gives an error that a Character was expected for arg #1.

Luckily in my case I only wanted to undo following because I hit AGS's limit of following characters. So, it was easy to fix by changing the limit in the engine. But if I needed to cancel following, I'd be in big trouble right about now. :P

Re: PLUGIN: Lua for AGS
« Reply #59 on: 02 May 2012, 16:26 »
Here is a bleeding edge dev version that hopefully fixes the nil/null problem:

http://dl.dropbox.com/u/29133560/agslua-dev-2012-05-02.zip
http://dl.dropbox.com/u/29133560/agslua-dev-2012-05-02_2.zip (EDIT: Replaced with a version with a fixed compat.lua)

...however, there is also a new feature which breaks compatibility with existing scripts, but I have included a script called "compat.lua" - run this script straight away before any other Lua script (probably in game_start()) and the compatibility problems should be sorted.

If you don't run this script, then there is different ways of accessing the player object and properties of AGS objects:
ags.player instead of ags.getplayer()
ags.player.ActiveInventory = nil instead of ags.getplayer():ActiveInventory(nil)
ags.Game.SpriteHeight[5] instead of ags.Game.SpriteHeight(5)
...and so on. This way is better, but I know it's a pain when you already have a lot of code that uses the old way, which is why I provide the compat script.
« Last Edit: 02 May 2012, 16:47 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #60 on: 02 May 2012, 17:05 »
Nice, thanks! Seems to be working fine so far. :)

Re: PLUGIN: Lua for AGS
« Reply #61 on: 03 May 2012, 13:22 »
Excellent! Sorry for the delay in getting to this stuff  :-[

Re: PLUGIN: Lua for AGS
« Reply #62 on: 12 May 2012, 18:01 »
Hi All,

I am new to the forum and AGS, and I am trying to make use of the Lua plugin in my first game.
After I enable the plugin and run my game, the game crashes and I get the following error: "Error: [Lua] Type not literally persistable by default." Here's a screenshot: http://oi47.tinypic.com/34eqhcm.jpg

Can anyone offer some advice?
Thanks!


Re: PLUGIN: Lua for AGS
« Reply #63 on: 12 May 2012, 19:07 »
That's an indication that there exists a value somewhere in the Lua "universe" that it does not know how to save in a restoreable format. It knows how to do this for every standard Lua object, but not non-standard custom objects (except ones that have had special handling specifically written for them in the plugin).

One example is an open file-handle object. If you do this in a Lua script and run it from game_start():

Code: Adventure Game Studio
  1. f = io.open('test.dat', 'wb')

...this opens a file for writing, and saves the open file-handle object in global variable 'f'. When the time comes for the game to be saved (which is immediately - AGS needs to create a restart point as soon as the game begins, which works by creating a save-game) there is no meaningful way for the variable 'f' to be saved, so you will get the "not literally persistable" error. (So make sure, if you do want to read/write files from Lua, that you do not keep a reference to the file handle around!)

Another example would be objects created by Lua C libraries that come as a DLL (for example, LuaSocket sockets or LPEG patterns). Are you doing anything like that? If not, maybe there is a bug in the plugin and one of these unsaveable values is being created accidentally by the plugin itself. It's not a bug I remember ever encountering myself, though.
« Last Edit: 12 May 2012, 19:13 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #64 on: 12 May 2012, 19:15 »
Thanks for the reply, Denzil... but I receive this error even when I have zero Lua scripts in my project...

Re: PLUGIN: Lua for AGS
« Reply #65 on: 12 May 2012, 19:20 »
Okay, so it must be a bug in the plugin. Thanks for the report! Is this an empty/new project, or does it have lots of existing rooms etc.? If it's an existing project, does the same thing happen if you try with a new one?

Re: PLUGIN: Lua for AGS
« Reply #66 on: 12 May 2012, 19:41 »
When I create a new project using "empty" or "default," I don't receive the error.
I only receive it when I create a new project using a saved template.

Re: PLUGIN: Lua for AGS
« Reply #67 on: 12 May 2012, 19:49 »
Aha, interesting - can I get a copy of the template? If it's a private one, but you don't mind just me seeing it, send a PM - I promise to keep it confidential.

(Sorry about this!)

Re: PLUGIN: Lua for AGS
« Reply #68 on: 12 May 2012, 21:14 »
Hmm, here's a weird bug. When I restart the game or restore a saved game, something (the plugin?) seems to override the compat.lua script. When I normally run the game, everything works fine but when I restart, the game crashes with the first call to set a character's x coordinate (because now it's a number value). I load all the scripts in game_start.

Re: PLUGIN: Lua for AGS
« Reply #69 on: 14 May 2012, 22:09 »
Oops. Here is a new dev version with a fix for that AJA:

http://dl.dropbox.com/u/29133560/agslua-dev-2012-05-14.zip

statelessrich, I think this should work for your problem too (I tried building a new game with your template and it works) - could you try it with this version and see if it works for you too?

Re: PLUGIN: Lua for AGS
« Reply #70 on: 14 May 2012, 22:54 »
Still doesn't quite work. :( Different error, though, so that's progress. It seems ags.object[id].Clickable is nil after a restore/restart. Visible and Baseline are also nil, didn't try any more of them. If I comment out the instantly crashing part of code, everything seems to work fine until I a script tries to access an object.

Is there any way to make the error message clearer in this kind of a case where stuff is read from a saved game? Since now it's just: Error: [Lua] [string ""]:0: attempt to call method 'Clickable' (a nil value)

Re: PLUGIN: Lua for AGS
« Reply #71 on: 15 May 2012, 03:23 »
We're getting there! We're getting there!  :X

http://dl.dropbox.com/u/29133560/agslua-dev-2012-05-15.zip

Try that one.

Quote from: AJA
Is there any way to make the error message clearer in this kind of a case where stuff is read from a saved game?

Mm, no, I don't see a way of doing it, sorry :( The error isn't actually occurring while the saved-game is being loaded, and once it's loaded there's no easy way of telling that an error happened because of "something that was just loaded" as opposed to any other kind of error.

Re: PLUGIN: Lua for AGS
« Reply #72 on: 15 May 2012, 04:01 »
Works great! Thanks! :D

And yeah, the error message thing was a bit of a long shot.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #73 on: 26 Jul 2012, 22:59 »
Ok, so I've spent the day putzing around with this plugin and frankly I see literally *no reason* why someone would not want to use it. There seems to be no disadvantages (unless you consider lua itself to be a disadvantage). This plugin is literally the best thing ever.

@Denzil

I assume this is fully portable? Do you plan to release the source so that JJS can have a go at recompiling it for other platforms?

Also, if your code is fairly general i reckon we could implement angelscript in a similar fashion.
« Last Edit: 26 Jul 2012, 23:31 by Calin Leafshade »

Re: PLUGIN: Lua for AGS
« Reply #74 on: 26 Jul 2012, 23:33 »
Thanks very much! The source code is up on GitHub:

https://github.com/duncanc/Lua-for-AGS

...the code is extremely messy, partly auto-generated, and difficult to compile (I know the VS project files refer to specific paths on my hard drive and there are some static lib dependencies that don't seem easy to find or compile, and so on :P) but it's there. I've always lived in hope of cleaning all this up, and I'd been putting off releasing the code for a while because of that, but decided that was silly. "Release early, release often, fix eventually" as I believe the saying goes.

Re: PLUGIN: Lua for AGS
« Reply #75 on: 26 Jul 2012, 23:41 »
I assume this is fully portable?
I don't believe the run-time plugin uses anything Windows-specific.

Also, if your code is fairly general i reckon we could implement angelscript in a similar fashion.
It isn't very general, I'm afraid, pretty specific (and convoluted). I'm sure you're right that something very similar could be done with other scripting languages, Lua is just one that I happen to know very well.

What I would really love to do is use the incredibly (and increasingly) high-powered version of Lua, LuaJIT2. It really is ridiculously fast, beating even state-of-the-art accelerated JavaScript JIT compilers on some benchmarks. But the big problem is that the serialization functionality that Lua For AGS needs for the save/load functionality is not compatible with LuaJIT2...

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #76 on: 27 Jul 2012, 17:06 »
Are there any plans to implement QueueGameScriptFunction from the plugin API?

This would allow users to call their own scripts.

My reasoning as to why this would be useful is that a lua script could request a hook from the game script if there were a LuaControl module or something.
like this:

Code: Lua
  1.     requestHook("repeatedly_execute_always", "nameOfLuaFunction")
  2.  

requestHook would look something like

Code: Lua
  1. function requestHook(hook, callback)
  2.     index = storeHookAndCallBackInAnArrayOrSomething(hook, callback) -- return a table index
  3.     ags.QueueScriptFunction("LuaRequestHook",index)
  4. end
  5.  

and the ags would look something like this:

Code: Adventure Game Studio
  1. void LuaRequestHook(int index)
  2. {
  3.     String funcName = Lua.CallScript("GetHookFromIndex", Lua.IntValue(index)); // or whatever, i dont remember the syntax
  4.     String hook = GetTheHookToo(index) //whatevr
  5.     StoreHookAndCallBack(funcName, hook); // just store it in an array
  6.  
  7. }
  8.  
  9. void repeatedly_execute_always()
  10. {
  11.     IterateThroughHooksAndFireIfAppropriate();
  12.    
  13. }
  14.  

I dont think the code was necessary to explain my point... whatever

Re: PLUGIN: Lua for AGS
« Reply #77 on: 27 Jul 2012, 17:43 »
The issue of QueueGameScriptFunction/CallGameScriptFunction is one that I do want to return to at some point. I made a start at it but I think I hit a problem (that I helpfully can't remember now) and left it for later...

But having said that, it looks like you shouldn't need it in this particular example, because in Lua you can put functions themselves into arrays - there's no need to burden AGS with the task of storing the hook and callback.

For example, say you have a script like this that you run in game_start():

Code: Lua
  1. -- callbacks.lua
  2.  
  3. local callbacksByEventName = {}
  4.  
  5. function addCallback(eventName, callback)
  6.   -- get a list of callbacks for this event
  7.   local callbacks = callbacksByEventName[eventName]
  8.   -- if the list doesn't exist yet, create it
  9.   if callbacks == nil then
  10.     callbacks = {}
  11.     callbacksByEventName[eventName] = callbacks
  12.   end
  13.   -- add the provided callback function to the end of the list
  14.   callbacks[#callbacks+1] = callback
  15. end
  16.  
  17. function runCallbacks(eventName, ...)
  18.   -- iterate through all callbacks registered to this event name
  19.   for i, cb in ipairs(callbacksByEventName[eventName] or {}) do
  20.     -- call the function, passing through any extra parameters
  21.     cb(...)
  22.   end
  23. end
  24.  

Then, in AGS, set up runCallbacks("repeatedly_execute_always") to be called every frame:

Code: Adventure Game Studio
  1. function repeatedly_execute_always()
  2. {
  3.   Lua.Call("runCallbacks", Lua.StringValue("repeatedly_execute_always"));
  4. }

Now, to add a function to be called on, you would do:

Code: Lua
  1. function DoThisEveryFrame()
  2.   -- (...whatever you like...!)
  3. end
  4.  
  5. addCallback('repeatedly_execute_always', DoThisEveryFrame)

...or, alternatively, even:

Code: Lua
  1. addCallback('repeatedly_execute_always', function()
  2.   -- (...whatever you like...!)
  3. end)
« Last Edit: 27 Jul 2012, 17:46 by Denzil Quixode »

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #78 on: 27 Jul 2012, 17:54 »
You make a good case. For some reason I didnt think of having lua store the callbacks which is, in hindsight, a far better idea.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #79 on: 28 Jul 2012, 16:44 »
Do I understand correct that the plugin basically adds a lua-scripts interpreter to the engine?
Sorry, that's probably obvious, just wanted to make it fully clear for myself.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #80 on: 28 Jul 2012, 17:02 »
Yes, that is precisely what it does.

Lua is not a language i personally like that much but it is *far* more flexible than AGSScript and since the plugin provides access to everything that AGSScript does there is really no reason to use standard ags script anymore. I am of the belief that AGSScript is quite literally obsolete at this point.


Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #81 on: 28 Jul 2012, 17:12 »
But we would still have to have event callbacks in the AGSScript, like game_start, repeatedly_execute, object interactions?

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #82 on: 28 Jul 2012, 17:25 »
Yes, but as Denzil said higher up, it's easy to make a system whereby a lua script can subscribe to events from the main script.

Re: PLUGIN: Lua for AGS
« Reply #83 on: 28 Jul 2012, 19:12 »
since the plugin provides access to everything that AGSScript does
Not quite true - you cannot access object fields (as opposed to properties, which are really getter/setter functions in disguise). There's very few of those around now, mostly you access everything through properties, but I think there might still be a few odd things you can only do with fields.

Re: PLUGIN: Lua for AGS
« Reply #84 on: 28 Jul 2012, 20:25 »
Plus you can't call modules or plugins from Lua.

Glad to see someone else finally seeing the light, Calin. :)

Btw, I'm not sure whether it's AGS or this plugin but it takes quite a while to save a game in Barely Floating (see GiP thread for game info). If AGS saves a screenshot regardless of whatever the game settings are, then it might be AGS. But just as a heads up, if the plugin saving is in any way a slow operation, you might want to add some AGS system polling calls in there because the sound stutters whenever I save a game.

And what exactly is the problem with fields? Can't you just write wrapper functions to access them? Or is there no way to access them through the plugin API? Why do I feel like I've asked this question before... :P

Re: PLUGIN: Lua for AGS
« Reply #85 on: 28 Jul 2012, 21:34 »
Plus you can't call modules or plugins from Lua.
Oh, yes, that too. It should at least be possible to convert any script module to Lua, and I did start work on a tool to automatically convert any piece of AGS script to equivalent Lua code to help with that.

For plugins though... well, it migbt be possible to one day achieve this, but it would take quite a bit of work:
  • I have no idea if the GetScriptFunctionAddress() works with plugin-imported functions, obviously that has to be the case
  • In order to call arbitrary C/C++ functions that are not known to the runtime plugin compiler at compile-time, the Lua plugin would need to use a special FFI library like libffi. (I haven't tried this before, I'm not sure how much work it would be, or how cross-platform.)
  • In order to find the other plugin's function signatures, the AGS script headers would need to be parsed and processed to extract them. (Luckily there is the C# module "SPAGS" I made that should help with doing stuff like that, though.)

Btw, I'm not sure whether it's AGS or this plugin but it takes quite a while to save a game in Barely Floating (see GiP thread for game info). If AGS saves a screenshot regardless of whatever the game settings are, then it might be AGS. But just as a heads up, if the plugin saving is in any way a slow operation, you might want to add some AGS system polling calls in there because the sound stutters whenever I save a game.

There is certainly a bit of processing going on when it serializes the Lua state. Part of the problem is I've never had a realistically large real-world test case project myself to experiment with, so it's quite possible you're seeing it under more strain than I ever have. I will certainly look into good places to put some PollSystem() calls, anyway.

And what exactly is the problem with fields? Can't you just write wrapper functions to access them? Or is there no way to access them through the plugin API?
While checking up on the documentation in reply to this I just noticed the GetGameOptions() function in the plugin API that I somehow missed before, so for game options it seems like it should be possible to write those wrapper functions! Sorry for not spotting that before. I'll put that on the todo list.

(In general though, there's no documented way to access them. Admittedly, I am already working with undocumented things in the plugin API, like using "GetScriptFunctionAddress" to get the addresses of variables rather than functions, and the odd way that "float" values are passed around internally as function parameters/return values in AGS. For both of those I was using information I found posted on the technical forum, so it was already kind of unofficially established, but I couldn't find anything about struct fields.)
« Last Edit: 28 Jul 2012, 21:44 by Denzil Quixode »

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #86 on: 29 Jul 2012, 13:08 »
Further discussion has been moved to HERE
No more military army stuff. I'm alive and back.

Re: PLUGIN: Lua for AGS
« Reply #87 on: 29 Jul 2012, 16:21 »
A new version (edit: another new version) of the plugin is now available from http://lua-for-ags.wikispaces.com/Downloads

The main changes:
  • You can now access game variables (ags.game.text_shadow_color, ags.game.total_score, etc.) and character fields (ags.player.on is probably the only useful one). Values that can only be 0 or 1 are exposed as Lua booleans, so make sure you do things like "if ags.player.on then..." instead of "if ags.player.on == 1 then..."
  • You can queue up a call to a global script function that takes 0, 1 or 2 int parameters, to be executed as soon as the current script has finished, by using:
    Code: Lua
    1. ags.queue('MyGlobalFunc' [, intparam1 [, intparam2 ] ])
    ...or to a room script function, with
    Code: Lua
    1. ags.Room.queue('MyRoomFunc' [, intparam1 [, intparam2 ] ])
« Last Edit: 29 Jul 2012, 17:45 by Denzil Quixode »

JJS

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2012, for his efforts in porting AGS to multiple platforms
    •  
Re: PLUGIN: Lua for AGS
« Reply #88 on: 30 Jul 2012, 10:43 »
I have a quick question on compiling the source: Is the version of Lua used (5.1.4) critical or would the plugin also work with Lua 5.2.x?
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Re: PLUGIN: Lua for AGS
« Reply #89 on: 30 Jul 2012, 10:51 »
I have a quick question on compiling the source: Is the version of Lua used (5.1.4) critical or would the plugin also work with Lua 5.2.x?
Unfortunately the Pluto serialization library that this plugin's save/load system relies on is extensively tied to the internals of 5.1. If there is a 5.2-compatible version of Pluto I'm not aware of it.

JJS

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2012, for his efforts in porting AGS to multiple platforms
    •  
Re: PLUGIN: Lua for AGS
« Reply #90 on: 30 Jul 2012, 11:06 »
Ok, thank you! It is not a problem to use 5.1.4, I just wanted to know what version I should use as a base because they need different patches.
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

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 #91 on: 31 Jul 2012, 19:06 »
Awesome work guys!
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

JJS

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2012, for his efforts in porting AGS to multiple platforms
    •  
Re: PLUGIN: Lua for AGS
« Reply #92 on: 31 Jul 2012, 20:05 »
I got the plugin running on Android. The changes to the plugin source are in here: https://github.com/jjsat/Lua-for-AGS

Changes are mostly for making GCC happy and enclosing the windows.h include and the MessageBox code in #ifdefs. Also I commented out the unused mutex as it doesn't seem like it is used anywhere.

Can you review the code and maybe merge it into your repo if it doesn't break anything?
« Last Edit: 31 Jul 2012, 20:10 by JJS »
Ask me about AGS on PSP, Android and iOS! Source, Daily builds

Re: PLUGIN: Lua for AGS
« Reply #93 on: 31 Jul 2012, 21:30 »
Great work JJS! Thanks! I've merged the changes, it all looks reasonable and it compiles without a hitch. (I can't remember why I ever had that mutex...)

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #94 on: 01 Aug 2012, 20:26 »
A request:

Line numbers in the editor please.

Edit: Also a way to enumerate the scripts in the store would be nice.
« Last Edit: 01 Aug 2012, 20:59 by Calin Leafshade »

Re: PLUGIN: Lua for AGS
« Reply #95 on: 01 Aug 2012, 21:15 »
I've added the line numbers to git.

Here's a built version (just the editor plugin): download

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #96 on: 01 Aug 2012, 21:19 »
Thanks,

with regards to the script store all would really be needed is an array of the filenames and an int somewhere for the count.

Code: Adventure Game Studio
  1. int i;
  2. while (i < Lua.ScriptCount)
  3. {
  4.     Lua.RunScript(Lua.ScriptNames[i]);
  5.     i++;
  6. }
  7.  

Re: PLUGIN: Lua for AGS
« Reply #97 on: 01 Aug 2012, 21:28 »
It's slightly complicated by the fact that the scripts can be put in folders (and really are stored in this folder hierarchy internally, not an array).

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #98 on: 01 Aug 2012, 21:31 »
Hmm well the filename could just return the relative folder structure.

So a file at lscripts/folder1/lua1.lua would return "folder1/lua1.lua"

I don't think having a special tree structure in this case is that necessary. If the user wants to rearrange the data at runtime they can do so.

Re: PLUGIN: Lua for AGS
« Reply #99 on: 02 Aug 2012, 00:50 »
I've added Lua.ScriptCount and Lua.ScriptNames[]. Here is the dev version of the runtime plugin with this change: download

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #100 on: 02 Aug 2012, 00:52 »
Exquisite.

Have yourself an extra slice of cake on my say so.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #101 on: 08 Sep 2012, 18:57 »
A request:

The AGS plugin API provides a way to replace font renderers with custom ones.

Could this be exposed to the lua interface so that one could write replacement font renderers from within lua?

You could create a table with all the functions required by a font renderer and then pass that to a function in the ags table and the lua runtime plugin just calls the lua functions in the script.

Possible?

Also, as an aside, since its quite common to directly write data to file as a lua script, it would be useful if the IsRunningUnderDebugger() function of the API(or whatever its called) were exposed so you could know if it was safe to write to lscripts/

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #102 on: 22 Dec 2012, 00:45 »
Another request, apologies for the triple post but it seemed permissible in this instance.

Could you enable some kind of Lua debugger for remote debugging?
Something like this: http://luaedit.sourceforge.net/support.html#faq-002


Scrap that.

I've tried to implement Mobdebug in my game but of course when Pluto tries to serialise the game it tries to serialise the c functions in socket which is not allowed.

Do you have any suggestions on how to get around this?

« Last Edit: 22 Dec 2012, 01:34 by Calin Leafshade »

Re: PLUGIN: Lua for AGS
« Reply #103 on: 22 Dec 2012, 13:45 »
One thing you could try is removing the C functions just before the game gets saved, and re-load them just after the game is restored.

I haven't had a chance to test this myself, but if you add something like this to the end of socket.lua:

Code: Lua
  1. -----------------------------------------------------------------------------
  2. -- Avoid having any C functions around while the game is being saved
  3. -----------------------------------------------------------------------------
  4.  
  5. function base.ags_presave_socket()
  6.     socket = nil
  7.     base.package.loaded['socket.core'] = nil
  8. end
  9.  
  10. function base.ags_postrestore_socket()
  11.     socket = require 'socket.core'
  12. end

...then make sure these functions are called on the pre-save and post-restore events, hopefully that will make the C functions unreachable during serialization but still there when you need them.
« Last Edit: 22 Dec 2012, 13:49 by Denzil Quixode »

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #104 on: 22 Dec 2012, 14:33 »
Hmm that works but AGS's framerate drops from 60 to about 4. Presumably because of all the polling.

Have you given any thought to any kind of debugger for the lua plugin? It's something it lacks i think at the moment and allowing for variable inspection at runtime will tip Lua over the edge as a defacto replacement for AGSScript. At least for me.

Re: PLUGIN: Lua for AGS
« Reply #105 on: 22 Dec 2012, 18:02 »
I've thought about it, but I feel like it would only really be worth doing if both AGS APIs were more deliberately tailored to supporting custom third-party scripting languages in general, and then had custom hooks for seamlessly dealing with breakpoints etc. for those languages at run-time in particular.

Re: PLUGIN: Lua for AGS
« Reply #106 on: 30 Dec 2012, 19:15 »
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
  1. 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:

Code: Lua
  1. if type(project.compiled_count) == 'number' then
  2.   project.compiled_count = project.compiled_count + 1
  3. else
  4.   project.compiled_count = 1
  5. end
  6.  
  7. 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:

Code: Lua
  1. 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.:

Code: Lua
  1. luanet.System.Windows.Forms.MessageBox.Show("hi")

The editor action scripts could use this too.
« Last Edit: 30 Dec 2012, 19:25 by Denzil Quixode »

Billbis

  • R, what else?
    • I can help with translating
    •  
Re: PLUGIN: Lua for AGS
« Reply #107 on: 01 Jan 2013, 10:17 »
One idea that I had early on but never quite got around to sorting out is compile-time scripts.

I totally support this. It would be very useful for game optimization and intensive calculation processes. I can use this for determination of Hotspots coordinates. ;)
(Even if I do not know how to code a "for each room in project" instructions.)
Also, it will be even better, if possible, that this possibility works with AGS script, and not just Lua code. Maybe by doing a independent - but compatible with Lua - plugin ?

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #108 on: 01 Jan 2013, 11:24 »
At first I couldn't see the utility. But if the plugin allowed access to all rooms and stuff at compile time then it would actually be very useful for data processing.

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 #109 on: 02 Jan 2013, 10:02 »
...This entire thread brilliantly demonstrates why a "real" language is a must in AGS: As Denzil explained in his previous long post, Lua can then be used for no less than 3 different things :
1) Scripts in-game, that can use the billions of scripts already developed in Lua, out there in the real world.
2) Scripts run only once, when the game gets compiled (imagine for example if you pre-processed some Tweens once and for all at compile time, to make the game faster later on -- that's just an example)
3) Make the Editor customizable (a bit the same way as you can run scripts in Photoshop, 3DS or Blender). That would be priceless for people who make large projects and are tired of repeating the same imports and stuff.


I'm planning on packaging a version of AGS that embeds Lua by default, along with other "advanced" tools (SpeechCenter, Tween module, etc.). Is there a default Lua game template?

 

Re: PLUGIN: Lua for AGS
« Reply #110 on: 02 Jan 2013, 11:24 »
I'm planning on packaging a version of AGS that embeds Lua by default, along with other "advanced" tools (SpeechCenter, Tween module, etc.). Is there a default Lua game template?
Dunno. Might want to check with the module creators they'd be OK with you packaging their stuff up first.
« Last Edit: 02 Jan 2013, 11:29 by Sslaxx »
Stuart "Sslaxx" Moore.

Re: PLUGIN: Lua for AGS
« Reply #111 on: 02 Jan 2013, 12:21 »
Is there a default Lua game template?
Not any official one, no. The thing is that it could be used in completely different ways, and so far I've kind of stood back and let people decide how they want to use it rather than push an officially "correct" way. (That's probably part of the reason it took three years for anything to get done with it, but anyway...)

Also, is it possible for templates to include weird arbitrary plugin-related files, like Lua scripts? I haven't tried, I don't remember there being anything special that the editor plugin is able to do to handle templates.
« Last Edit: 02 Jan 2013, 12:23 by Denzil Quixode »

Windows 7 Lua Crashing
« Reply #112 on: 16 Jan 2013, 04:17 »
Hello!

Thanks for all the hard work with the Lua pluggin -- it looks like it can make scripting certain things in AGS a lot easier.

Now, I've been trying to get this Lua plugin to work but it's been crashing no matter what I do. The issue seems to go right back to the plugin itself as even if I create a new default game, enable the Lua plugin (both the "lua scripts" and "lua runtime" components), and then try to run the game with no new Lua scripts or anything, I get an immediate crash (see below)...Obviously the same thing happens if I have a developed game and write some Lua scripts and try to call them in AGS...when I disable the pluggin the game will run again as before...

I had downloaded what I thought to be the latest version of the Lua plugin from http://lua-for-ags.wikispaces.com/ and am running AGS 3.2.1 on a Windows 7 64-bit machine...

After downloading the zipped Lua plugin folder I simply unzipped it and copied the dlls into the AGS editor main program folder as were the instructions...

...the "lua scripts" blue node and "lue code converter" show up in AGS when I did this and I can create new lua scripts in AGS without issue. 

Does anyone have any idea what's going on? I'd really like to be able to use this great piece of work...

Thanks!

Crash:


---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x066DE51E ; program pointer is -23, ACI version 3.21.1115, gtags (0,0)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.



Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK   
---------------------------




So... 64-bit may be the issue.

"Dependency Walker" reports "agslua.dll" and dependency "lua5.1.dll" (bundled with the latest plugin download) as having been compiled for 32-bit systems, declaring: "Error: Modules with different CPU types were found." That said, it seems a bit doubtful that I could be the only poster in this thread running a 64-bit system.

So... 64-bit may not be the issue. Consider me flummoxed. :tongue:

Incidentally, on merely copying all requisite plugin DLLs into the AGS folder of a Windows XP 64 system I have handy, I receive the following error on every AGS startup:

---------------------------
Adventure Game Studio
---------------------------
There was an error loading plugin 'ags.plugin.lua.dll'.System.Reflection.TargetInvocationExce ption: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'lua5.1.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)   at AGS.Plugin.Lua.InvokeLua.luaL_newstate()   at AGS.Plugin.Lua.LuaForAGSEditorComponent ..ctor(IAGSEditor editor)   at AGS.Plugin.Lua.LuaPlugin..ctor(IAGSEditor editor)   --- End of inner exception stack trace ---   at System.RuntimeMethodHandle._InvokeConst ructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)   at System.RuntimeMethodHandle.InvokeConstr uctor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)   at System.Reflection.RuntimeConstructorInf o.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)   at AGS.Editor.EditorPlugin..ctor(String fileName, AGSEditorController pluginEditorController)   at AGS.Editor.Components.PluginsComponent. LoadEditorPluginIntoMemory(String fileName)
---------------------------
OK   
---------------------------


Thanks much, guys.

Combined double post. ^_^
« Last Edit: 16 Jan 2013, 09:59 by Dualnames »

Re: PLUGIN: Lua for AGS
« Reply #113 on: 16 Jan 2013, 11:48 »
I'm really sorry you're having these problems pietakio. I have 64-bit Windows 7 myself, and just tried a fresh install of AGS 3.2.1 with the latest version of the plugin, and can't reproduce the problem. I also don't have a 64-bit version of Windows XP handy unfortunately. I doubt 64-bit can be the issue because the application and DLLs themselves are all really 32-bit, they run on WoW64. (Unless there is a 64-bit version of AGS itself that I am not aware of...?) I will try to look into the "modules with different CPU types" thing. Sorry again.

Re: PLUGIN: Lua for AGS
« Reply #114 on: 16 Jan 2013, 14:12 »
Hey Denzil,

Well, thanks for letting me know about the 64-bit issue not being the issue and getting back so quickly. The Windows 7 computer is my main one so no worries about the 64-bit XP side of things -- it was just weird that it didn't work there either.

I wonder if I'm doing something stupid?! To get things going the process is really just:
1. copy the five "LuaForAGS_v6_b" dll's into the AGS editor game folder (alongside ags.exe, etc), then
2. start up AGS, activate the blue Lua node to get the scripts and then activate the green puzzle-piece going under the plugins node

?

I had also tried copying the agslua.dll and the lua51.dll + lua5.1.dll into the game folder but no luck.

Hmmm...hopefully I've just done something dumb as this looks like just the thing to take AGS to the next level!

Thanks again!

Re: PLUGIN: Lua for AGS
« Reply #115 on: 16 Jan 2013, 16:12 »
I wonder if I'm doing something stupid?! To get things going the process is really just:
1. copy the five "LuaForAGS_v6_b" dll's into the AGS editor game folder (alongside ags.exe, etc), then
2. start up AGS, activate the blue Lua node to get the scripts and then activate the green puzzle-piece going under the plugins node
No, you are doing everything right.

Hmm... I wonder if it is possible that you have another, incompatible version of lua5.1.dll installed in a system folder somewhere that is somehow overriding the one in the immediate application folder. It doesn't seem very likely though...
« Last Edit: 16 Jan 2013, 16:19 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #116 on: 16 Jan 2013, 21:27 »
Hmmm...well...thanks for the suggestion but there isn't another copy of the Lua5.5.dll around on my system...

So far have tried *everything* I can think of but no luck...

The only other possible hint is that when a game.exe compiled with the lua plugin is executed (I tried runnin Calin's "Night Thorn" game), there's an error:

Error:[Lua] lscripts.dat signature mismatch

I can't believe it won't work on either of my computers :(

Anyways, if there are any ideas about dependencies and so on please let me know...

Thank you!   

Re: PLUGIN: Lua for AGS
« Reply #117 on: 17 Jan 2013, 00:40 »
Hello again! Sorry for all the posts but since I can't even *PLAY* lua-ags compiled games (i.e. Night Thorn) on either of my two machines at home I thought it might be a kind of important thing to try and suss out what's going on in case there are more folks like me who won't be able to use the lua plugin OR play games made with it....

So, a summary of what's going on with my two machines.
 

XP-64 bit machine:

Here, if the 5 lua plugin dlls are in the AGS editor directory on startup AGS calls an error ("unable to load ags.plugin.lua.dll") and bunks out.

I then went to the "Administrative Tools Event Viewer" in Windows control panel and found the following message related to the ags crash:

"Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system."

Scanning the lua plugin dlls with the program "dependency walker" for the agslua.dll I get:

Error: The Side-by-Side configuration information for "c:\program files (x86)\adventure game studio 3.2.1\LUA5.1.DLL" contains errors. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001).

It also reports that devmgr.dll is missing, however, it does that for other things that work so I take it with a grain of salt...

Then, when I then tried to PLAY the compiled game Night Thorn (a lua-ags hybrid) I get the event viewer message:

Generate Activation Context failed for C:\Documents and Settings\Administrator\My Documents\GameMaker\NightThorn\NightThorn\Compiled\lua5.1.dll. Reference error message: The referenced assembly is not installed on your system.

And yes lua5.1.dll is right there in the folder that the application is looking for each time (all the required dlls are) -- so this is really kind of funky!

I also immediately checked and can play regular compiled AGS games (5 days a stranger, etc) without issue.

ON the Windows 7 64 bit machine:

Here I put the 5 lua-plugin dll files into the AGS editor folder and fire up AGS without issue. I can activate both components of the plugin and make and write lua scripts and stuff. If there is any call to a lua script in AGS then upon compiling the game (f5 or ctl-f5) I get a message like "LuaValueList is not a public member of 'Lua'. Are you sure you spelt it correctly" and this goes on for all lua-related script. If I remove all reference to lua in the game script and just have the lua plugin activated then it calls a fatal error (ambiguous splash screen mentioned in my first post yesterday). If the lua plugin is disabled, everything is normal and runs fine again. This same kind of stuff happens for games I'm working on, the default game, the empty game, everything.

Running the "dependency walker" on the lua dlls in this system says GPSVC.dll and IESHIMS.dll are missing, though again I see 'em in the System-32 folder so don't understand or know if this is a red herring or not. Scanning AGS dlls gives similar errors and again it works fine.   

I'm not a developer and suspect there is some dependency (visual C++ runtime library?) that you all have on your systems and I don't? Maybe?

Anyways it would be great if the lua plugin could work on at least one of these two computers and probably a good thing to sort out what's happening in case a bunch of folks can't play the lua-AGS hybrid games that get made...

Thanks very much again :)

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #118 on: 17 Jan 2013, 00:56 »
Yea, I think you might need the cpp re-distributable package.

http://www.microsoft.com/en-gb/download/details.aspx?id=14632

That is the 2010 version. You may need the 2008 (or maybe 2005) version depending on what version the lua plugin (and lua) were compiled against.


Re: PLUGIN: Lua for AGS
« Reply #119 on: 17 Jan 2013, 01:35 »
Definitely worth a try but just did the c++ runtime library installs (2010, 2008, 2005 for 64 and 32 bit,  hopefully this isn't really dumb to get all of the ones I didn't have...!) and everything is the same as before :(

Hmmmm.....

Re: PLUGIN: Lua for AGS
« Reply #120 on: 17 Jan 2013, 20:41 »
in case there are more folks like me who won't be able to use the lua plugin OR play games made with it....
Sure, I understand the potential severity of this... it does seem odd that you're the first person who's had this many problems with it, unless there are others who never bothered to post in the thread...?

"Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system."
As I understand it, this should be taken care of by the msvcr80.dll/Microsoft.VC80.CRT.manifest files that should also be found in the AGS editor folder after a normal installation. I'm no expert, though... hmm, does copying the msvcr*/msvcrm*/*.manifest files to the game project's "compiled" and "debug" folders help anything?

"LuaValueList is not a public member of 'Lua'. Are you sure you spelt it correctly"
That's very weird, like the lscripts.dat error... it almost sounds like the script header is getting corrupt somehow.

Running the "dependency walker" on the lua dlls in this system says GPSVC.dll and IESHIMS.dll are missing
Hmm, for me, dependency walker only mentions KERNEL32.dll and MSVCRT80.dll. It sounds like maybe you have a problem with the Microsoft Visual C Runtime (MSVCR) on both machines, but unfortunately, again, I'm no expert on it...
« Last Edit: 17 Jan 2013, 21:01 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #121 on: 17 Jan 2013, 23:00 »
Hey thanks again for your help, and yes, it is probably only some weird windows issue with my machines. 

A great idea and job with the lua plugin though, and I'm sad that I can't use it, but AGS-script will probably be fine in the end.

Thanks!
 

Re: PLUGIN: Lua for AGS
« Reply #122 on: 18 Jan 2013, 13:41 »
I do hate to turn away an enthusiastic potential user :/ Thank you so much for documenting the errors you encountered though.

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #123 on: 05 Jun 2013, 21:24 »
It seems that loadscript doesnt return an error message. Is there anyway to see if a file exists in the script store? Currently it seems impossible to tell whether loadscript failed because the file does not exist or because there was a compilation error.

Re: PLUGIN: Lua for AGS
« Reply #124 on: 13 Jun 2013, 19:00 »
I just started using the Lua plugin for a game prototype I'm working on after getting frustrated with the limits of AGS Script - it's working great so far, except when I compiled the game and sent it to one of our writers to check out, he got the "lscripts.dat signature mismatch" error mentioned by pietakio. Any ideas on what could be causing that, do we have to distribute some extra .dlls with the game or something? I was glad to find a solution to my AGS problems but if it's not going to reliably work on a variety of machines I'm not sure it's going to be viable. Hopefully we can find a solution, I really can't be bothered writing an adventure game engine in scratch in Unity! :)

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #125 on: 13 Jun 2013, 21:03 »
Try doing a rebuild all files and be sure to send him the files from the Compiled folder.

If you run the game again in debug I think it invalidates the stuff in the compiled folder because the lua plugin writes a new version of the lscripts.dat.

Re: PLUGIN: Lua for AGS
« Reply #126 on: 14 Jun 2013, 06:25 »
Try doing a rebuild all files and be sure to send him the files from the Compiled folder.

If you run the game again in debug I think it invalidates the stuff in the compiled folder because the lua plugin writes a new version of the lscripts.dat.

Thanks, looks like that was the problem!

Re: PLUGIN: Lua for AGS
« Reply #127 on: 14 Jun 2013, 19:56 »
Is the documentation on the wiki still up to date? I'm having trouble getting return values from my Lua functions called from AGS Script.

I initially tried this, based on the example here: http://lua-for-ags.wikispaces.com/IntroducingLuaValueLists

Code: Adventure Game Studio
  1. LuaValueList* results = Lua.Call("getQueueLength");
  2. int queueLength = Lua.AsInt(results);

But AsInt doesn't seem to exist as a function of the Lua object.

I then tried to use the examples from here: http://lua-for-ags.wikispaces.com/UsingLuaForAGS

Code: Adventure Game Studio
  1. LuaValueList* results = Lua.NewValueList();
  2. LuaCallResult status = Lua.Call("getQueueLength", null,  results);
  3. Display(status);
  4. Display(results.AsInts[1]);

but that gives me "Error (line 183): Type mismatch: cannot convert 'LuaValueList*' to 'LuaCallMode'" because it seems like the function signature doesn't line up with the documentation.

Any advice?

Re: PLUGIN: Lua for AGS
« Reply #128 on: 10 Jul 2013, 16:13 »
If another scripting language was used in AGS, would it be implemented in the same way?
Meaning it being tied to the editor in the same way.
AGS scriting is far easier then other scripting.
« Last Edit: 10 Jul 2013, 18:49 by dbuske »
What if your blessings come through raindrops
What if your healing comes through tears...

Scavenger

  • Cavefish
  • In Four Glorious Colours!
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with scripting
    •  
    • Scavenger worked on a game that was nominated for an AGS Award!
      Scavenger worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #129 on: 30 Nov 2013, 19:13 »
Hey, I've been using the Lua plugin for a couple of days now, and I'm loving it's speed - this is the best thing for complex scripting. AGS Script has nothing on it.

However, I've been having a few problems with it.

Firstly, if you rename a script, it will duplicate the entry and deleting one of the entries will crash AGS and remove "both" scripts.

Secondly, I've been having some problems with the project getting corrupted if AGS doesn't crash cleanly. In 3.3.0, at least, if the engine stalls and needs to be shut down manually (prompting the "The AGS engine did not shut down properly" error in AGS), any Lua calls will crash a few loops in with:

Quote
Adventure Game Studio
---------------------------
An internal error has occurred. Please note down the following information.
If the problem persists, post the details on the AGS Technical Forum.
(ACI version 3.3.0.1148)

Error: [Lua] [string "local select = select;local error = error;l..."]:1: bad argument #2 to 'setter' (number expected, got nil)

I've included a copy of the ruined project here: https://dl.dropboxusercontent.com/u/50882197/Game/paltest_ruined.zip

Other than that, it's brilliant, and I love it! I want to continue using Lua for engine-intensive code.

Re: PLUGIN: Lua for AGS
« Reply #130 on: 30 Nov 2013, 21:08 »
Yes, the renaming bug is an embarrassingly old one - I need to fix that, sorry!! :-[

I will have a look at the corrupted project though, I haven't seen that happen before...

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #131 on: 30 Nov 2013, 21:21 »
This might as well be AGS 3.3.0 error.
Uh, sorry, I had to read the Scavenger's post more carefully. The crash might be the AGS 3.3.0 error, but the corruption is something I have no idea about.
« Last Edit: 30 Nov 2013, 21:33 by Crimson Wizard »

Scavenger

  • Cavefish
  • In Four Glorious Colours!
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with scripting
    •  
    • Scavenger worked on a game that was nominated for an AGS Award!
      Scavenger worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #132 on: 30 Nov 2013, 21:51 »
Additional suggestion: Can we get the 8 bit palette arrays accessable in Lua? I'm currently working on a module that relies on the palette and Lua doesn't have access to it (I tried ags.palette.r etc and it came up with nothing).

Also, LuaValueList.ToArray() seems to be missing from the copy of the plugin on the Downloads page? It doesn't show up in Autocomplete, and it doesn't compile, but it IS in the documentation.

Lua.Evaluate is also missing.
« Last Edit: 01 Dec 2013, 03:18 by Scavenger »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #133 on: 01 Dec 2013, 12:57 »
@Denzil Quixode, your lua-for-ags wiki states:
Quote
The run-time component is a DLL called agslua.dll. This DLL needs to be present in the same directory as your game when it runs, as well as lua51.dll and lua5.1.dll, which agslua.dll depends on. (These should hopefully all be copied in automatically.)
However lua51.dll is never copied to Compiled folder, and game seem to run without it as well.


Another thing I should mention just in case: the game will crash badly if the script .dat file is missing (AGS 3.2.1).
« Last Edit: 01 Dec 2013, 13:00 by Crimson Wizard »

Re: PLUGIN: Lua for AGS
« Reply #134 on: 01 Dec 2013, 18:24 »
@Denzil Quixode, your lua-for-ags wiki states:
Quote
The run-time component is a DLL called agslua.dll. This DLL needs to be present in the same directory as your game when it runs, as well as lua51.dll and lua5.1.dll, which agslua.dll depends on. (These should hopefully all be copied in automatically.)
However lua51.dll is never copied to Compiled folder, and game seem to run without it as well.
Ah, oops, thank you, I've changed it. (This was originally true, there WERE two DLLs, because of some confusing issue where some things want to link against "lua51" rather than "lua5.1" -- but once I realised it shouldn't affect this plugin, I removed the extra DLL copy, which only acted as a proxy to the other DLL anyway.)

Another thing I should mention just in case: the game will crash badly if the script .dat file is missing (AGS 3.2.1).
Thanks for the report, I'll start adding these things to the github tracker.
« Last Edit: 01 Dec 2013, 18:27 by Denzil Quixode »

Re: PLUGIN: Lua for AGS
« Reply #135 on: 01 Dec 2013, 22:47 »
I've been having some problems with the project getting corrupted if AGS doesn't crash cleanly. In 3.3.0, at least, if the engine stalls and needs to be shut down manually (prompting the "The AGS engine did not shut down properly" error in AGS), any Lua calls will crash a few loops in with:

Quote
Adventure Game Studio
---------------------------
An internal error has occurred. Please note down the following information.
If the problem persists, post the details on the AGS Technical Forum.
(ACI version 3.3.0.1148)

Error: [Lua] [string "local select = select;local error = error;l..."]:1: bad argument #2 to 'setter' (number expected, got nil)

I've included a copy of the ruined project here:
Thank you very much for the test case!

So, I have to apologise for that error message. I know there's no way you would be able to guess this, but the actual problem here is that you end up assigning nil to OSSurface.DrawingColor in your ProcessTranslucency() function.

I will have to do something about that error message, so it actually shows your script/line number (instead of blaming the internal script that handles the "DrawingColor" getter/setter)

For now, you can do a temporary workaround get better error messages here by changing lines like this:

Code: Lua
  1. OSSurface.DrawingColor = <VALUE>

...to this:

Code: Lua
  1. OSSurface.DrawingColor = assert(  <VALUE>  ,'DrawingColor cannot be nil')

Digging in a bit, it looks like BGSurface:GetPixel(x,y) is returning -1 sometimes, and this leads to it looking up clut[ i ][ j ] for a negative j, which is where the nil value comes from. I'm afraid I have no idea whether GetPixel returning -1 is something that should ever happen or why it would be related to project corruption or 3.3.0, etc.

Also, LuaValueList.ToArray() seems to be missing from the copy of the plugin on the Downloads page? It doesn't show up in Autocomplete, and it doesn't compile, but it IS in the documentation.

Lua.Evaluate is also missing.
I must apologise for this too - I changed my mind several times on how the whole LuaValueList/LuaValue API stuff should work, and was inconsistent about both implementing and documenting features in it, as things got rewritten and moved around... I plan to move all the documentation and stuff over to GitHub soon, and as part of that I will double-check everything in the docs as I do it, so there's no more nasty surprises like this.
« Last Edit: 01 Dec 2013, 23:06 by Denzil Quixode »

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #136 on: 01 Dec 2013, 22:57 »
GetPixel returns -1 because COLOR_TRANSPARENT is -1 so it just refers to a mask pixel.

Re: PLUGIN: Lua for AGS
« Reply #137 on: 01 Dec 2013, 23:17 »
GetPixel returns -1 because COLOR_TRANSPARENT is -1 so it just refers to a mask pixel.
That makes sense, but seems odd since we're talking about what I assume is a room background surface -- do room backgrounds have transparency masks?

(That's probably something to discuss further in the Advanced Technical Forum thread about this, which I've only just noticed)

Re: PLUGIN: Lua for AGS
« Reply #138 on: 02 Dec 2013, 13:40 »
Additional suggestion: Can we get the 8 bit palette arrays accessable in Lua? I'm currently working on a module that relies on the palette and Lua doesn't have access to it (I tried ags.palette.r etc and it came up with nothing).
I've made changes to the code (there'll be a new build soon) to allow ags.palette[ i ].r etc. to work, and also a (probably faster) alternative form that uses Lua's multiple-return value feature:
Code: Lua
  1. local r,g,b = ags.palette.getRGB(3)
  2. ags.palette.setRGB(5, 0,63,0)
  3.  
  4. -- copying a colour from one slot to another
  5. ags.palette.setRGB(30, ags.palette.getRGB(11))

Re: PLUGIN: Lua for AGS
« Reply #139 on: 11 Sep 2014, 14:04 »
Ok, I converted the intro room script to Lua.
Do I put the Lua code in place of the original ags room code.
Or is their more?
What if your blessings come through raindrops
What if your healing comes through tears...

Calin Leafshade

  • AGS Project Tracker Admins
  • Long live King Cat!
    • I can help with making music
    •  
    • I can help with voice acting
    •  
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #140 on: 11 Sep 2014, 15:05 »
There is significantly more.

The AGS-Lua link is purely manual. If you want to trigger AGS events in lua then you need to wire that up yourself.

You need a fairly good grasp of programming before you'll be able to understand how this is done.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #141 on: 11 Sep 2014, 15:28 »
Ok, I converted the intro room script to Lua.
Do I put the Lua code in place of the original ags room code.
Or is their more?
There's an explanation with script examples in the very first post of this very thread.

In short, you are to put "Lua.RunScript("whatever_name_i_have.lua");" in game_start, and then put "Lua.Call("my_function_name")" whenever you want to call a function from lua script.
« Last Edit: 11 Sep 2014, 15:32 by Crimson Wizard »

Re: PLUGIN: Lua for AGS
« Reply #142 on: 11 Sep 2014, 21:41 »
Thanks for the replies.  Looks like I won't be able to use this.
What if your blessings come through raindrops
What if your healing comes through tears...

Re: PLUGIN: Lua for AGS
« Reply #143 on: 21 Nov 2014, 08:34 »
Just for information. When I go to the download page it says "Subscription Expired". No downloads available.

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #144 on: 01 Mar 2015, 05:06 »
http://duals.agser.me/Plugins/LuaForAGS_v4.rar

Found an old cd, and it had a version of certain plugins and one of them happened to be lua.
No more military army stuff. I'm alive and back.

Re: PLUGIN: Lua for AGS
« Reply #145 on: 11 May 2016, 08:02 »
Hi,
sorry for writing in this old topic, but I have a problem with this plugin.
I have installed it correctly and it works fine with simple lua scripts. But now, in order to write my real code, I need another lua module (luasql.sqlite, exactly).
In this case, what should I do? I am not expert about how Lua Works and I haven't found any dll for that module; and If I am not wrong the modules I got must be installed directly into lua.

Can you give me any hint?

Thanks.
Hi, this signature is not funny because my imagination is actually on holiday.

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 #146 on: 11 May 2016, 09:30 »
Hi,
sorry for writing in this old topic, but I have a problem with this plugin.
I have installed it correctly and it works fine with simple lua scripts. But now, in order to write my real code, I need another lua module (luasql.sqlite, exactly).
In this case, what should I do? I am not expert about how Lua Works and I haven't found any dll for that module; and If I am not wrong the modules I got must be installed directly into lua.

Can you give me any hint?

Thanks.
You'd be probably better off asking on the Lua forums, but I'm sure Calin Leafshade will help if he sees your update (did you try PM'ing him?)
 

Re: PLUGIN: Lua for AGS
« Reply #147 on: 11 May 2016, 09:41 »
Hi,
sorry for writing in this old topic, but I have a problem with this plugin.
I have installed it correctly and it works fine with simple lua scripts. But now, in order to write my real code, I need another lua module (luasql.sqlite, exactly).
In this case, what should I do? I am not expert about how Lua Works and I haven't found any dll for that module; and If I am not wrong the modules I got must be installed directly into lua.

Can you give me any hint?

Thanks.
You'd be probably better off asking on the Lua forums, but I'm sure Calin Leafshade will help if he sees your update (did you try PM'ing him?)

I've done that some day ago(with another question, to be honest), but I've got no answer.
You know, I found a "sqlite3.dll" file, but I fear it's not enough - I'd should add something which allows comunication between lua and sqlite, shouldn't I? :P Before asking to official lua forums (where I am not sure they know about this old plugin) I wanted to ask here, I'll be waiting some time. :)
« Last Edit: 11 May 2016, 09:43 by TheNaiker »
Hi, this signature is not funny because my imagination is actually on holiday.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: PLUGIN: Lua for AGS
« Reply #148 on: 11 May 2016, 17:51 »
I would start by writing a proof-of-concept test just in Lua (without AGS) to access SqlLite. This seems to be how to load a DLL: https://www.lua.org/pil/8.2.html, or you could try this: http://alien.luaforge.net/

If you can't get that to work, you need Lua-specific help. If you can, it should also work in AGS, and if it doesn't there might be something you need to do with the plugin or AGS build.
« Last Edit: 11 May 2016, 17:55 by Snarky »

Re: PLUGIN: Lua for AGS
« Reply #149 on: 11 May 2016, 19:38 »
Thanks, your second hint looks to be good. I typed this
Code: Lua
  1. function readDb (ID)
  2. assert (package.loadlib("sqlite3.dll", "luaopen_luasql_sqlite3"))()  
  3. env = luasql.sqlite3()
  4. con = env:connect("test.db")
  5. res = con:execute("create table person( id integer primary key,name text not null, email text, phone text)")
  6. con:close()
  7. env:close()
  8. a = 12
  9. return a
  10. end
And after compiling and running the "test.db" file has been created without error messages. (I used the A variable to see if Ags runs the script)
I will make further tests, but I am satisfied with this. Thanks again.
Hi, this signature is not funny because my imagination is actually on holiday.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: PLUGIN: Lua for AGS
« Reply #150 on: 11 May 2016, 20:02 »
Sweet! I don't know Lua, but that looks good so far. And thanks for posting your sample code, I'm sure that could be helpful for others.

Hope it works out.
« Last Edit: 11 May 2016, 20:04 by Snarky »

Re: PLUGIN: Lua for AGS
« Reply #151 on: 22 Jan 2018, 21:10 »
Hey! What's the status of this plugin? Is there an update? Is source code available somewhere? The first page link points to an expired wiki.

I played a little bit with love2d this weekend and would like to test using lua to use shaders :]

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: PLUGIN: Lua for AGS
« Reply #152 on: 02 Jul 2018, 12:51 »
Hey! What's the status of this plugin? Is there an update? Is source code available somewhere? The first page link points to an expired wiki.

We have this plugin as submodule in our repository. Actual repository is https://github.com/duncanc/Lua-for-AGS/commits/master

The status of plugin is unknown. It seems to be made in such way that requires continious sync with the engine to have full support. Yet it was last updated in 2013, which means it cannot work with the any recently added engine API.
Also the reason I believe we should drop supporting this plugin when developing AGS 4 branch, because plugin is strictly tied to the engine's data layout in memory. Unless there would be a maintainer who rewrites it in a different way.