interface.removeComponent bug

  • sfsjunior
    29th Jun 2015 Member 0 Permalink

    I was trying to make a simple LUA script for controlling the fps limit without needing to open the console, but when i call interface.removeComponent, it creates the component (a button) instead of removing it (i had a button for enabling other buttons and a button for removing them, both behaved in the same way).

    Here is the code, if you need:

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    local fpsp = Button:new(0,20,100,20,"FPS+");
    local fpsl = Button:new(0,40,100,20,"FPS-");
    local fpsi = Button:new(0,120,100,20,"Type FPS");
    local r = Button:new(150,20,200,20,"Remove buttons from screen");
    local enable = Button:new(0,60,100,20,"Add buttons to the screen");
    interface.addComponent(enable);
    interface.addComponent(r);
    local fps=60;
    function up()
    graphics.drawText(0,100,"Fps limit: "..fps);
    end
    fpsp:action(
    function()
    fps=fps+1;
    tpt.setfpscap(fps);
    end
    );
    fpsl:action(
    function()
    fps=fps-1;
    tpt.setfpscap(fps);
    end
    );
    fpsi:action(
    function()
    inp=tpt.input("Fps limit:","Please type the new fps limit");
    fps=tonumber(inp);
    tpt.setfpscap(tonumber(inp));
    end
    )
    enable:action(
    function()
    tpt.register_step(up);
    interface.addComponent(fpsp);
    interface.addComponent(fpsi);
    interface.addComponent(fpsl);
    enable:enabled(false);
    end
    )
    r:action(
    function()
    interface.removeComponent(fpsp);
    interface.removeComponent(fpsl);
    interface.removeComponent(fpsi);
    interface.removeComponent(enable);
    interface.removeComponent(r);
    tpt.unregister_step(up);
    tpt.message_box("FPS mod:","Buttons removed.");
    end
    )

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    The mod isn't that good... I created it just for not needing to open the console everytime i need to set a different limit for FPS.

     

    Thanks for reading and (possibly) helping!

     

    Post scriptum: sorry for bad english... it's not my mother language.

    Edited once by sfsjunior. Last: 29th Jun 2015
  • chillinpenguin311
    29th Jun 2015 Member 0 Permalink

    What bad english?

  • jacob1
    29th Jun 2015 Developer 0 Permalink
    @sfsjunior (View Post)
    It looks like interface.removeComponent is calling interface.addComponent instead. Blame Simon for this. I fixed it for the next version.

    For now, there is no way to remove a component from the main window. You can still remove components from custom windows though as far as I know.

    Also it looks like this is a nice alternative, you can make a component invisible:
    fpsp:visible(false)
    fpsl:visible(false)
    fpsi:visible(false)
    enable:visible(false)
    r:visible(false)
  • sfsjunior
    29th Jun 2015 Member 0 Permalink

    @jacob1 (View Post)

     Thank you very much!

  • jacob1
    29th Jun 2015 Developer 0 Permalink
    @sfsjunior (View Post)
    If you want to set fps I also recommend this script:
    http://starcatcher.us/scripts/#16

    Edit: that script is very broken but it still somewhat works ...
    Edited once by jacob1. Last: 29th Jun 2015