Database Upgrade: Difference between revisions
imported>OCDoc Import Imported from legacy OpenComputers documentation at ocdoc.cil.li |
Unify block and component API pages |
||
| Line 1: | Line 1: | ||
= | = Overview = | ||
[[File:upgradedatabase0.png|128px]][[File:upgradedatabase1.png|128px]][[File:upgradedatabase2.png|128px]] | [[File:upgradedatabase0.png|128px]][[File:upgradedatabase1.png|128px]][[File:upgradedatabase2.png|128px]] | ||
Provides the | Provides the <code>database</code> component. | ||
This upgrade can be used to store item stack information. It can be configured by open its GUI by right clicking holding it in your hand and placing items in it (no actual items are stored in the item, clicking with an item in the grid will store a "ghost" stack). Alternatively, a few components allow configuring the database programmatically, such as the [[Item/inventory controller upgrade|Inventory Controller Upgrade]] and the [[Block/geolyzer|Geolyzer]]. | This upgrade can be used to store item stack information. It can be configured by open its GUI by right clicking holding it in your hand and placing items in it (no actual items are stored in the item, clicking with an item in the grid will store a "ghost" stack). Alternatively, a few components allow configuring the database programmatically, such as the [[Item/inventory controller upgrade|Inventory Controller Upgrade]] and the [[Block/geolyzer|Geolyzer]]. | ||
| Line 37: | Line 37: | ||
[[File:t3database.png|200px]] | [[File:t3database.png|200px]] | ||
== Contents | = Component API = | ||
Component name: <code>database</code>. | |||
{{APICallback|name=get|signature=(slot:number):table|description= | |||
Get the representation of the item stack stored in the specified slot. | |||
}} | |||
{{APICallback|name=computeHash|signature=(slot:number):string|description= | |||
Computes a hash value for the item stack in the specified slot. This value is guaranteed to be the same for identical item stacks, allowing comparison of item stacks across a network (by comparing the hash values). | |||
}} | |||
{{APICallback|name=indexOf|signature=(hash:string):number|description= | |||
Get the index of an item stack with the specified hash. Returns a negative value if no such stack was found. | |||
}} | |||
{{APICallback|name=clear|signature=(slot:number):boolean|description= | |||
Clears the specified slot. Returns true if there was something in the slot before. | |||
}} | |||
{{APICallback|name=copy|signature=(fromSlot:number, toSlot:number[, address:string]):boolean|description= | |||
Copies an entry to another slot, optionally to another database. Returns true if something was overwritten. | |||
}} | |||
{{APICallback|name=clone|signature=(address:string):number|description= | |||
Copies the data stored in this database to another database with the specified address. | |||
}} | |||
= Example = | |||
<syntaxhighlight lang="lua"> | |||
local component = require("component") | |||
local sides = require("sides") | |||
local db = component.database -- primary database component | |||
local invcontrol = component.inventory_controller -- primary inventory controller | |||
-- define slot numbers | |||
dbSlot = 1 invSlot = 1 | |||
-- compare item inside remote inventory to item in first slot of database | |||
if db.get(dbSlot).label == invcontrol.getStackInSlot(sides.north, invSlot).label then | |||
-- items match, do stuff with it. | |||
else | |||
-- items don't match, do nothing, or do something else. | |||
end | |||
</syntaxhighlight> | |||
= Contents = | |||
{{:Item/contents}} | {{:Item/contents}} | ||
Revision as of 20:33, 28 August 2026
Overview
Provides the database component.
This upgrade can be used to store item stack information. It can be configured by open its GUI by right clicking holding it in your hand and placing items in it (no actual items are stored in the item, clicking with an item in the grid will store a "ghost" stack). Alternatively, a few components allow configuring the database programmatically, such as the Inventory Controller Upgrade and the Geolyzer.
The Database Upgrade (Tier 1) is crafted using the following recipe:
- 4 x Iron Ingot
- 2 x Microchip (Tier 1)
- 1 x Hard Disk Drive (Tier 1)
- 1 x Analyzer
- 1 x Printed Circuit Board
The Database Upgrade (Tier 2) is crafted using the following recipe:
- 4 x Iron Ingot
- 2 x Microchip (Tier 2)
- 1 x Hard Disk Drive (Tier 2)
- 1 x Analyzer
- 1 x Printed Circuit Board
The Database Upgrade (Tier 3) is crafted using the following recipe:
- 4 x Iron Ingot
- 2 x Microchip (Tier 3)
- 1 x Hard Disk Drive (Tier 3)
- 1 x Analyzer
- 1 x Printed Circuit Board
Component API
Component name: database.
get
get(slot:number):table
Get the representation of the item stack stored in the specified slot.
computeHash
computeHash(slot:number):string
Computes a hash value for the item stack in the specified slot. This value is guaranteed to be the same for identical item stacks, allowing comparison of item stacks across a network (by comparing the hash values).
indexOf
indexOf(hash:string):number
Get the index of an item stack with the specified hash. Returns a negative value if no such stack was found.
clear
clear(slot:number):boolean
Clears the specified slot. Returns true if there was something in the slot before.
copy
copy(fromSlot:number, toSlot:number[, address:string]):boolean
Copies an entry to another slot, optionally to another database. Returns true if something was overwritten.
clone
clone(address:string):number
Copies the data stored in this database to another database with the specified address.
Example
local component = require("component")
local sides = require("sides")
local db = component.database -- primary database component
local invcontrol = component.inventory_controller -- primary inventory controller
-- define slot numbers
dbSlot = 1 invSlot = 1
-- compare item inside remote inventory to item in first slot of database
if db.get(dbSlot).label == invcontrol.getStackInSlot(sides.north, invSlot).label then
-- items match, do stuff with it.
else
-- items don't match, do nothing, or do something else.
endContents
| Items | |
|---|---|
| Components | Data Card - Debug Card - Graphics Card - Internet Card - Linked Card - Network Card - Redstone Card - Wireless Network Card |
| Storage Devices | Floppy Disk - EEPROM - Hard Disk Drive - Memory |
| Upgrades | Angel Upgrade - Battery Upgrade - Chunkloader Upgrade - Database Upgrade - Experience Upgrade - Generator Upgrade - Hover Upgrade - Inventory Controller Upgrade - Inventory Upgrade - Leash Upgrade - Navigation Upgrade - Piston Upgrade - Sign I/O Upgrade - Solar Generator Upgrade - Tank Upgrade - Tank Controller Upgrade - Tractor Beam Upgrade - World Sensor Upgrade |
| Containers | Card Container - Upgrade Container - Disk Drive |
| Others | Analyzer - Texture Picker - Component Bus - CPU - APU - Drone Case - Manual - Microcontroller Case - Nanomachines - Remote Terminal - Terminal Server - Server - Tablet Case - Tablet - Crafting Materials - Ink Cartridge - Scrench - Hover Boots - Grog - Loot Disks |


