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.


Messages - mrunderhill

Pages: [1]
1
Bugs & Feature requests / Re: Controlling the Hero with an AI Script
« on: November 21, 2013, 05:20:51 pm »
Yep, and it's working on my end now, too. I was accidentally using an old version of the executable that didn't have my changes.
One fixed shortcut later and now everything works as expected. Thanks for your help! :)

2
Bugs & Feature requests / Re: Controlling the Hero with an AI Script
« on: November 21, 2013, 04:27:30 pm »
Sure. Will this work?

3
Bugs & Feature requests / Re: Controlling the Hero with an AI Script
« on: November 20, 2013, 10:57:44 pm »
I tried that. Still giving me errors.

Error: In callback(): [string "play_game.lua"]:19: attempt to call method 'force_command_pressed' (a nil value)

4
Bugs & Feature requests / Re: Controlling the Hero with an AI Script
« on: November 20, 2013, 10:11:29 pm »
I tried putting your code into game::on_started() and got this error:

Error: In callback(): [string "play_game.lua"]:19: attempt to call global 'force_command_pressed' (a nil value)

Edit: I've been getting nil values with "force_command_pressed", "game.force_command_pressed", and "game:force_command_pressed," all in game:on_started(). It's probably just a Lua problem. I'll try working with that.

5
Bugs & Feature requests / Re: Controlling the Hero with an AI Script
« on: November 20, 2013, 07:45:20 pm »
I think we've tried something similar to that, but we came across quite a few bugs with that approach: Link would alternate inconsistently between player and AI control, and it looks like there's no way to control anything other than movement from a Movement object.  We'd like to get swordfighting, items, and other elements under AI control, as well, so that may not be the best approach.

My current idea is to just expose some of the GameCommand methods to lua ("game_command_pressed" and "game_command_released," specifically). That way, player input can work like it normally does, with the only change being that the commands are coming from a Lua script instead of the keyboard/joystick. Would that work just as well?

Here's the code I'm using. It compiles and runs without errors, but it doesn't do anything at the moment. I feel like I'm close to getting it working, so any help figuring out what I'm missing would be great.

In GameCommands.h
Code: [Select]
    // These are now public instead of private.
    void game_command_pressed(Command command);
    void game_command_released(Command command);

In Game.h
Code: [Select]
    // force commands
    void force_command_pressed(GameCommands::Command command);
    void force_command_released(GameCommands::Command command);


In Game.cpp
Code: [Select]
/**
*  \brief Forces a command into the command set.
*/
void Game::force_command_pressed(GameCommands::Command command){
    commands->game_command_pressed(command);
}

/**
*  \brief Forces a command into the command set.
*/
void Game::force_command_released(GameCommands::Command command){
    commands->game_command_released(command);
}

In GameAPI.cpp
Code: [Select]
//These lines were added to methods[]
      { "force_command_pressed", game_api_force_command_pressed },
      { "force_command_released", game_api_force_command_released },
//...

//Force command functions
int LuaContext::game_api_force_command_pressed(lua_State* l){
    //Read a string from Lua
    //Compare the string with our Command enums
    Savegame& savegame = check_game(l, 1);
    GameCommands::Command command = check_enum<GameCommands::Command>(
      l, 2, GameCommands::command_names);
    Game* game = savegame.get_game();
    //Call game.force_command_pressed on the resultant command
    game->force_command_pressed(command);
    return 0;
}

int LuaContext::game_api_force_command_released(lua_State* l){
    //Read a string from Lua
    //Compare the string with our Command enums
    Savegame& savegame = check_game(l, 1);
    GameCommands::Command command = check_enum<GameCommands::Command>(
      l, 2, GameCommands::command_names);
    Game* game = savegame.get_game();
    //Call game.force_command_pressed on the resultant command
    game->force_command_released(command);
    return 0;
}

In LuaContext.h:
Code: [Select]
//These were added under "FunctionExportedToLua"
      game_api_force_command_pressed,
      game_api_force_command_released,

And lastly, in main.lua, under update():
Code: [Select]
function sol.main:on_update()
force_command_pressed("up")
force_command_pressed("attack")
--...

6
Bugs & Feature requests / Controlling the Hero with an AI Script
« on: November 19, 2013, 06:50:28 pm »
Hello,
    I'm working with a team for a Game AI project, and we were hoping to use Solarus as a framework for making a Zelda AI, but we're having some issues linking our AI to the engine. We were wondering what the easiest way to get the Hero to move on its own would be, if we wanted to emulate a human player with our AI. Any help on this would be appreciated, as the project checkpoint is due Friday and this is making us fall way behind.

Cheers,
~MrUnderhill

Pages: [1]