Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Denzil Quixode

#21
^^ Yeah, a good suggestion from Calin there. So it looks like Lua's C8PaletteMap has some holes in it, not all palette slots are being set in ProcessPalette().

One thing I notice about ProcessPalette() is that you're taking an array of parameters using palindex = {...} but this array will start from 1 rather than 0, and later code adapted from AGSScript naturally isn't expecting this. So to change it to a 0-based array, you could change the first few lines of ProcessPalette() from:

Code: Lua
function ProcessPalette (...)
  local palindex = {...}
  local paltemp = {...}
  local palsiz = #palindex


...to:

Code: Lua
function ProcessPalette (...)
  local palindex = {}
  local paltemp = {}
  local palsiz = select('#', ...) -- get number of arguments
  for n = 1, palsiz do
    palindex[n - 1] = select(n, ...) -- get nth argument
    paltemp[n - 1] = select(n, ...)
  end


A second thing in ProcessPalette(): it looks like, in the first while-loop, where the original AGSScript version of the function uses ags.palette[palindex[ i ]].r etc. the Lua version uses (the equivalent of) ags.palette[ i ].r
#22
Quote from: Scavenger on Sat 30/11/2013 21:51:50
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
local r,g,b = ags.palette.getRGB(3)
ags.palette.setRGB(5, 0,63,0)

-- copying a colour from one slot to another
ags.palette.setRGB(30, ags.palette.getRGB(11))
#23
Two problems I noticed in the Lua Colourise() function:

  • cpixel is sometimes -1, and C8PaletteMap[-1] doesn't exist, so surface.DrawingColor is being set to nil, which is invalid
  • there's an infinite loop problem in there:
Code: lua
while (i < w) do

  -- ( . . . ) --

  i = j + 1
end
    (...should be i = i + 1)


Also, this bit in ProcessPalette:
Code: Lua
while (i < palsiz)
do
  if (i > palsiz) then upperboundary = 255
  -- ... --


...looks like it should probably have "-2" added, to be equivalent to the AGSScript version in pal2.asc:

Code: AGS
while (i < palsiz)
{
  if (i > palsiz -2) upperboundary = 255;
#24
Hi, hi, really sorry you've been having all these issues with the Lua plugin! Please bear with me a little. This is a really cool project and I always wanted people to use the plugin for ambitious interesting things so I feel like I've really dropped the ball on this one. I have posted some stuff in the plugin thread about where the problem seems to be in issue 1.) there. I will address missing API functions and the lousy documentation as soon as I can. Sorry again!
#25
Quote from: Calin Leafshade on Sun 01/12/2013 22:57:31
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)
#26
Quote from: Scavenger on Sat 30/11/2013 19:13:25
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:

QuoteAdventure 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
OSSurface.DrawingColor = <VALUE>


...to this:

Code: lua
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.

Quote from: Scavenger on Sat 30/11/2013 21:51:50
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.
#27
Quote from: Crimson Wizard on Sun 01/12/2013 12:57:00
@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.)

Quote from: Crimson Wizard on Sun 01/12/2013 12:57:00
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.
#28
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...
#29
This is great, thank you!

Here is my contribution - a special BASS version of Character.Say()!

Code: AGS
function Say_BASS_Style(this Character*, String message)
{
  String bass_style = "";
  int space_idx = message.IndexOf(" ");
  bool prev = false;
  while (space_idx != -1)
  {
    String part = message.Substring(0, space_idx + 1);
    message = message.Substring(space_idx + 1, message.Length - (space_idx + 1));
    if (prev)
    {
      prev = false;
    }
    else if (Random(1) == 0)
    {
      part = part.UpperCase();
      prev = true;
    }
    bass_style = bass_style.Append(part);
    space_idx = message.IndexOf(" ");
  }
  if (!prev && Random(3) == 1) message = message.UpperCase();
  bass_style = bass_style.Append(message);
  return this.Say(bass_style);
}


( (laugh)  (laugh)  (laugh) )
#30
I do hate to turn away an enthusiastic potential user :/ Thank you so much for documenting the errors you encountered though.
#31
Quote from: pietakio on Thu 17/01/2013 00:40:27
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...?

Quote from: pietakio on Thu 17/01/2013 00:40:27
"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?

