12 posts
Location
Germany
Posted 20 March 2012 - 03:34 PM
Hey guys,
I worte my own door lock, but it always stops before it reachs its end.
My sc:
Spoiler
user = "rUM1"
pass = "aBq47B"
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# !!Attention!! #"
print "# !You are going to open the reactor gate! #"
print "# !!Attention!! #"
print "# continue(Y/N): #"
print "#################################################"
term.setCursorPos(18, 6)
input = read()
if input == "y" then
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# !!Attention!! #"
print "# Loading... #"
print "# !!Attention!! #"
print "# #"
print "#################################################"
sleep(1)
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# Login #"
print "# User: #"
print "# Password: #"
print "# #"
print "#################################################"
term.setCursorPos(23, 4)
--[[HERE]]
function loginuser()
useri = read()
if useri == user then
return loginpass()
else
return loginuser()
end
end
function loginpass()
passi = read()
if passi == pass then
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# Checking.. #"
print "# #"
print "# Pleas wait.. #"
print "# #"
print "#################################################"
sleep(1.5)
else
return loginuser()
end
end
if useri == user and passi == pass then
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# Login sucessful! #"
print "# #"
print "# !!Opening gate!! #"
print "# #"
print "#################################################"
--[[sleep(3)
dofile("redset", back white true))]]
end
end
Everytime it stops at –[[here]] (<- this is not included in the source).
Someone knows where the problem is? I cant find it..
If necessary feel free to ask for more information.
411 posts
Posted 20 March 2012 - 03:40 PM
You never call your functions.
try putting loginuser() at that "here"
12 posts
Location
Germany
Posted 20 March 2012 - 03:56 PM
Now it says:
Attempt to call nil
source:
loginuser()
function loginuser()
local user = "rUM1"
term.setCursorPos(23, 4)
useri = read()
if useri == user then
return loginpass()
else
return loginuser()
end
end
411 posts
Posted 20 March 2012 - 04:05 PM
Sorry, i forgot to say move your functions to the top of your code. You can only call them after the've been defined.
12 posts
Location
Germany
Posted 20 March 2012 - 04:10 PM
Hm.. I got it to work due to a different method:
Spoiler
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# !!Attention!! #"
print "# !You are going to open the reactor gate! #"
print "# !!Attention!! #"
print "# continue(Y/N): #"
print "#################################################"
term.setCursorPos(18, 6)
input = read()
if input == "y" then
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# !!Attention!! #"
print "# Loading... #"
print "# !!Attention!! #"
print "# #"
print "#################################################"
sleep(1)
term.clear()
term.setCursorPos(1, 1)
repeat
term.clear()
term.setCursorPos(1, 1)
local user = "rUM1"
local pass = "aBq47B"
print "#################################################"
print "# #"
print "# Login #"
print "# User: #"
print "# Password: #"
print "# #"
print "#################################################"
term.setCursorPos(22, 4)
useri = read()
term.setCursorPos(22, 5)
passi = read()
until useri == user and passi == pass
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# Checking.. #"
print "# #"
print "# Pleas wait.. #"
print "# #"
print "#################################################"
open()
function open()
term.clear()
term.setCursorPos(1, 1)
print "#################################################"
print "# #"
print "# Login sucessful! #"
print "# #"
print "# !!Opening gate!! #"
print "# #"
print "#################################################"
--[[sleep(3)
dofile("redset", back white true))]]
end
end
As you said I have to predefine the functions: Why does the last function work then? :D/>/>
Ok.. Solved this.
But next question:
How do I call another script? I tried:
dofile("redset", back white true))]]
How to depower a bundled cable?
Edited on 20 March 2012 - 03:35 PM
715 posts
Posted 20 March 2012 - 05:09 PM
How to depower a bundled cable?
Set it to 0.
12 posts
Location
Germany
Posted 20 March 2012 - 06:06 PM
c = colors.combine( colors.white )
rs.setBundledOutput( "back", c, 1 )
sleep(2)
rs.setBundledOutput( "back", c, 0 )
what is wrong?
473 posts
Location
Poland
Posted 20 March 2012 - 06:11 PM
c = colors.combine( colors.white )
rs.setBundledOutput( "back", c)
sleep(2)
rs.setBundledOutput( "back", 0)
12 posts
Location
Germany
Posted 20 March 2012 - 06:25 PM
But this would turn all outputs off, wouldnt it?
473 posts
Location
Poland
Posted 20 March 2012 - 06:41 PM
then make it
bundle=rs.getBundledOutput("back")
c = colors.combine(bundle, colors.white )
rs.setBundledOutput( "back", c)
sleep(2)
c=colors.subtract(c, colors.white)
rs.setBundledOutput( "back", c)
12 posts
Location
Germany
Posted 20 March 2012 - 08:05 PM
Could you or someone else pleas explain this code snippet, because im not sure how it works?
473 posts
Location
Poland
Posted 20 March 2012 - 08:10 PM
bundle=rs.getBundledOutput("back") --get all the output colors and save to a var
c = colors.combine(bundle, colors.white ) --add white to said colors
rs.setBundledOutput( "back", c) --set output to include white
sleep(2) --well, sleep
c=colors.subtract(c, colors.white) --remove white from the var
rs.setBundledOutput( "back", c) --set the output to the var from line above
12 posts
Location
Germany
Posted 20 March 2012 - 08:26 PM
Thx! :)/>/> This helps me alot!
//edit²:
Next question:
I want to get a global var from the readline(= userinput?). What is the best way?
(Should I make a new topic for every question? :D/>/> )
715 posts
Posted 20 March 2012 - 09:08 PM
The global table holding all global variables is _G
Then entering e.g. "_VERSION" as an input into this program…
local input = read()
if _G[ input ] then
local output = tostring( _G[ input ] )
print( output )
end
… should yield this output:
Luaj 0.0
EDIT: Changed the example to make testing it easier. ^^
Edited on 20 March 2012 - 08:16 PM
12 posts
Location
Germany
Posted 20 March 2012 - 10:05 PM
Thx :)/>/>
Next problem :D/>/> :
length = io.read()
term.clear()
term.setCursorPos(1, 1)
function checkLength()
if length >= 0 then
length = length - 1
else
os.shutdown()
end
end
Error:
attempt to compare string with number expected, got string
Help pls :)/>/>
473 posts
Location
Poland
Posted 20 March 2012 - 10:13 PM
length=tonumber(io.read())
12 posts
Location
Germany
Posted 22 March 2012 - 07:05 PM
Thanks :(/>/>
A new problem:
Spoiler
function invalidLength()
term.clear()
term.setCursorPos(1, 1)
print "#- Replace bottom by defighter9 -#"
print "# Length invalid! Length >= 1 #"
print "# Length: #"
print "# #"
print "#--------------------------------#"
term.setCursorPos(12, 3)
length = tonumber(io.read())
if length <= 1 then
return checkLenght()
else
invalidLength()
end
end
function checkLength()
term.clear()
term.setCursorPos(1, 1)
if length >= 1 then
length = length - 1
print( "Turns left: " .. length .. " . Please wait.")
return checkBot()
else
invalidLength()
end
end
function checkBot()
if turtle.detectDown() then
return digBot()
else
return placeBot()
end
end
function digBot()
turtle.digDown()
sleep(0.5)
return checkSlot()
end
function checkSlot()
if turtle.getItemCount(1) >= 0 then
return placeBot()
end
end
function placeBot()
turtle.select(1)
turtle.placeDown(1)
return move()
end
function move()
turtle.forward()
sleep(0.5)
return checkLength()
end
term.clear()
term.setCursorPos(1, 1)
term.clear()
term.setCursorPos(1, 1)
print "#- Replace bottom by defighter9 -#"
print "# #"
print "# Length: #"
print "# #"
print "#--------------------------------#"
term.setCursorPos(12, 3)
length = tonumber(io.read())
return checkLength()
It works, but if it doesn't detect something down it doesn't place something, why? Where is my bug?
473 posts
Location
Poland
Posted 22 March 2012 - 07:46 PM
turtle.placeDown() not turtle.placeDown(1)
12 posts
Location
Germany
Posted 22 March 2012 - 08:07 PM
thx, always this small bugs…
Question:
I'm using Technic 6 SSP, don't know whether you heard about it, but it seems CC is only compatible with the vanilla blocks, because turtles can only place vanilla blocks. Any idea how to fix this?
436 posts
Posted 22 March 2012 - 09:31 PM
"Only work with vanilla blocks" ?
From all experiments I've done (basically NEI'ing myself a bunch of blocks and tile entities), the problem only comes from tile entities. Vanilla ones it refuses (returns false), but mod-based entities such as RP2 wires get destroyed. Also, when it digs IC2 machines, it has, if not 100%, a 90% chance to convert down. But, that may just be bad luck on my part.
About the tile entities, until Dan200 finds/makes a way to call orientation on blocks placed by the turtles, there is not much fix for it. So far as I can tell, this is a limitation on the mod. But I've been known to be wrong.
One further thought, before I go. I actually don't use Technic or Tekkit, mostly because I find it much easier to update myself (since most of the mods just need to be placed in the mods folder), but they are known to change mods they put it (or did back when I did use it), so maybe they have disable mod-block usage for simplicity's sake. But, again, unless you change the code for the mod, there is no way to change this.