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

Input box inside printed gui?

Started by TyDoesMC, 16 May 2015 - 03:35 AM
TyDoesMC #1
Posted 16 May 2015 - 05:35 AM
Hello, I'm getting into UI's/GUI's and I'm wanting to make one by me not by others, just personal preference.
This is what Im wanting to achieve:
A UI with inputs inside a border like
+===========+
| Usermame: |
+===========+




How to have a keyboard scroll menu with highlighted
> Menu option one <
menu option two

thats what I want to work on for now so please dont say make advanced comp guis I am wanting to learn this because its good for my rping
Edited on 16 May 2015 - 03:43 AM
Lyqyd #2
Posted 16 May 2015 - 05:40 AM
Please try uploading the image to imgur or another image hosting site and providing a link to it here. Whatever you tried to do previously did not work correctly.
TyDoesMC #3
Posted 16 May 2015 - 05:44 AM
Edited check again for better detail
TyDoesMC #4
Posted 16 May 2015 - 06:06 AM


Thats whats wrong it wont print the bottom until I type the name
Bomb Bloke #5
Posted 16 May 2015 - 06:18 AM
What you're asking sounds a bit like "I know a bit about how to do addition. Can someone explain this calculus problem to me?"…

In order to make multiple input fields that you can switch between and scroll through yadda yadda yadda, you pretty much have to forget about using read() - which is designed to block execution of the rest of your script until someone hits enter - and instead switch to building your own version from scratch. You need to manually handle every keypress and mouseclick with your own code - figuring out which input field is active, and therefore should have characters added to it when you type stuff, how to change the active field without discarding the content of the old one, and so on.

I suppose a good example to start you off would be this basic structure:

-- Fill this table with the positions and contents of each text field:
local textfields = {}

-- Use this to figure out which index in textfields to modify when the user types stuff:
local activeField = 1

while true do
	local myEvent = {os.pullEvent()}
	
	if myEvent[1] == "mouse_click" then
		-- Did the click match a position in the textfields table? Make that active if so.
		
	elseif myEvent[1] == "key" then
		-- Was the keypress something like a backspace? Remove a character from the active textfield if so.
		
	elseif myEvent[1] == "char" then
		-- Add the character to the current text field.
	
	end
end

A good understanding of os.pullEvent() and tables is essential.
TyDoesMC #6
Posted 16 May 2015 - 06:25 AM
Is there any apis for this or builders like Graffiti?
Bomb Bloke #7
Posted 16 May 2015 - 07:22 AM
Well, I've got a hunch you can build forms with Bedrock, and there are a few other "GUI" APIs about the place such as this one. My WorldPorter script also treats its menu pages as forms.
Dragon53535 #8
Posted 16 May 2015 - 05:09 PM
I have a hunch that the reason his bottom line won't show is because he's attempting to get user input before drawing the line.


print("-------")
write("Username: ")
local s = read()
print("--------")
That bottom print will not run until AFTER you type in a username. Your best bet would be to print it all, then manually move the cursor there and THEN read.

print("-------")
print("Username: ") --#10 characters long, i'll put it in at 11.
print("-------")
term.setCursorPos(11,2) --#Set it right after that space
local s = read()
On this one the last line will be made.
TyDoesMC #9
Posted 16 May 2015 - 06:37 PM
Thankyou thats what I needed!
TyDoesMC #10
Posted 17 May 2015 - 07:43 PM
I have a hunch that the reason his bottom line won't show is because he's attempting to get user input before drawing the line.


print("-------")
write("Username: ")
local s = read()
print("--------")
That bottom print will not run until AFTER you type in a username. Your best bet would be to print it all, then manually move the cursor there and THEN read.

print("-------")
print("Username: ") --#10 characters long, i'll put it in at 11.
print("-------")[img]http://i.imgur.com/mVXJUYv.png[/img]
term.setCursorPos(11,2) --#Set it right after that space
local s = read()
On this one the last line will be made.
thankyou so much I made a good login screen now!