ecco7777

CC Search function

Apr 10th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. items={"cobble stone","grass","diamond","computer","wood","wooden planks","wooden stairs","pokemon","book","netherrack","golden gear","iron gear","wooden gear","diamond gear","golden bag of holding","iron fence","wood iron","steel leaf","steel","mana steel"}
  2. pos=1
  3. mem={}
  4. while true do
  5. event, key=os.pullEvent("key")
  6. if #keys.getName(key)==1 then
  7. mem[pos]=keys.getName(key)
  8. end
  9.  
  10. if keys.getName(key)=="backspace" then
  11. if pos>1 then
  12. mem[pos-1]=""
  13. pos=pos-1
  14. end
  15. else
  16. pos=pos+1
  17. end
  18. --term.clear()
  19. term.setCursorPos(1,1)
  20. strmem=""
  21. yPos=2
  22. for i=1,#mem do
  23. strmem=strmem..mem[i]
  24. end
  25. term.clear()
  26. term.write(strmem)
  27. for i=1,#items do
  28. if string.find(items[i],strmem) then
  29. term.setCursorPos(1,yPos)
  30. term.write(items[i])
  31. yPos=yPos+1
  32. end
  33. end
  34. end
Add Comment
Please, Sign In to add comment