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

Asd:42: Expected String, Number

Started by Elaniel, 29 July 2013 - 07:25 AM
Elaniel #1
Posted 29 July 2013 - 09:25 AM
Hey. I don't know what i must change to fix this error. I hope someone can help me.

Elaniel greets from Germany


local arg = { ... }
	local side = "back"
	local output = "top"
	
	items = {
			["Cobblestone"]=1,
			["Planks"]=2,
			["Dirt"]=4,
			["Sandstone"]=8,
			["Stone"]=16,
			["Brick"]=32,
			["Iron"]=64,
			["Copper"]=128,
			["Silver"]=256,
			["Gold"]=512,
			["Tin"]=1024,
			["Electrum"]=2048,
			["Lead"]=4096,
			["Ferrous"]=8192,
			["Brass"]=16384,
			["Steel"]=32768
	}
	
	function clearScreen()
			term.clear()
			term.setCursorPos(1,1)
	end
	
	function get()
			clearScreen()
			print("Was für ein Item willst du?")
			userInputItem = read()
	
			clearScreen()
			print("Menge?")
			userInputItems = read()
			userInputItems = tonumber(userInputItems)
			clearScreen()
			print("Fetching "..userInputItems.." of "..userInputItem.."...")
			i=0
			while i < userInputItems do
					rs.setBundledOutput(side, items[userInputItem])
					sleep(0.5)
					rs.setBundledOutput(side, 0)
					sleep(0.5)
					i = i + 1
			end
			clearScreen()
			print("Hole "..userInputItems.." con "..userInputItem.." ! ")
	end
	
	function send()
			clearScreen()
			print("Anzahl der Stacks?")
			amount = read()
			amount = tonumber(amount)
			x = 0
			clearScreen()
			print("Sende Items...")
			while x < amount do
					rs.setOutput(output, true)
					sleep(0.5)
					rs.setOutput(output, false)
					sleep(0.5)
					x = x + 1
			end
			clearScreen()
			print("Items gesendet!")
	end
	
	if arg[1] == "get" then
			get()
	elseif arg[1] == "send" then
			send()
	else
			clearScreen()
			print("Ungültig. Bitte benutze <get> oder <send>")
	end
Lyqyd #2
Posted 29 July 2013 - 01:02 PM
Split into new topic.
Lord_Spelunky #3
Posted 29 July 2013 - 03:06 PM
You don't have to use read() then tonumber() You can do example = tonumber(read())

I think I found it, I think you may have to do userInputItems = tonumber(userInputItems[1])
like that, because I think read is still keeping it as a string. I will try it out.
albrat #4
Posted 29 July 2013 - 07:42 PM
1 mis spelling will break the system.

The best way might be to use numberical entries.

for example change the table and get function to this….


	   items = {
						[1]=1,
						[2]=2,
						[3]=4,
						[4]=8,
						[5]=16,
						[6]=32,
						[7]=64,
						[8]=128,
						[9]=256,
						[10]=512,
						[11]=1024,
						[12]=2048,
						[13]=4096,
						[14]=8192,
						[15]=16384,
						[16]=32768
		}

		  function get()
						clearScreen()
	  term.setCursorPos(1,3)
	  print("1. Cobblestone")
	  print("2. Planks")
	  print("3. Dirt")
	  print("4. Sandstone")
	  print("5. Stone")
	  print("6. Brick")
	  -- etc ...
	
	  write("Input number of item : ") -- in german
						--print("Was für ein Item willst du?")
						userInputItem = tonumber(read())
	 if userInputItem > 0 and userInputItem < 17 then
						clearScreen()
						print("Menge?")
						userInputItems = read()
						userInputItems = tonumber(userInputItems)
						clearScreen()
						print("Fetching "..userInputItems.." of "..userInputItem.."...")
						i=0
						while i < userInputItems do
										rs.setBundledOutput(side, items[userInputItem])
										sleep(0.5)
										rs.setBundledOutput(side, 0)
										sleep(0.5)
										i = i + 1
						end
						clearScreen()
						print("Hole "..userInputItems.." con "..userInputItem.." ! ")
	 else
	  print("invalid item") -- in german
	 end
		end

