|
On 2012-10-21 3:40 PM, "Giuliano Suminsky" <yksnimus@gmail.com> wrote:
>
> Hey there
>
> To illustrate my confusion:
>
> Imagine an AI agent, the input is a map 20x20 with IDs(player, power
> ups, obstacles..) and current HP, the output is a movement to some
> tile, and an action:(shoot(requires direction), defend and use power
> up...
>
> How to use lua to define this agent decision making code? The only
> stupid thing I can think is calling a lua function passing a zillion
> of parameters and returning a zillion of weird values on the stack
> that are actually keywords + value pairs that the c++ code understands
> ( i.e. passing an 20x20 array to the stack, the HP, and returning
> something like [A, 8, 4, B, up], 'A' being a keyword for movement,
> witch is followed by tile x and y, 'B' meaning shoot, followed by a
> direction..)
>
> Resuming, I dont know how to modulate the architecture around Lua/c++
> to do the stuff I wish to do. Every times I read an article about this
> someone throws another Lua OO library at your face..But thats not what
> I want, I want to know how to do that with Lua.
It sounds like you need to rethink how your code is interacting. You have an "AI object" C++ class of some type and you want Lua code to decide what it should do? Probably the simplest method is to return a table of actions for the C code to handle, like {{'move', 2, 3}, 'shoot', ...}
A more elegant method, that might also be easier to write, is to give the object "move" and "shoot" methods that the Lua part can call. The C part might execute these actions immediately or store them in a queue.
>
> - another unrelated question -
>
> When you use Lua as data/config files, can update the data on a .lua
> file (using lua library or in lua script itself)? Lets say you using
> a .lua to save the last user video options (resolution, vsync, msaa),
> if he changes it, how to update the .lua file? )...
>
Look at string.format('%q'). My personal preferred method is to store defaults in some internal file (or even string), then just write any changed options to a user config file. e.g.
defaults.lua:
display = {
width = 640,
height = 480,
depth = 24,
}
external config.lua:
display.depth = 16
that way the user config file is a simple one-value-per-line format, so if display.depth changes again you can easily find and replace that line, and deleting the file reverts to defaults instead of breaking the game. That also allows you to use nice functions in defaults.lua (object constructors, include external files, etc) while sandboxing the user config by giving it an environment without anything it doesn't need.