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

dgelessus

Members
  • Content Count

    158
  • Joined

  • Last visited

  • Days Won

    17

Posts posted by dgelessus

  1. 5. Okay, i dont have anything knowledge about programming... 

    That explains the "Windows would be better". ;) Trust me, if you program on Windows long enough, you'll find that it's terrible for programming. Okay, that's true for *every* system that you work with long enough, but Windows is worse than most Unix-based systems. I'm talking about the underlying operating system, not the user interface. A "good UI" is very subjective. ;)

  2. You can use component.gpu.setResolution to reduce the resolution, which (like most real monitors nowadays) means that the text is upscaled and looks larger. This only affects the text size on the screen block in the world, in the right-click GUI for the screen it will just make the "window" smaller. You might also want to use more than one monitor block - for the default resolution I find a 3*2 screen works well.

    • The first line doesn't do what you think. All it does is assign the string "component.redstone" to the variable c. If you want to use the redstone component, you first have to load the component library using local component = require("component"). You'll also want to load the sides library the same way, because you later need to say what side to read the signal from.

    The third line is what's causing your error. On the wiki, functions are written like getInput(side: number): number. This means that the function takes one argument of type number and returns a number. However this is not normal Lua syntax, so you cannot just copy over the function from the wiki. In your case, you'll want to call the function like local signal = component.redstone.getInput(sides.back). This calls the redstone component's function getInput and gives it the argument sides.back. We've loaded the sides library before, and sides.back is actually a number that stands for a side. The function returns the redstone signal strengh as a number, which we store in the variable signal. (If you don't assign the return value to a variable, it is "thrown away" and you cannot use it later.)

    Lua is case-sensitive. If is not the same as if. if is a keyword for the if statement (which is what you want here). If is a normal variable name like any other.

    = is the assignment operator, used to store something in a variable. To check if two things are equal, you need to use the equality operator ==. One equals is for storing things, two equals is for comparing them.

    Unlike in some languages, in Lua the string "0" is not the same as the number 0. So if you want to check if a number is zero, you need to write if signal == 0 then etc.

  3. @Elsys656 That's not how Lua works. Whether or not you have a local before the function name doesn't matter - you're passing the function value to event.listen, not its name. Theoretically you could even do eventhandler = nil afterwards and the code would still work, as the function is not actually deleted.

     

    In fact in Lua you almost never want to make a variable not local, because then it will land in the global namespace shared by all libraries and programs (the shell might do additional sandboxing, but you shouldn't rely on that).

     

    I'm also quite sure that your unreg command won't work like this either. Every time your program is run, a new function value is created and assigned to the name eventhandler, which is different from every other function that you previously created and passed to event.listen. When you pass your new function to event.ignore, no matching listener will be found and nothing will be unregistered.

  4. There are countless GUI systems that you can find on the forums, but as far as I can tell none of them are widely used. The best solution for GUIs at the moment is probably to write everything you need yourself based on the standard OpenOS libraries.

     

    How would you create text files using print? To create text files by hand you can use the edit program from the shell, and to create files from Lua code you should use the io library.

  5. OC has no real threading or background processes. This means that even "background" listeners only run when you (indirectly) tell them to. In an empty loop like while true do end nothing happens at all, and at some point OC kills the program because it ran too long without checking for events. Event handling happens in the event.pull function - when you call it, it waits for the next event to happen, then calls any listener functions for that event and returns the event name and data. You can also set a filter so that only specific events are caught and returned by event.pull (listeners are still called for all events). For example, this loop will run forever until you press Ctrl+C (which fires an "interrupted" event):

    local event = require("event")
    
    while event.pull(nil, "interrupted") == nil do
        
    end
    

    The first argument to event.pull is the timeout. I'm not sure if a nil timeout actually means "wait forever" or defaults to something like 60 seconds, so just in case I put it in a loop that runs as long as no "interrupted" event was received (i. e. event.pull returned nil). Because event.pull is called, event listeners will still be called while the loop is running.

  6. OC computers don't have any operating system preinstalled, not even a BIOS. To get started, you need to craft the Lua BIOS (not just an empty EEPROM chip) and an OpenOS boot disk. The BIOS chip goes into the computer, and the floppy into an attached floppy drive. Now you should be able to start the computer.

    Once you're at the OpenOS shell, you can run the command "install" to install OpenOS onto the hard disk, that way you can boot without a floppy and you can write into the system directories.

  7. Not really. Lua uses 64-bit signed integers as long as possible (unless you force floating-point numbers by writing 4265.0 instead of 4265) and switches to double-precision floats for anything outside of that range. And if you exceed that range, then you get float infinity.

     

    If you're doing cryptography, you might want to look at the Data Card though. If I remember correctly the higher tiers provide some cryptographic functions too.

  8. You could set up your router to make your RPi's "garden temperature service" port available over the internet, then you don't have to worry about modifying the blacklist. And you can get your garden temperature from any computer running on any server, not just from one in your LAN. Of course you'll have to live with the danger of people gaining access to highly personal information like the temperature in your garden. :P

     

    As for how to implement it on the RPi side, you'd probably have some kind of Python HTTP server running, which would return the garden temperature on the URL http://weathermaster.example.net/garden/temp or something. Then you could easily query that using a simple HTTP request.

  9. That's not possible very easily. The font used by OpenComputers is the GNU Unifont, which is a raster font (each character is 8*16 or 16*16 pixels) instead of a vector font like most fonts, including the DejaVu ones (where characters are multiple lines and curves which can be displayed at any size). I'm also not sure how exactly OC's internal font data file looks and how you would convert a TrueType font to that format.

  10. If OpenOS require is anything like standard Lua's, then you can force a reload for all future `require` calls by `table.remove`-ing the first entry in `package.loaders`. That is the one that queries `package.loaded`.

    That's a bad idea, there probably is some code that relies on require not reloading every module every time. It's safer to remove the modules that you want to reload from package.loaded instead.

  11. External libraries/packages are loaded using the require function, for example require("myAPI") loads the file myAPI.lua. To find libraries, require looks through a few different folders and uses the first file it finds. Your own libraries should go under /usr/lib, OpenOS's own libraries are under /lib, and a few libraries (like math or computer) are provided by Lua or the mod and are loaded "by magic".

     

    To write a library that can be loaded using require, it's important that you return something from your library (usually a table). The return value of the library is what require passes back to your main program. For example, your library might look like this:

    local mylib = {}
    
    function mylib.foo()
    	-- do something
    end
    
    function mylib.bar(a, b, c)
    	-- do something else
    end
    
    return mylib
    

    If you save this file as /usr/lib/mylib.lua, you can load it from another script like this:

    local mylib = require("mylib")
    

    And then you can use the functions foo and bar that your library placed into the mylib table.

  12. In Lua, strings are just bytes. There is no distinction between text and raw data (like in Java or Python), instead all characters represent their ASCII byte value. (Well, Lua makes no promises about which character set is actually used, but in almost all cases it's ASCII or a superset of it, like Latin-1.) Unicode characters are represented by UTF-8 byte sequences, there is no native Unicode support in Lua, except for the utf8 library that provides a few utilities for encoding and decoding UTF-8 strings.

×
×
  • Create New...

Important Information

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