Quote from: pietakio on Thu 17/01/2013 00:40:27
"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.

Quote from: pietakio on Thu 17/01/2013 00:40:27
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...
#32
Quote from: pietakio on Wed 16/01/2013 14:12:20
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...
#33
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.
#34
To be honest, the way things are now, it is likely to be confusing to jump straight to Lua. The plugin does not completely replace AGS-Script. Instead, it adds special functions to AGS-Script's standard set of functions, and these functions can run Lua scripts and call Lua functions, etc. So it's still AGS-Script running the show, handling game-events and so on, but it can choose to pass control over to Lua.

For example, in AGS-Script, if you want to do something whenever a mouse button is clicked, you would add an on_mouse_click() handler in AGS-Script:

Code: ags
function on_mouse_click(int button)
{
  Display("You clicked mouse button %d at co-ordinates (%d,%d)", button, mouse.x, mouse.y);
}


...and that's it, that's all you need to do.

But to do the same thing with Lua, you could first create a Lua script - let's call it mousehandler.lua - that defines the function:

Code: Lua
-- mousehandler.lua
function on_mouse_click(button)
  ags.Display("You clicked mouse button %d at co-ordinates (%d,%d)", button, ags.mouse.x, ags.mouse.y)
end


...and then you also need to set up AGS-Script to run mousehandler.lua when the game starts up, and then call the function when it should be called:

Code: ags
function game_start()
{
  Lua.RunScript("mousehandler.lua");
}

function on_mouse_click(int button)
{
  Lua.Call("on_mouse_click", Lua.IntValue(button));
}


