Simple FPS limit UI

  • sfsjunior
    29th Jun 2015 Member 0 Permalink

    Some saves require that you change the game's fps limit. This script creates a UI for doing that in a much simpler way.

     

    It's very simple, but helps in many situations.

    --------------------------------------------------------------------

    HOW DO I USE THIS?

    Open the game and press "O" or "o" to [o]pen the UI. "FPS+" increases the FPS limit. "FPS-" decreases the FPS limit. "Type FPS" opens an input box for typing the fps limit.

    --------------------------------------------------------------------

     

     

     

    CODE:

    Save that as autorun.lua on the directory where your powder toy binary file is (or if you have script manager, save it with any name) and then open the game.

    -----------------

    ||AUTORUN.LUA||

    -----------------

     

    -----------------------------------------------------------------------------------

     

    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,"Start");
    interface.addComponent(enable);
    interface.addComponent(r);

    interface.addComponent(fpsp);
    interface.addComponent(fpsi);
    interface.addComponent(fpsl);

    fpsp:visible(false);
    fpsl:visible(false);
    fpsi:visible(false);
    enable:visible(false);
    r:visible(false);
    enable:enabled(true);

    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);
    fpsp:visible(true);
    fpsl:visible(true);
    fpsi:visible(true);
    enable:enabled(false);
    end
    )
    r:action(
    function()
    fpsp:visible(false);
    fpsl:visible(false);
    fpsi:visible(false);
    enable:visible(false);
    r:visible(false);
    enable:enabled(true);
    tpt.unregister_step(up);
    end
    )

    tpt.register_keypress(function(key,keycode,ignorethis,ignorethis1)

    if key=="o" or key =="O" then
    enable:visible(true)
    r:visible(true)
    end

    end);



    -----------------------------------------------------------------------------------

     

    Thanks for reading this!

     

    PS: Sorry for bad english, i'm not a native english speaker.

    Edited once by sfsjunior. Last: 29th Jun 2015