How Do you run a command in C++

  • bowserinator
    9th Nov 2014 Member 0 Permalink

    I really need help so I'm repeating this thread

     

    I'm compiling with visual studio C++ and I was wondering how do you run a command like !set type all gold or !set temp all 9999 or something like that? I assumed it was this line:

    ConsoleCommand(command, returnCode, commandInterface->GetLastError())

     

    but it's probably wrong as it doesn't work. Can anyone help me?

  • FeynmanLogomaker
    9th Nov 2014 Member 0 Permalink

    I've actually tried to figure this out too, with little success. I'll try to find it again.

     

    By the way, it seems like you're making a mod - where might I find it? (or is it released yet?)

  • bowserinator
    9th Nov 2014 Member 0 Permalink

    no it's not released yet. I might in the future.

  • jacob1
    9th Nov 2014 Developer 0 Permalink
    There's some code in Feynman's mod to run lua code, maybe you could find that. It's in GameController.cpp

    Here's the main parts (I think), not sure what else is needed:
    lua_State *l = luacon_ci->l;
    const char* luaCodeC = luaCode.c_str();
    if(luaL_loadstring(l, luaCodeC) || lua_pcall(l, 0, 0, 0))

    luacon_ci->Log(CommandInterface::LogError, luacon_geterror());

    I don't think it's possible to run old console commands except in the console.

  • FeynmanLogomaker
    9th Nov 2014 Member 0 Permalink

    How does the console run said commands?

     

    (By the way, feel free to use my code if it helps)

  • jacob1
    9th Nov 2014 Developer 0 Permalink
    It has it's own weird interpreter thing in TPTScriptInterface.cpp
  • boxmein
    9th Nov 2014 Former Staff 0 Permalink
    @bowserinator (View Post)
    Don't really use console commands in C++ scripts. Stuff like !set type all gold can easily be done with C++ code alone, by modifying either the parts array or calling respective simulation functions.
  • bowserinator
    9th Nov 2014 Member 0 Permalink

    OK, Guess I'm writing my own function to stimulate those commands. Thanks everybody!