6 posts
                
                    
                        Location
                        Canada
                    
                
             
            
                Posted 06 August 2014 - 01:01 AM
                Hello guys. I was working on a script that allow me or players to type password to open or close the door and it was working successful. Here's the code.
local pass1 = "open"
local pass2 = "close"
rs.setOutput("bottom", true)
while true do
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome to Silverhustle & Exor's Underground Base. Please enter a password:")
   userPass = read("*")
   for _, side in pairs(rs.getSides()) do
		  rs.setOutput(side, true)
   end
   if userPass == pass1 then
		  rs.setOutput("bottom", false)
   elseif userPass == pass2 then
		  rs.setOutput("bottom", true)
   else --
		  rs.setOutput("bottom", true)
   end
end
But that's not until one player came to my base and used CTRL+T terminate on my code and the door automatically opens. Is there a way to prevent that from happening? Please let me know if that's possible, thank. :)/>
 
                
             
         
        
        
            
            
                
                    
                
                3790 posts
                
                    
                        Location
                        Lincoln, Nebraska
                    
                
             
            
                Posted 06 August 2014 - 01:09 AM
                You can simply add
os.pullEvent = os.pullEventRaw
at the top of your code.
This doesn't prevent shutdown or restart events however, as those are hardcoded into the Java side.
 
                
             
         
        
        
            
            
                
                    
                
                6 posts
                
                    
                        Location
                        Canada
                    
                
             
            
                Posted 06 August 2014 - 02:06 AM
                You can simply add
os.pullEvent = os.pullEventRaw
at the top of your code.
This doesn't prevent shutdown or restart events however, as those are hardcoded into the Java side.
That's it? Wow, never knew it's that simple. Thanks!
 
                
             
         
        
        
            
            
                
                    
                
                1140 posts
                
                    
                        Location
                        Kaunas, Lithuania
                    
                
             
            
                Posted 06 August 2014 - 10:23 AM
                What Cranium suggested would disable the termination event for the whole computer and if you would exit out of your door lock you wouldn't be able to terminate any other program/script. Looks like you never exit out of the door lock, but to re-allow termination event you should first save the 
os.pullEvent function and then restore it whenever your script exits:
local pullEvent = os.pullEvent --// Save the os.pullEvent function so we could restore it later
os.pullEvent = os.pullEventRaw --// Overwrite os.pullEvent to disable terminating
--[[/*
Your script goes here
*/]]
if scriptIsGoingToExit == true then --// If we are going to end the program
  os.pullEvent = pullEvent --// restore the original os.pullEvent
  exit() --// Exit out of the program
end
Note: there is no actual function 'exit', nor a variable named 'scriptIsGoingToExit', those variables should be defined by yourself.
 
                
                    Edited on 06 August 2014 - 08:25 AM
                
             
         
        
        
            
            
                
                    
                
                52 posts
                
             
            
                Posted 07 August 2014 - 09:25 PM
                What Cranium suggested would disable the termination event for the whole computer and if you would exit out of your door lock you wouldn't be able to terminate any other program/script. Looks like you never exit out of the door lock, but to re-allow termination event you should first save the 
os.pullEvent function and then restore it whenever your script exits:
local pullEvent = os.pullEvent --// Save the os.pullEvent function so we could restore it later
os.pullEvent = os.pullEventRaw --// Overwrite os.pullEvent to disable terminating
--[[/*
Your script goes here
*/]]
if scriptIsGoingToExit == true then --// If we are going to end the program
  os.pullEvent = pullEvent --// restore the original os.pullEvent
  exit() --// Exit out of the program
end
Note: there is no actual function 'exit', nor a variable named 'scriptIsGoingToExit', those variables should be defined by yourself.
After a restart os.pullEvent with termination will be back there.
 
                
             
         
        
        
            
            
                
                    
                
                1140 posts
                
                    
                        Location
                        Kaunas, Lithuania
                    
                
             
            
                Posted 08 August 2014 - 08:20 AM
                Unless the script wich overwrites the os.pullEvent runs on startup.