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

Help with code (Is most likely awful but constructive criticism would help)

Started by TheGuy, 21 May 2017 - 08:02 PM
TheGuy #1
Posted 21 May 2017 - 10:02 PM
I'm trying to create a turtle clerk or salesman who sells items, mainly tools and sword but i cannot entirely figure out what to do, at all… The following code is all I've got so far but please keep in mind that i am new ad that it is very weak. Any help or alterations would very much be appreciated.

-- All diamond items = 50$ each
-- All Gold items = 35$ each
-- All iron items = 20% each
-- All cobblestone items = 15$ each
-- All wooden items- = 5$ each

-- Welcome, the following will be my submission for term 3, and I veru much ope that it works...

B == "minecraft:diamond"
C == "minecraft:gold_ingot"
D == "minecraft:iron_ingot"

-- The above shall be the only legitamate means to purchase the items of yourchosing and below, i will showhow much each one is worth.

local B = 50
local C = 35
local D = 15

-- Now, i will begin with the code which will permit the user to give an currency to the turtle and receive an item back.

local function Diamond_process()
	-- in this function, you will be permitted to purchase any of the diamond items, for they are all worth the same...
	-- Slot 5 will be where people would insert their cash, etc.
	
	turtle.select(5)
	turtle.getSelectedSlot()
	
	if turtle.getItemSpace([5]) = local B then
		turtle.say( "Ah, you have exact change... are you sure that this is the item that you'd like?")
		turtle.select(1)
		turtle.drop()
	elseif
		turtle.say( "sorry pal, but it seems like you don't have a sufficient amount of funds." )
	end
end

-- Next, i'm hoping to repeat the same process but with Gold, and Iron ingots.
local function Gold_process()
	turtle.getSelectedSlot(5)

	if turtle.getItemSpace([5]) = local C then
		turtle.say( "Ah, you have exact change... are you sure that this is te item that you' like?" )
		turtle.select(2)
		turtle.drop()
	elseif
		turtle.say( "I apologize to be the bearer of bad news but it seems like you do not have the sufficient amount of funds to purchase this item" )
	end
end

-- And now, last but not least, Iron...
local function Iron_process()
	turtle.getSelectedSlot(5)

	if turtle.getItemSpace([5]) = local D then
		turtle.say( "Ah why thank you for your patrionage, is that everything and are you sure that the selected item is in fact the one you'd like?" ) then
		turtle.select(3)
		and
		turtle.drop()
	elseif
		turtle.say( "I apologize but you do not have the correct amunt of funds for this item...." )
	end
end

Diaond_process()
Gold_process()
Iron_process()
Edited by
Bomb Bloke #2
Posted 22 May 2017 - 01:07 AM
Use = for assignments, and == for comparisons. Don't confuse "elseif" with "else", and don't use the "local" keyword unless defining a value for the first time.

You really need to review your basics; I recommend reading your way down through at least the first eight articles here. If you get stuck on fixing your code after that, quote the error you get and the content of the precise line number it references.