4 posts
Posted 22 May 2014 - 03:13 PM
I've downloaded and setup a program called TangentLock v.4 by Tangentdelta. (
http://pastebin.com/GmrdsdPR)
The script works fine and does what it says but for some reason it allows the user the exit the program by CTRL + T. So, the user is able to list and edit the program and get the password from the code.
What should I add to this code so that it will not allow user to terminate the program?
Thanks.
14 posts
Posted 22 May 2014 - 03:35 PM
Faneader
I my self am pretty new to the whole ComputerCraft stuff but I am pretty sure It has something to do with the os.pullEvent()
You are going to want to change it from
os.pullEvent()
to
os.pullEventRaw()
As I said I am pretty new to Lua so I could be completely wrong and I apologize in advance if I am! :D/>
Edited on 22 May 2014 - 01:37 PM
4 posts
Posted 22 May 2014 - 03:55 PM
No problem, thank you for trying.
I understand your suggestion but there is no os.pullEvent() function in the code, so I don't know what to replace actually.
1281 posts
Posted 22 May 2014 - 04:08 PM
While your answer is correct, you should probably read the code next time. He doesn't use os.pullEvent, but rahter io.read which calls os.pullEvent. What he instead needs to do is overwrite the global os.pullEvent with the global os.pullEventRaw, thereby overwriting the one io.read uses.
Put this at the top
local pullBack = os.pullEvent --backup the old function
os.pullEvent = os.pullEventRaw --override to prevent termination
Then put this at the part where the password has been entered correctly
os.pullEvent = pullBack --restore original to enable termination again
4 posts
Posted 22 May 2014 - 06:30 PM
Thanks for clarifying the issue CometWolf, your code solved the problem.
Now I'm trying to come up with ideas where this code can be expanded, for example if the entered password is incorrect, the player gets attacked. (Maybe by turtles or something else.) Do you guys think it's possible?
571 posts
Location
Some Fish Bowl in Ohio.
Posted 22 May 2014 - 06:48 PM
Thanks for clarifying the issue CometWolf, your code solved the problem.
Now I'm trying to come up with ideas where this code can be expanded, for example if the entered password is incorrect, the player gets attacked. (Maybe by turtles or something else.) Do you guys think it's possible?
Yes it is. Have the turtle wait for a redstone pulse(1) and when it receives one from the computer(2), have it attack(3).
1:
os.pullEvent("redstone") --#Waits for a redstone input.
2:
local side = back --#side the redstone is on.
local time = 1 --#time to emit the pulse.
rs.setOutput(side, true) --#redstone is active.
sleep(time) --#sleeps for the amount of time defined.
rs.setOutput(side, false) --#redstone is deactivated.
3:
turtle.attack() --#Attacks in the direction it is facing.
Final code snippets:
Spoiler
--#turtle
while (os.pullEvent("redstone")) do
turtle.attack()
end
--#computer
local side = back --#side the redstone is on.
local time = 1 --#time to emit the pulse.
rs.setOutput(side, true) --#redstone is active.
sleep(time) --#sleeps for the amount of time defined.
rs.setOutput(side, false) --#redstone is deactivated.
Edited on 22 May 2014 - 05:58 PM
14 posts
Posted 22 May 2014 - 06:56 PM
Faneader
Sorry about that. My brain didn't register the Pastebin link. Oops. :/
There are a couple of ways you could get the turtles to attack. I'll leave that to the pros though. Messed up enough already today. XD
Wish you luck!
4 posts
Posted 22 May 2014 - 09:58 PM
Yes it is. Have the turtle wait for a redstone pulse(1) and when it receives one from the computer(2), have it attack(3).
Thanks for the code, I'm trying to add it to the main code but I have other questions due to my lack of experience with computercraft
.
1) You are using
side multiple times when telling the computer to emit the code, do the computer and turtle need to be in physical contact? Or can we transmit this signal via something else.. ?
2) Does it matter which turtle I'm using? My options are (Melee Turtle, Melee Sensor Turtle and the advanced versions)
3057 posts
Location
United States of America
Posted 22 May 2014 - 10:18 PM
Yes it is. Have the turtle wait for a redstone pulse(1) and when it receives one from the computer(2), have it attack(3).
Thanks for the code, I'm trying to add it to the main code but I have other questions due to my lack of experience with computercraft
.
1) You are using
side multiple times when telling the computer to emit the code, do the computer and turtle need to be in physical contact? Or can we transmit this signal via something else.. ?
2) Does it matter which turtle I'm using? My options are (Melee Turtle, Melee Sensor Turtle and the advanced versions)
1) yes with that code, but with the rednet api or the modem api you could transmit messages
2) I don't think so, no
571 posts
Location
Some Fish Bowl in Ohio.
Posted 22 May 2014 - 10:44 PM
Yes it is. Have the turtle wait for a redstone pulse(1) and when it receives one from the computer(2), have it attack(3).
Thanks for the code, I'm trying to add it to the main code but I have other questions due to my lack of experience with computercraft
.
1) You are using
side multiple times when telling the computer to emit the code, do the computer and turtle need to be in physical contact? Or can we transmit this signal via something else.. ?
2) Does it matter which turtle I'm using? My options are (Melee Turtle, Melee Sensor Turtle and the advanced versions)
1) yes with that code, but with the rednet api or the modem api you could transmit messages
2) I don't think so, no
They need to have a redstone dust line connecting to each other.