KingofGamesYami 0 Posted February 4, 2015 Share Posted February 4, 2015 Alright, so I've got an extensive knowledge of CC, and recently decided to learn OC. My Profile Anyway, as I've gotten interested in OC, I've come across a few questions: 1) Is it possible to list all the various APIs and functions? In CC you can iterate through _G, but this isn't possible with OC AFAIK. 2) What sort of things that worked in CC no longer work in OC, and how can I get around this? 3) Are the pixels on the OC monitor scalable as they were in CC? I've noticed you cannot 'click' the monitor as it opens a GUI. 4) Is there a way to download programs, and if so, how? CC has the pastebin program and the http api. That's all for now, I may come up with more later. Quote Link to post Share on other sites
0 dgelessus 26 Posted February 5, 2015 Share Posted February 5, 2015 1. Unlike with CC, not all APIs are loaded by default. Instead you need to explicitly load them with require: local component = require("component") local fs = require("filesystem") For a full list of all APIs and components, see the wiki at http://ocdoc.cil.li/. 2. Practically none - CC and OC have similar components and APIs, though of course they are used differently. And if you absolutely need to use a CC peripheral that has no OC counterpart, you can use the Adapter block to control it. 3. OC monitors are character-based, so there is no way to directly control pixels as such. Scalable, yes - you can change a monitor's virtual resolution, which effectively changes the scale of all characters. Touch input is possible with tier 2+ screens, either by clicking on the GUI or by shift-clicking on the screen blocks. If there is no keyboard attached to the screen, right-clicking on the block also sends touch events rather than opening the GUI. 4. Craft an internet card - it comes with a built-in wget program to download any file from the internet, and IIRC also a pastebin program. (And the corresponding API of course.) You can also "cheat" by copying text from your browser and pasting it into the editor using middle-click. Quote Link to post Share on other sites
0 mpmxyz 27 Posted February 5, 2015 Share Posted February 5, 2015 1) Default Lua libraries are already loaded in _G. To load other libraries you have to use 'require'. You can read in the Lua 5.2 documentation how 'require' works in detail. Here is the short version: 1st: It checks the contents of 'package.loaded' to find out if the library has already been loaded. 2nd: If not, it checks the contents of 'package.preload'. Any function found is executed and it's return values are returned. 3rd: If steps 1+2 failed it uses 'package.path' to find and execute a file To find all loaded and preloaded libraries you just have to iterate the tables and remember the corresponding keys. You can use them as a parameter for 'require' to get the library. Finding libraries loaded by step 3 is a bit trickier: You have to search the file system. I've written such a function for a project of mine. (a component/library 'browser' for viewing and testing components and libraries; on my to do list for release) Here is an extract: --find libraries (loaded, preloaded and in lib directory) local filesystem = require("filesystem") --the list of all libraries (name -> loaded library) local libraries = {} --a function that loads all libraries for the given template local function addLibs(path) --extract the directory, the file prefix and the file suffix around the "?" local dir, prefix, ext = path:match("^(.-)([^/]*)%?([^/]*)$") --don't search working dir if dir and prefix and ext and dir ~= "./" and dir ~= "" then for file in filesystem.list(dir) do --don't require directories if file:sub(-1, -1) ~= "/" then local libname = file:gsub(ext.."$", ""):gsub("^"..prefix,"") local ok, lib = pcall(require, libname) libraries[libname] = lib end end end end --iterates all templates in package.path and loads all libraries for path in package.path:gmatch("[^;]+") do addLibs(path) end --add preloaded libraries for libname, loader in pairs(package.preload) do local ok, lib = pcall(require, libname) libraries[libname] = lib end --add loaded libraries for libname, library in pairs(package.loaded) do if library ~= false then libraries[libname] = library end end If you just want to find documentation, read the wiki: http://ocdoc.cil.li/ 2) Since OC uses Lua 5.2 it does not have 'setfenv' anymore. You can specify the environment when loading code but can't change it from the outside thereafter. It is still possible to change the environment from inside the affected code: Just overwrite '_ENV' or create a new local variable with the same name. 3) Yes they are. Check 'gpu.setResolution'! And you can also click them if they are Tier2 or Tier 3 and if they don't have an attached keyboard. (You have to use shift+right click if they have a keyboard.) 4) Install an Internet card. It automaticly adds the programs 'wget' and 'pastebin'. Quote Link to post Share on other sites
0 KingofGamesYami 0 Posted February 5, 2015 Author Share Posted February 5, 2015 Thanks for the help! Now, more questions: 1) What is the maximum achievable resolution? That is to say, how small can the pixels get? 2) What are the dimensions of the pixels? In CC, the pixels were roughly 1.5 * 1, allowing us to compensate when drawing things by multiplying the y by 0.66 (2/3). 3) Is there any sort of window api similar to what was introduced in CC 1.63? Is it possible to write one? Quote Link to post Share on other sites
0 Negi 6 Posted February 6, 2015 Share Posted February 6, 2015 1) The maximum resolution with a T3 card and a T3 screen is 160*50 characters. The smallest they can get depends on the actual size in blocks of your in-game screen. 2) The ratio for a character is of 1:2 afaik. But you can use half-block characters to make actual square pixels. 3) There are a few in the part of the forums made for that. And it's possible to write one. You can even use box-drawing characters for that. Quote Link to post Share on other sites
0 dgelessus 26 Posted February 6, 2015 Share Posted February 6, 2015 2) The ratio for a character is of 1:2 afaik. But you can use half-block characters to make actual square pixels. ^ this. The exact size of normal characters is 8*16 points, and double-width ones (East Asian glyphs, certain other symbols and control character replacements) are 16*16. The font used by OC computers is the GNU Unifont, see its Wikipedia article for more technical details that you'll probably never need Quote Link to post Share on other sites
Alright, so I've got an extensive knowledge of CC, and recently decided to learn OC.
My Profile
Anyway, as I've gotten interested in OC, I've come across a few questions:
1) Is it possible to list all the various APIs and functions? In CC you can iterate through _G, but this isn't possible with OC AFAIK.
2) What sort of things that worked in CC no longer work in OC, and how can I get around this?
3) Are the pixels on the OC monitor scalable as they were in CC? I've noticed you cannot 'click' the monitor as it opens a GUI.
4) Is there a way to download programs, and if so, how? CC has the pastebin program and the http api.
That's all for now, I may come up with more later.
Link to post
Share on other sites