Help pls

  • bowserinator
    30th Nov 2014 Member 0 Permalink

    Why does this code not work? I used visual studio and I added the file into the project and it doe sn't throw any errors. I also added the lua in the project and the directory

    #include "lua/LuaScriptInterface.h"

    #include "lua/LuaLuna.h"

    #include "lua/LuaScriptHelper.h"

    #include "lua/LuaBit.h"

    #include "lua/LuaWindow.h"

    #include "lua/LuaButton.h"

    #include "lua/LuaLabel.h"

    #include "lua/LuaTextbox.h"

    #include "lua/LuaCheckbox.h"

    #include "lua/LuaSlider.h"

    #include "lua/LuaProgressBar.h"

    void luaopen_scriptmanager(lua_State *l){

    #ifndef _MSC_VER

    int scriptmanager_luac_sz = 37193;

    const char* scriptmanager_luac = "crap";

    luaL_loadbuffer(l, scriptmanager_luac, scriptmanager_luac_sz, "@scriptmanager.lua");

    lua_pcall(l, 0, 0, 0);

    #endif

    }

    Edited 2 times by bowserinator. Last: 30th Nov 2014
  • FeynmanLogomaker
    30th Nov 2014 Member 0 Permalink

    What error does it give you?

  • bowserinator
    30th Nov 2014 Member 0 Permalink

    No errors. (I said that already above)

  • FeynmanLogomaker
    30th Nov 2014 Member 0 Permalink

    Oh, my bad.

    What does go wrong?

     

    I've been using this code:

    if(luaL_loadstring(l, scriptmanager_luac) || lua_pcall(l, 0, 0, 0))
    luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
    else
    luacon_ci->Log(CommandInterface::LogNotice, "Loaded script manager");

    That might work better than what you're using, but tbh I only vaguely know what I'm doing

  • jward212
    30th Nov 2014 Member 0 Permalink

    could you add a lua script by doing Require "soandso" in socket.lua, would you need a buffer?

  • FeynmanLogomaker
    30th Nov 2014 Member 0 Permalink

    It's best to do it in the same way it loads autorun.lua, but with a predefined const char* for the source instead of a file. I'd even do it in the same place, just for organization's sake.

  • bowserinator
    30th Nov 2014 Member 0 Permalink

    On an unrealted note sim->drawline or whatever that is doesn't work apparently it doesn't accept arguments of int int int int int, despite following the wiki exactly. Anyone know why

  • jacob1
    30th Nov 2014 Developer 0 Permalink
    It's this define: #ifndef _MSC_VER

    This makes the code not do anything if you are compiling using visual studio. You can remove it, but it will probably error and tell you that the string is too long. If you want to include really large scripts in your mod you'll have to compile using scons, or find another way to include lua scripts inside the exe.

    Also why are you including every single lua header? It should look like this: https://github.com/jacob1/The-Powder-Toy/blob/c%2B%2B/src/lua%20scripts/scriptmanager.lua.cpp



    Also I fixed the wiki entry, I changed CreateLine a really long time ago when I started adding replace mode support and found the drawing code in a really bad state ... It doesn't allow using radius arguments anymore since it's only intended for elements like ETRD and STKM. Drawing from the brush uses an alternate overload of CreateLine with these arguments: int x1, int y1, int x2, int y2, int c, Brush * cBrush, int flags (if you can figure it out ...)
    Edited 3 times by jacob1. Last: 30th Nov 2014
  • bowserinator
    30th Nov 2014 Member 0 Permalink

    It works perfectly! (Not the script since it's too long lol) but why is the line so thick?

  • jacob1
    30th Nov 2014 Developer 0 Permalink