This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TylerTharp's profile picture

Economy Item Price Billboard?

Started by TylerTharp, 22 July 2013 - 10:37 PM
TylerTharp #1
Posted 23 July 2013 - 12:37 AM
I have attempted to make a billboard that can be used to display prices for items I am selling on a big monitor billboard, but I failed. I wanted the format to be something like this "Diamond - (price(for x amount)) - (availability)" but like I said, I failed. I also wanted it to have some sort of GUI that I could use to edit the info without messing with the code. I really need some help with this project, can anyone help me out?
Grim Reaper #2
Posted 23 July 2013 - 12:39 AM
We all could help you out, but what exactly do you need help with? We're not really here to write your code for you, just to steer you in the right direction and answer semi-specific to specific questions if you have them :)/>

You could probably start by writing a file that contains all of the data you want to display. If you want to have the item quantities / prices adjusted automatically, you might have to invest in some turtles and chests so that you can interface with the chests.
TylerTharp #3
Posted 23 July 2013 - 12:42 AM
Well, I did have the code because I deleted it. I am sure I could rewrite it. What I really needed help with originally was making a GUI to edit the info. I have no clue where to start with a GUI.
Grim Reaper #4
Posted 23 July 2013 - 12:49 AM
Essentially, a GUI is just a bunch of characters written to the screen with various colors :)/> If you know how to change the text and background colors of the screen and know how to write text to the screen at different places, then you shouldn't have a problem with GUIs ;)/>

You could start by thinking about what your GUI is going to look like, then abstracting various drawing ideas into functions which can be used repeatedly to draw the GUI that you want to the screen after every update (it sounds like you want to be able to enter info using the GUI).
TylerTharp #5
Posted 23 July 2013 - 01:06 AM
Okay, I have everything I need for a basic sign finished. I just need help with being able to edit the info without messing with the code.

Here is what I have so far

term.clear()
term.setCursorPos(1,1)
term.setTextColor(8192)
print("Displaying info...")
mon = peripheral.wrap("back")
mon.setTextColor(colors.yellow)
mon.setBackgroundColor(colors.black)
strtpos = 12
prices = "Prices"
-- Prices start
item1 = "(items and prices)"
item2 = "(items and prices)"
item3 = "(items and prices)"
item4 = "(items and prices)"
-- Prices end
while true do
mon.clear()
  mon.setCursorPos(1, 1)
mon.write(prices)
  mon.setCursorPos(1, 2)
mon.write(item1)
  mon.setCursorPos(1, 3)
mon.write(item2)
  mon.setCursorPos(1, 4)
mon.write(item3)
  mon.setCursorPos(1, 5)
mon.write(item4)
end
Grim Reaper #6
Posted 23 July 2013 - 01:32 AM
You could throw all of your prices into a table:


local monitor = peripheral.wrap ("back")

monitor.setTextColor (colors.yellow)
monitor.setBackgroundColor (colors.black)

local prices = {
    item1 = { price = 0, quantity = 0 },
    item2 = { price = 0, quantity = 0 },
    item3 = { price = 0, quantity = 0 }
}

local function writePrices (prices)
    monitor.clear()

    local lineNumber = 1
    for itemName, itemData in pairs (prices) do
        monitor.setCursorPos (1, lineNumber)
        monitor.write (itemName .. " : $" .. itemData.price .. " each | Quantity: " .. itemData.quantity)

        lineNumber = lineNumber + 1
    end
end

print ("Displaying info...")
writePrices()

You could also set up the information in a file like:


item1:price=0|quantity=0
item2:price=0|quantity=0
item3:price=0|quantity=0

Then read them like this:


local monitor          = peripheral.wrap ("back")
local itemInfoFilePath = "/itemInfo"

monitor.setTextColor (colors.yellow)
monitor.setBackgroundColor (colors.black)

local prices = {}

local function getItemInfo (itemInfoFilePath)
    local itemInfoFileHandle = io.open (itemInfoFilePath)
    local prices             = {}

    if itemInfoFileHandle then
        for itemData in itemInfoFileHandle:lines() do
            local itemName, itemPrice, itemQuantity = itemData:match ("(.-):.-(%d+)|.-(%d+)")

            prices[itemName] = { price = itemPrice, quantity = itemQuantity }
        end
    else
        error ("Item info file path was invalid.")
    end

    return prices
end

local function writePrices (prices)
    monitor.clear()

    local lineNumber = 1
    for itemName, itemData in pairs (prices) do
        monitor.setCursorPos (1, lineNumber)
        monitor.write (itemName .. " : $" .. itemData.price .. " each | Quantity: " .. itemData.quantity)

        lineNumber = lineNumber + 1
    end
end

prices = getItemInfo (itemInfoFilePath)

print ("Displaying info...")
writePrices()