Posted 03 April 2015 - 09:21 PM
Hi everyone!
First let me explain my rough idea for the interface. The player walks up to the monitor and it has text detailing how the shop works. After reading the initial page it prompts the user to select the "armour shop" to begin making purchases. Once the user selects the shop they are given a $100 balance in the top right corner and given three options to spend their $$$. One option is "Diamond armour $75", another is "Iron Armour $50" and lastly "Leather Armour $25". Lets say the user chose to purchase the diamond armour, the monitor would now send the player to the next shop and display $25 as the balance. In this shop the user has 4 options, "Normal bow $25", "power bow $30", "knock back bow $30", and "Here". The here button allows the player to opt out of purchasing a bow and to move to the next shop. This is where I need help. If the player chose not to make a purchase here how can I make the computer record what option was purchased in the armour menu and display the correct balance.
Any help is appreciated and I am open to any criticism for I want to learn how to code!
Here is the code I have written:
(Note this is my first ever attempt at coding I'm sure it shows!)
First let me explain my rough idea for the interface. The player walks up to the monitor and it has text detailing how the shop works. After reading the initial page it prompts the user to select the "armour shop" to begin making purchases. Once the user selects the shop they are given a $100 balance in the top right corner and given three options to spend their $$$. One option is "Diamond armour $75", another is "Iron Armour $50" and lastly "Leather Armour $25". Lets say the user chose to purchase the diamond armour, the monitor would now send the player to the next shop and display $25 as the balance. In this shop the user has 4 options, "Normal bow $25", "power bow $30", "knock back bow $30", and "Here". The here button allows the player to opt out of purchasing a bow and to move to the next shop. This is where I need help. If the player chose not to make a purchase here how can I make the computer record what option was purchased in the armour menu and display the correct balance.
Any help is appreciated and I am open to any criticism for I want to learn how to code!
Here is the code I have written:
(Note this is my first ever attempt at coding I'm sure it shows!)
local mon = peripheral.wrap("right")
local bal = 100
function touchScreen()
event, side, xPos, yPos = os.pullEvent("monitor_touch")
print(event .. " => Side: " .. tostring(side) .. ", " ..
"X: " .. tostring(xPos) .. ", " ..
"Y: " .. tostring(yPos))
end
function compVersion()
mon.clear()
mon.setCursorPos(2,1)
mon.setTextColor(colors.yellow)
mon.write("Prep Computer v1.43")
end
function balance()
mon.setCursorPos(54,3)
mon.setTextColor(colors.green)
end
function bowMenu()
mon.setCursorPos(25,6)
mon.setTextColor(colors.red)
mon.write("Marksman Shop")
mon.setTextColor(colors.blue)
mon.setCursorPos(22,8)
mon.write("Select your bow")
mon.setCursorPos(15,9)
mon.write("Your bow will come with 16 arrows")
mon.setCursorPos(15,10)
mon.write("Not intrested in a bow? Click")
mon.setBackgroundColor(colors.green)
mon.setCursorPos(44,10)
mon.write("[Here]")
mon.setBackgroundColor(colors.black)
mon.setCursorPos(3,18)
mon.setBackgroundColor(colors.green)
mon.write("[Normal Bow $25]")
mon.setBackgroundColor(colors.black)
mon.setCursorPos(20,18)
mon.setBackgroundColor(colors.green)
mon.write("[Power 1 Bow $30]")
mon.setBackgroundColor(colors.black)
mon.setCursorPos(38,18)
mon.setBackgroundColor(colors.green)
mon.write("[Knock Back Bow $30]")
mon.setBackgroundColor(colors.black)
end
function bowButtons()
while true do
touchScreen()
--Here Button
if (xPos > 43 and xPos < 51) and (yPos > 9 and yPos < 11) then
compVersion()
balance()
mon.write("$" .. tostring(bal))
--Normal Bow Button
elseif (xPos > 2 and xPos < 19) and (yPos > 17 and yPos < 19) then
compVersion()
--Power Bow Button
elseif (xPos > 20 and xPos < 37) and (yPos > 17 and yPos < 19) then
compVersion()
--Knock Back Bow Button
elseif (xPos > 37 and xPos < 51) and (yPos > 17 and yPos < 19) then
compVersion()
end
end
end
--I have no idea what im doing but its WORKING KINDA
--Main Program
compVersion()
mon.setCursorPos(21,6)
mon.setTextColor(colors.red)
mon.write("Welcome to the shop!")
mon.setCursorPos(13,8)
mon.setTextColor(colors.blue)
mon.write("You're given $100 dollars use it wisely")
mon.setCursorPos(13,9)
mon.write("Your balance is in the top right corner")
mon.setCursorPos(13,11)
mon.write("Items you purchase will fall from the sky")
balance()
mon.write("$" .. tostring(bal))
mon.setTextColor(colors.blue)
mon.setCursorPos(18,12)
mon.write("Let's start with some armour!")
mon.setCursorPos(18,10)
mon.write("Note items are non refundable")
mon.setCursorPos(28,18)
mon.setBackgroundColor(colors.green)
mon.write("[Armour]")
mon.setBackgroundColor(colors.black)
while true do
touchScreen()
if (xPos > 27 and xPos < 37) and (yPos > 17 and yPos < 19) then
compVersion()
balance()
mon.write("$" .. tostring(bal))
mon.setTextColor(colors.red)
mon.setCursorPos(27,6)
mon.write("Armour Shop")
mon.setTextColor(colors.blue)
mon.setCursorPos(24,9)
mon.write("Select your armour:")
mon.setCursorPos(2,18)
mon.setBackgroundColor(colors.green)
mon.write("[Diamond Armour $75]")
mon.setBackgroundColor(colors.black)
mon.setBackgroundColor(colors.green)
mon.setCursorPos(23,18)
mon.write("[Iron Armour $50]")
mon.setBackgroundColor(colors.black)
mon.setBackgroundColor(colors.green)
mon.setCursorPos(41,18)
mon.write("[Leather Armour $25]")
mon.setBackgroundColor(colors.black)
while true do
touchScreen()
if (xPos > 2 and xPos < 22) and (yPos > 17 and yPos < 19) then
compVersion()
balance()
mon.write("$" .. tostring(bal-75))
bowMenu()
bowButtons()
elseif (xPos > 23 and xPos < 40) and (yPos > 17 and yPos <19) then
compVersion()
balance()
mon.write("$" .. tostring(bal-50))
bowMenu()
bowButtons()
elseif (xPos > 41 and xPos < 61) and (yPos > 17 and yPos < 19) then
compVersion()
balance()
mon.write("$" .. tostring(bal-25))
bowMenu()
bowButtons()
end
end
end
end