Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Fingercomp

Members
  • Content Count

    120
  • Joined

  • Last visited

  • Days Won

    35

Posts posted by Fingercomp

  1. So, I guess, you want to unserialize a table. This can be done using the unserialize function from the serialization library. Here's the sample code:

    -- Require the library
    local srl = require("serialization")
    
    -- The table of serialized tables
    tables = {
      '{user = "ADMIN", pass = "ADMIN", settings = {}, admin = true}',
      '{user = "KARASURO", pass = "TEST", settings = {}}'
    }
    
    -- The table where unserialized tables will be put
    unsrlTables = {}
    
    -- Finally, unserialize
    for k, tbl in pairs(tables) do
      unsrlTables[k] = srl.unserialize(tbl)
    end
    
  2. In OpenOS 1.6 the piping system was greatly improved, and is capable to redirect not only io.stdxxx buffers, but also print and term.write.

    So, to be able to redirect the output of your program, you should consider either upgrading OpenComputers, or using io.write instead of print.

     

    And the fs issues... I think your test program should look like this:

    local fs = require("filesystem")
    local f = fs.open("/testfile.txt", "w")
    print(f)
    print(f:write("testtext")) -- colon, not period
    f:close() -- and here, too
    

    But why do you not just use io.open? You don't need to require any library, and it writes into the internal buffer, which flushes on close or by using a :flush, as the raw fs handle writes directly onto the disk, and, obviously, takes more time.

  3. The problem is that all programs that previously were on magic component filesystems (e.g., pastebin, wget) got moved to loot disks. So you need to craft any loot disk (e.g., openos or oppm) with a scrench to get another one, and cycle through them until you get a floppy you need. Then you simply type install, and install program(s) on floppy disk.

    Another option you may consider is updating your OC to the very latest version, which can be found here. In one of those builds internet-related programs were moved to OpenOS. You will only need to reinstall OS (the installer will only copy the OS's files and won't do anything with yours), which is done the same as installing it (don't forget to update the openos floppy, i.e., cycle through all loot disks, if you choose this option).

  4. Replace your wait function with this one:

    local function wait(seconds)
      local begin = os.time()
      repeat
        computer.pullSignal(0.05)
      until os.time() - begin >= seconds
    end
    

    OpenComputers devices (such as servers, drones, etc.) should call the computer.pullSignal function periodically, or they'll crash. Just like your µC does.

  5. So, basically, the things you need to get your computer running:

    • Computer case, a block where cards, CPU, RAM and HDDs are located.
    • Central processing unit (CPU).
    • Memory (at least 2 x T1).
    • Hard disk drive.
    • Graphics card.
    • If your computer case is tier 2 or lower, you'll also need a disk drive.
    • EEPROM (Lua BIOS) — a blank one won't work.
    • OpenOS floppy disk (simply combine a blank floppy with a OpenComputers manual in the crafing grid).
    • Power converter.
    • Screen.
    • Keyboard.

    When you have all of these things, do:

    1. Place a power converter next to the power source. This block will convert such types of energy as RF, EU, GJ, AE, to OpenComputers' internal one.
    2. Then, place your computer case. If it's placed not next to the power converter, you'll also need OC cables — connect the converter to the computer with it.
    3. Place a screen next to the computer case.
    4. Place a keyboard on the screen.
    5. If you crafted a disk drive, place it next to the computer. Insert OpenOS floppy into it. If your computer case is T3, just insert the floppy in its slot into the computer.
    6. Insert memory, CPU, HDD, EEPROM and graphics card into the computer case.
    7. And then, finally, start your computer.

    (Oh, I didn't see the page on wiki. Then it would be more useful than all of this text)

  6. CC has a treasure disk with this on it - theirs has a toggleable option that shows colors representing the cells - red for a cell that will die next turn, green for a cell that will live, and yellow for a cell that will be born. I really liked that feature - and it looks pretty.

    I've updated the game. One of new features is highlighting, toggled by [c]. (Red means that a cell will die next turn. Green - will be born. White - stays alive)

    J7enOnc.png


    vAxFyhu.png

    Other features:

    • [backspace] clears the board;
    • [<] and [>] controls the speed of the simulation;
    • [Enter] updates the board if the simulation is paused (something like one-step simulation);
    • Generation counter.
  7. This program can download gists, upload files to gist and do some more things.

    It uses JSON library, which will be downloaded automatically if it is missing.

     

    Usage:

     

    For example, you need to upload some junk.

    To do this, you need to specify -p flag. --P=s flag makes your gist to be a secret one (it will not show up in lists). Use --desc="description" to provide a description for a gist. Then you should specify each file you want to upload as argument. (/path/to/the/file/on/computer.lua=fileOnGistWith.ext). The command will look like this:

    gist -p --P=s --desc="Hello, world!" /examples/hello.c=helloworld.c /examples/hello.lua=helloworld.lua
    

    You will get a long URL to the created gist, like this one: https://gist.github.com/anonymous/a2b3c5d7e9f1a3b5c7d9e

    That's why there's a -s option. If you specify it when uploading, you'll get a short URL.

     

    Let's assume you want to download this gist.

    If you type the following command:

    gist a2b3c5d7e9f1a3b5c7d9e
    

    the contents of the gist will be printed on the screen. But what if there are multiple files? Then you'll get an error with a list of files. So I need to choose one and specify it with the --f option: --f=helloworld.c.

    If this program was unable to save contents to a file, I think, it would be useless. So if you need to save gist to the file /tmp/helloworld.c, you should place it after the gist ID.

    gist --f=helloworld.c a2b3c5d7e9f1a3b5c7d9e /tmp/helloworld.c
    

    If the output file existed, you had to specify -r flag.

    Instead of gist ID you can use Git.io URL.

     

    There's some other options left.

    • -s. Shorten a specified URL via Git.io.
    • -R. Show a raw file contents URL.
    • -q. Quiet mode: do not show regular info.
    • -Q. Superquiet mode: do not show errors.
    • -l. List files in a gist.
    • -i. Show info about file.
    • -G. Show info about gist.

    If you won't specify any arguments, the help will be displayed.

     

    Download:

    wget https://raw.githubusercontent.com/OpenPrograms/Fingercomp-Programs/master/gist/gist.lua gist.lua
    
  8. eAINaIq.png

    OK, here's what you should do in this game:

    • Create an initial configuration.
    • Observe how it evolves.
    Sounds simple?

    This program is something like the pixel editor. You have a board with a grid, pressing left mouse button places a cell, pressing right one kills a cell. All the magic begins when you press [space bar]. Then every 1/10 s the board updates according to the following rules:

    • Every cell may have up to 8 neighbors.
    • Any live cell with 0 or 1 neighbors dies (under-population).
    • Any live cell with 2 or 3 neighbors lives on to the next generation.
    • Any live cell with more than 3 neighbors dies (over-population).
    • Any dead cell with exactly 3 neighbors becomes a live one (reproduction).
    You can find more information here.

    Controls:

    • [space bar] Start or pause simulation.
    • [RMB] Kill a cell.
    • [LMB] Place a cell.
    Requirements:
    • Tier 3 screen (only this screen supports precise mode).
    • Tier 3 graphics card.
    Download:

    wget https://raw.githubusercontent.com/OpenPrograms/Fingercomp-Programs/master/game-of-life/game-of-life.lua gol.lua
  9. Command blocks has three methods:

    cb.setCommand(command)
    cb.getCommand()
    cb.executeCommand()
    

    So your code must look like this:

    local component = require("component") 
    local cb = component.command_block 
    local ticks = math.floor(1000/60/60 * os.time() - 6000) 
    print(os.date()) 
    cb.setCommand("time set " .. (ticks + 24000)) 
    cb.executeCommand() 
    print(os.date())
    

    If command block driver was disabled in the config, this program would crash with error "no such component".

     

    P. S. This wiki is outdated, use ocdoc.cil.li.

  10. Seems pretty good, although might need some fixing of the time zones, it was an hour behind for me.

    Time is completely messed up. But, yeah, some changes to the code are required.

    ***

    New CORRECT setting makes possible to do some tweaking with time zones.

  11. Long time ago I wrote a small program. It displays in-game time and real-life time.

    Pastebin: pastebin get aKjh5SZL clock.lua

     

    By default, touching the screen switches mode (from RL to in-game and vise versa).

     

    There are also some settings to play with.

    MT_BG    = 0x000000 -- In-game Time (MT) mode background color.
    MT_FG    = 0xFFFFFF -- MT mode foreground color.
    DAY      = 0xFFFF00 -- "Day"       |
    EVENING  = 0x202080 -- "Evening"   | String
    NIGHT    = 0x000080 -- "Night"     | colors
    MORNING  = 0x404000 -- "Morning"   |
    RT_BG    = 0x000000 -- Real-life Time (RT) Mode background color.
    RT_FG    = 0xFFFFFF -- RT mode foreground color.
    TIMEZONE = 0        -- Set TZ to make program display your local time.
                        -- Example values: -6, 2.5, 12.
    CORRECT  = 0        -- Some TZ correction. Needs if host TZ is not UTC, or time gets messed up again.
    W, H     = 40, 8    -- Width and height of screen in "pixels".
    REDSTONE = false    -- Enable/disable redstone mode switching behaviour.
    TOUCH    = true     -- Same as this (↑). But for screen touching.
    KEY1     = 13       -- Make program stop when key pressed ([Enter] by default).
    KEY2     = 28       -- ↑
    SHOWSECS = true     -- Shows seconds in RT mode if value is true.
    AUTOMODE = true     -- Controls which mode will be chosen on program start.
                        -- MT = true
                        -- RT = false
    SWDATEMT = true     -- Shows date line in MT mode if value is true.
    SWDATERT = true     -- Shows date line in RT mode if value is true.
    SWDTMMT  = true     -- Shows time of day line in MT mode if value is true.
    SWDTMRT  = true     -- Same as this (↑). But for RT mode.
    
  12. Thank you for pointing that out! I ah, didn't quite think to do that. Bah. But aside from that, I've come into a new problem. When I start the program now, just as you have it above, it updates it just once, showing it as it is the first time it checks it, and then loops again, but doesn't update the values of the RPM and others. I even checked by increasing and decreasing the RPM to confirm it. That is a bit of a crucial part of the monitoring, so I would like to know what is wrong if anything is. Again, thank you in advanced!

    To keep values updating, you need to move this part into a loop. There's a code:

    local term = require("term")
    local component = require("component")
    
    local turbine = component.br_turbine
    local tRPM, tRf, tRfPt                -- Not to spam with 'local' in a loop
    
    
    while true do
      if turbine.getActive() then              -- If turbine IS active, then get and print out info...
        tRPM = math.ceil(tonumber(turbine.getRotorSpeed()))               --   Get
        tRf = math.ceil(tonumber(turbine.getEnergyStored()))              -- turbine
        tRfPt = math.ceil(tonumber(turbine.getEnergyProducedLastTick()))  --  info
    
        term.clear()
        print(tRPM .. " RPM")
        print(tRf .. " RF Stored")
        print(tRfPt .. " RF/t")
        os.sleep(1)
      else              -- If not, then
        os.sleep(0.25)  -- sleep for 0.25 seconds
      end
    end
    
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.