Basic Lua Stopwatch

  • FeynmanLogomaker
    16th Jul 2013 Member 1 Permalink

    I don't think I need to give instructions; the buttons are really self-obvious. Start to start, stop to stop and reset to reset.

     

    local running = false
    local frameCount = 0
    function drawmeter()
    tpt.fillrect(4,335,25,10,255,255,255,255)
    tpt.drawtext(6,337,"Start",0,0,0,255)
    tpt.fillrect(29,335,22,10,255,255,255,255)
    tpt.drawtext(31,337,"Stop",0,0,0,255)
    tpt.fillrect(51,335,27,10,255,255,255,255)
    tpt.drawtext(53,337,"Reset",0,0,0,255)
    tpt.drawtext(80,337,frameCount .. " frames",155,155,155,255)
    if running == true then
    frameCount = frameCount + 1
    end
    end
    function mouseTesting()
    if tpt.mousex >= 4 and tpt.mousex <= 29 and tpt.mousey >= 335 and tpt.mousey <= 345 then
    running = true
    elseif tpt.mousex >= 29 and tpt.mousex <= 51 and tpt.mousey >= 335 and tpt.mousey <= 345 then
    running = false
    elseif tpt.mousex >= 51 and tpt.mousex <= 78 and tpt.mousey >= 335 and tpt.mousey <= 345 then
    running = false
    frameCount = 0
    end
    end
    tpt.register_step(drawmeter)
    tpt.register_mouseclick(mouseTesting)

     

    Oh, and @mniip, I think I may have beaten you to this one.

  • mniip
    16th Jul 2013 Developer 0 Permalink
    :/
    too simple and useless
  • Lockheedmartin
    16th Jul 2013 Moderator 0 Permalink

    While you're making scripts, I think one idea would be nice. Some sort of system to place "pixels" or sensors. These sensors would output the information such as temperature, element, pressure, etc to a text file. The frame time would be stored next to that information.

     

    Nice script however!

  • FeynmanLogomaker
    16th Jul 2013 Member 0 Permalink

    @mniip (View Post)

     Not quite useless, and simple isn't bad. Your scripts are too complicated, but no one cares...

  • mniip
    16th Jul 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    the more features and uses a thing has, the more complicated it has to be, exactly.
    what's the use of a stopwatch in TPT
  • FeynmanLogomaker
    16th Jul 2013 Member 0 Permalink

    @mniip (View Post)

     Obviously to time things...

     

    And my FPS meter works just as well as yours, looks as good and does everything yours does with much fewer lines...but it can't be as good, it's not as complex...

  • mniip
    16th Jul 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    it's not as good :P
    EDIT: of course, why use half-megabyte GCC to create an executable, if you can open a binary editor and write the ELF file yourself
  • FeynmanLogomaker
    16th Jul 2013 Member 0 Permalink

    Well, it's graphics aren't quite as good (but almost), and it doesn't fade away, but it's just as useable.

     

    And @lockheeedmartin: Challenge accepted. https://powdertoy.co.uk/Discussions/Thread/View.html?Thread=17254 :) It can only place one sensor right now, but I'm getting there.

  • MiningMarsh
    16th Jul 2013 Member 0 Permalink

    Arguably line count doesn't matter, but complexity, readability, maintainibility, and algorithmic complexity (the most important one) do.

     

    Honestly, in this case since the end user is not seeing anything, both scripts are readable, and both run at acceptable speed, it comes down to how many features, and mniip has the clear advantage...

     

    (I am referring to the clock scripts if anyone is wondering.)

  • FeynmanLogomaker
    16th Jul 2013 Member 0 Permalink

    Complexity (algorithmic or otherwise) doesn't really matter if you only consider the end result - more complex programs often run more slowly.