82 posts
                
             
            
                Posted 26 May 2012 - 06:42 PM
                Im trying to make a code where that the user needs to input a value that they want for x, and I can't seem to find any sort of code that someone could input a value for x (on the computer).
                
             
         
        
        
            
            
                
                    
                
                7 posts
                
             
            
                Posted 26 May 2012 - 06:52 PM
                I guess you have to use os.pullEvent and handle the char/key events…
this way you can build an input string which you can convert to a number afterwards (tonumber)
                
             
         
        
        
            
            
                
                    
                
                2447 posts
                
             
            
                Posted 26 May 2012 - 07:30 PM
                x = tonumber(read())
                
             
         
        
        
            
            
                
                    
                
                65 posts
                
                    
                        Location
                        The Internet
                    
                
             
            
                Posted 26 May 2012 - 07:45 PM
                You need to give more detail. what is the variable x going to do?
                
             
         
        
        
            
            
                
                    
                
                18 posts
                
             
            
                Posted 26 May 2012 - 08:16 PM
                I think I know what you mean.
I have used this in my code :
write("Height : ")
height = read()
heightmax = tonumber(height)
It will ask for an input and the variable "height" will be the input, the return from the input will be a string.
the tonumber function is to make it from a string to an integer.
Hope this helps
 
                
             
         
        
        
            
            
                
                    
                
                82 posts
                
             
            
                Posted 28 May 2012 - 05:35 AM
                You need to give more detail. what is the variable x going to do?
Its going to be the name you set, for a text adventure.
 
                
             
         
        
        
            
            
                
                    
                
                864 posts
                
                    
                        Location
                        Sometime.
                    
                
             
            
                Posted 28 May 2012 - 05:48 AM
                
x = "String"
print(x)
xVar = read()
if xVar == "OTHER STRING" then
print("ok.")
end
That prints the variable (x) then it reads the input and gives a reply.
Example:
x = "Username: "
write(x)
username = read()
if username == "hohoho" then
print("Accepted")
else
print("Denied")
end
EDIT: If you are searching for a word, "Dig" then you are going to have to read the "xVar" for that specific thing..
 
                
             
         
        
        
            
            
                
                    
                
                92 posts
                
             
            
                Posted 29 May 2012 - 06:39 PM
                
function handleEvent()
	evt, p1, p2 = os.pullEvent()
if evt == "char" then
   writeChar(p1)
	elseif evt == "key" then
   handleKey(p1)
elseif evt == "rednet_message" then
   messageReceive(p1, p2)
end
end
This is what LordDrako was talking about but it doesn't have to be so complicated.
Using a simple:
x = io.read()
will work as well, although it will halt your program until you press enter.