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

Advanced text manipulation

Started by Jman, 06 April 2013 - 05:35 PM
Jman #1
Posted 06 April 2013 - 07:35 PM
I Couldn't think of a good topic title to associate this topic and define it's, well, topic…

Anyways.
I am attempting to make a password program equipped with: a full GUI; two input fields(User and Password); and Dialogue that appears before the GUI. However, the dialogue is my issue. Now your probably saying "Why?, it's simple just type (print ("text")) or (print "text" ) or (print 'text')". Well yes I know this but that is not quite exactly my issue about it, you see I'm a code NEAT FREAK, and I like to make my scripts as small in length as possible. That way it is easier to fix problems too. Anyways let me show you my issue then elaborate on how it's an issue.
print("[SYSTEM]")
term.setCursorPos(9,Y)    -- Y is yet to be determined
textutils.slowPrint("Diagnosing ASE Error")
sleep(2)
print("[SYSTEM]")
term.setCursorPos(9,Y+1)
textutils.slowPrint("Checking For Other Problems")
sleep(2)
Now, my issue is with the
print("[SYSTEM]")
term.setCursorPos(9,Y+1)
textutils.slowPrint("text")
Why? Well,I have close to around 15 more lines of dialogue to type out and I don't want to have to type those same three lines followed by 'sleep(#)' 17 consecutive times then have to go through and make sure everything is typed correctly, that and I personaly think that by doing that 17 repeated times just looks unprofessional. Of Course your probably thinking that this is just a personal problem and I'll admit it kind does sound like one now that I've read this through, but however, if you think you could help me out that would just be flat out amazing and thank you.

(Edit: Yep By Far The Worst Topic I have Ever Typed Then Posted. For Sure.)
1lann #2
Posted 06 April 2013 - 07:46 PM
If you're trying to have an output like this

[SYSTEM] Blah
[SYSTEM] More stuff
[SYSTEM] Derrrr

then use this function or something

local function systemPrint(str)
  write("[SYSTEM] ")
  textutils.slowPrint(str)
  sleep(2)
end
Jman #3
Posted 06 April 2013 - 07:55 PM
If you're trying to have an output like this

[SYSTEM] Blah
[SYSTEM] More stuff
[SYSTEM] Derrrr

then use this function or something

local function systemPrint(str)
  write("[SYSTEM] ")
  textutils.slowPrint(str)
  sleep(2)
end
thanks but whats the '(str)' for??
Engineer #4
Posted 06 April 2013 - 08:57 PM
So you can write anything with it.
You mist call the function like so:

functionNameHer('some random text')
Smiley43210 #5
Posted 07 April 2013 - 12:10 AM
It's the argument for a function.
Example:
-- Variables text and color will be set to whatever is passed to the function when it is called. If an argument is missing, it will be nil.
-- The variables here can only be used in this function, and not outside of it.
function colorPrint(text, color)
	if term.isColor() then term.setTextColor(color) end
	print(text)
end

-- In this case, the text variable is set to "Test 1: Lime green", and the color variable is set to colors.lime
colorPrint("Test 1: Lime green", colors.lime)
-- In this case, the text variable is set to "Test 2: Red", and the color variable is set to colors.red
colorPrint("Test 2: Red", colors.red)