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 - mrunderhill

#1
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
Sure. Will this work?
#3
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
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
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

    // These are now public instead of private.
    void game_command_pressed(Command command);
    void game_command_released(Command command);


In Game.h

    // force commands
    void force_command_pressed(GameCommands::Command command);
    void force_command_released(GameCommands::Command command);



In Game.cpp

/**
*  \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

//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:

//These were added under "FunctionExportedToLua"
      game_api_force_command_pressed,
      game_api_force_command_released,


And lastly, in main.lua, under update():

function sol.main:on_update()
force_command_pressed("up")
force_command_pressed("attack")
--...
#6
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