My coding idea there is not complete but an idea of one way to do it.

The reason I am thinking do a list then choose the number is that if you mis-spelled a name eg.. Cobblestone / cobblestone this would error your script, but with the numbers you can filter bad entries easily. (plus you can quickly choose your items instead of typing the names.)

You would need another table with item names in it.. eg itemnames[] so you can call the names of the items. If I remember I will revisit this tomorrow as I just had another idea to make the code smaller and do the same, but it is 1.48 am here and I am prone to mistakes at this time of morning. :D/>
Edited on 29 July 2013 - 05:46 PM
albrat #5
Posted 30 July 2013 - 04:42 AM

local arg = { ... }
	    local side = "back"
	    local output = "top"
	   
	    items = {
					    [1]={"Cobblestone",1},
					    [2]={"Planks",2},
					    [3]={"Dirt",4},
					    [4]={"Sandstone",8},
					    [5]={"Stone",16},
					    [6]={"Brick",32},
					    [7]={"Iron",64},
					    [8]={"Copper",128},
					    [9]={"Silver",256},
					    [10]={"Gold",512},
					    [11]={"Tin",1024},
					    [12]={"Electrum",2048},
					    [13]={"Lead",4096},
					    [14]={"Ferrous",8192},
					    [15]={"Brass",16384},
					    [16]={"Steel",32768}
	    }
	   
	    function clearScreen()
					    term.clear()
					    term.setCursorPos(1,1)
	    end
	   
	    function get()
					    clearScreen()
	  for i = 1, #items do  -- loop for table items
	    print(tostring(i) .. ". " .. tostring(items[i][1])) -- Print items list
	  end
					    print("Was für ein Item willst du (1-16)?")
					    userInputItem = tonumber(read()) -- gather a number
	 
	 if userInputItem > 0 and userInputItem < 17 then -- is our number inside the limits of 1 and 16.
					    clearScreen()
					    print("Menge?")
					    userInputItems = read()
					    userInputItems = tonumber(userInputItems)
					    clearScreen()
					    print("Fetching "..userInputItems.." of "..tostring(items[userInputItem][1]).."...") -- print sub table items 1 which is our names.
					    i=0
					    while i < userInputItems do
									    rs.setBundledOutput(side, items[userInputItem][2])  -- call sub table 2 which is our numbers.
									    sleep(0.5)
									    rs.setBundledOutput(side, 0)
									    sleep(0.5)
									    i = i + 1
					    end
					    clearScreen()
					    print("Hole "..userInputItems.." con "..userInputItem.." ! ")
	 else
	   print("Not a number") -- Translate to german. :D/>
	 end
	    end
	   
	    function send()
					    clearScreen()
					    print("Anzahl der Stacks?")
					    amount = read()
					    amount = tonumber(amount)
					    x = 0
					    clearScreen()
					    print("Sende Items...")
					    while x < amount do
									    rs.setOutput(output, true)
									    sleep(0.5)
									    rs.setOutput(output, false)
									    sleep(0.5)
									    x = x + 1
					    end
					    clearScreen()
					    print("Items gesendet!")
	    end
	   
	    if arg[1] == "get" then
					    get()
	    elseif arg[1] == "send" then
					    send()
	    else
					    clearScreen()
					    print("Ungültig. Bitte benutze <get> oder <send>")
	    end

hopefully this code will work better…
some print statements may need translation to german. :)/> (I myself do not know german :(/> )
jesusthekiller #6
Posted 30 July 2013 - 06:00 AM
Next time for "items" table do

local items = {}
for i=0,15 do
  items[i+1] = 2^i
end
It will be much faster :)/>


Second file from the end - you have umlaut (ü) which can not be displayed by CC. CC terminal supports only standard ASCII chars excluding grave key (code 9, 10, 32 - 95, 97 - 126)