This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PetruZ's profile picture

[Question] Only making a thing work if i typed a specific text.

Started by PetruZ, 16 May 2012 - 01:01 PM
PetruZ #1
Posted 16 May 2012 - 03:01 PM
Hi, the title might be confusing, sorry for that.

What I want is to make something like this:

You type in "commands" and if you have done that then you can type "commands2" otherwise, if you haven't typed commands you can't. And when you type "clear" (It clears the screen and sets the cursorpos. to 1,1) you can't type commands2 anymore.

Thanks.
PetruZ
PixelToast #2
Posted 16 May 2012 - 04:18 PM
sorry but what commands are you trying to do? are you trying to edit the shell? im confused
hold on im editing the shell to see if i can do something similar
PetruZ #3
Posted 16 May 2012 - 04:28 PM
I assumed you would :P/>/> What I have made is a script with different functions, like for example shutdown and then it shutsdown. What I want to modify is if you type commands it shows all the available commands, but there are quite a few so I made a "commands2" thing, which shows like page 2 or just basically the rest of the commands. But I dont want it to be possible to type commands2 without typing commands. Since commands shows everything then I've made print("type commands2 to show more"). And one of my commands are "clear" which clears from text and when I do that, it should disable being possible to type commands2.

So basically; "commands" makes it possible to type "commands2" and "clear" makes it not possible anymore. And of course it should not be possible from the star
PixelToast #4
Posted 16 May 2012 - 05:09 PM

local tCommandHistory = {}
cleared = false
while not bExit do
	canrun = true
write( shell.dir() .. "> " )
local sLine = read( nil, tCommandHistory )
table.insert( tCommandHistory, sLine )
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
  table.insert( tWords, match )
end
local sCommand = tWords[1]
if sCommand == "clear" then cleared = true end
if sCommand == "commands" then cleared = false end
if sCommand == "commands2" and cleared == true then canrun=false end
if sCommand and canrun then
  shell.run( sCommand, unpack( tWords, 2 ) )
end
if canrun == false then
  print("Error: try running commands first")
end
end
havent tested it IG yet, doing that now
EDIT: seems to work fine
PetruZ #5
Posted 16 May 2012 - 07:40 PM
is there nothing simple like "then if input==….." ? :P/>/>