Quoteare there things that can't be done in Lua that can in AGS Script
Well, you can only call standard built-in AGS functions, so you can't use any other plugins from Lua, and you can't directly use AGS-Script modules (you'd have to convert them to Lua). You also can't do bitwise operations very easily at the moment (but if you don't happen to already know what those are, it probably isn't going to be something you need).
#35
Quote from: Monsieur OUXX on Wed 02/01/2013 10:02:52
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.
#36
There is a serious problem with Lua C modules (like a DirectX binding) in AGS, unfortunately. There is no reasonable way for the plugin's Lua state serialization system to know how to save an external C function. All the standard built-in C modules ('math', 'string' etc.) are carefully processed when the game starts up, but once you load your own one the next time the game tries to save it is likely to not be able to. There are ways to get around this (like removing the loaded module when you save the game and restoring it after you load), and hopefully in the future features could be added to make it easier to deal with, but I think it is impossible to ever make it completely seamless.
#37
Quote from: KhrisIf I want to build a game, and that game's going to benefit greatly from the stuff Lua can do that AGSScript doesn't support (well) because the game is far removed from a classical adventure with rooms and characters' walk cycles and the like (...)
Well, back when I originally made the plugin I did intend for it to be used for adventure games. (I don't think I even had RPGs in mind, I'm not much of an RPG guy myself.) What I really hoped for is that it would be helpful to someone who wants to make an adventure game that pushes the bounds of what an adventure can be, without losing its identity as an adventure game. I would love to help people do ambitious, experimental, new things in their adventure games -- ideally, things that would be as new to us today as the interface in Loom or the Virtual Theatre system in Lure of the Temptress were, 20-odd years ago.

That's the dream, anyway. So it depends what you mean by making a "classical adventure"-like game: whether you only mean going with specific conventions and mechanics originally established by those games, or whether there is also room for trying to continue in the spirit of inventiveness, experimentation and upheaval that a lot of those games actually had at the time they came out.
#38
Quote from: Crimson Wizard on Sun 30/12/2012 22:20:12
Quote from: Calin Leafshade on Sun 30/12/2012 22:13:03(Second also, I love syntax like this:
Code: lua
local r, g, b = getRGB(65535)
And I don't :/. That looks like defining two variables with undefined value and initialize one variable with function's return value.

If it disturbs you too much, you can always stick 'em in a table :)

Code: Lua
local rgb = {getRGB(65535)}
local r = rgb[1]
local g = rgb[2]
local b = rgb[3]


I know they're unusual, I think Google's "Go" is the only other language I remember seeing with multiple return values. There's some interesting things you can do with them. You can use multiple return values as multiple arguments to another function, for example:

Code: Lua
ags.SetFadeColor(getRGB(40892))    -- a nice eggshell blue...


The standard Lua function assert() takes two arguments. If the first argument is false or nil, it throws an error, using the second argument as the error message. Otherwise, it returns the first argument unchanged. For example, if you want to get the current active inventory item and throw an error if there isn't one, you could do this:

Code: Lua
local activeinv = assert(ags.player.ActiveInventory, "there is NO active inventory item!!")
-- ...do something with activeinv...


In combination with multiple return values from functions, this can be a useful coding-pattern. For example, if you try opening a file to read but the file doesn't exist, io.open() will return nil instead of a file object:

Code: Lua
local f = io.open('i_dont_exist.txt', 'rb')
if f == nil then
  print('unable to open the file!')
else
  -- ...do something with f...
end


...except it doesn't just return nil - it also returns a "file not found"-like error message string, as the second return value. You don't notice here because it just gets discarded. So, if you want to throw an error if the file cannot be opened, rather than handling it yourself:

Code: Lua
local f = assert( io.open('i_dont_exist.txt', 'rb') )   -- /!\ ERROR: i_dont_exist.txt: No such file or directory
-- ... do something with f


In this way, when you write a function you are not forced to choose between throwing an error if it is unable to get a valid result (which can be annoying if it's not a fatal problem), or just returning nil (which is "friendlier", but sometimes it is a fatal problem to your code, and it's helpful to have a handy error message around - especially if there's several different things that could have gone wrong).
#39
Quote from: Khris on Sun 30/12/2012 21:32:14
Say I want to use lua tables to store all my tile info for an RPG.
What do I do to draw on a room background? Do I still use AGS's raw drawing?

Yes, you'd still use the same functions essentially, just with (slightly) different syntax. Here is a Lua equivalent for the manual's example for Room.GetDrawingSurfaceForBackground():

Code: Lua
local surface = ags.Room.GetDrawingSurfaceForBackground()
surface.DrawingColor = 14
surface:DrawLine(0, 0, 50, 50)
surface:Release()


It should seem pretty familiar... the tricky one is that method calls on the surface object must use a colon ':' rather than a dot '.' before the method name, while property accesses still use the dot, and so do static function calls on the Room type.
#40
Quote from: Calin Leafshade on Sun 30/12/2012 15:13:13
Then it might be a good idea to expose some functions to us in the API to get colours from AGS colours since thats the only reason we'd need bitwise functions anyway probably.

Oh, like the Colour Finder you mean? I do have a function for that:

Code: Lua

local floor = math.floor

local low32 = {
  [-1] = 0x000000; -- COLOR_TRANSPARENT
  [ 0] = 0x000000; [ 1] = 0x0000A5; [ 2] = 0x00A500; [ 3] = 0x00A5A5;
  [ 4] = 0xA50000; [ 5] = 0xA500A5; [ 6] = 0xA5A500; [ 7] = 0xA5A5A5;
  [ 8] = 0x525252; [ 9] = 0x5252FF; [10] = 0x52FF52; [11] = 0x52FFFF;
  [12] = 0xFF5252; [13] = 0xFF52FF; [14] = 0xFFFF52; [15] = 0xFFFFFF;
  [16] = 0x000000; [17] = 0x101010; [18] = 0x212121; [19] = 0x313131;
  [20] = 0x424242; [21] = 0x525252; [22] = 0x636363; [23] = 0x737373;
  [24] = 0x848484; [25] = 0x949494; [26] = 0xA5A5A5; [27] = 0xB5B5B5;
  [28] = 0xC6C6C6; [29] = 0xD6D6D6; [30] = 0xE7E7E7; [31] = 0xF7F7F7;
}

function getRGB(agsColor)
  if agsColor < 32 then
    local rgb = low32[agsColor] or 0x000000
    return floor(rgb / 0x10000) % 0x100,
           floor(rgb /   0x100) % 0x100,
                 rgb            % 0x100
  end
  return (floor(agsColor / 0x800) % 0x20) * 8,
         (floor(agsColor /  0x20) % 0x40) * 4,
         (      agsColor          % 0x20) * 8
end


...to be used like this:

Code: Lua
local r, g, b = getRGB(65535)
SMF spam blocked by CleanTalk