Jump to content




GUI help


  • You cannot reply to this topic
19 replies to this topic

#1 CaptiveCreeper

  • Members
  • 22 posts

Posted 23 April 2014 - 04:20 AM

A while back i saw a forum post on how to make a text user interface in CC and i thought that was really cool so i made it a api. Now when i tried to use it with more items it is too long how would i make it so that it only show so it fits on the screen and then when you press down below the bottom option it will scroll down?

function custom(options)
  position = 1
  while true do
	term.clear()
	term.setCursorPos(1,2)
	for i = 1, #options, 1 do
	  if i == position then print(" >"..options[i].."<") else print( " ".. options[i]) end
	end
	a, b = os.pullEvent("key")
	if b == 200 and position > 1 then position = position - 1 end
	if b == 208 and position < #options then position = position + 1 end
	if b == 57 then break end
  end
  term.clear()
  term.setCursorPos(1,2)
  return position
end


Any help will be appreciated in advanced thanks.

Edited by Bubba, 23 April 2014 - 05:29 AM.


#2 bigbaddevil6

  • Members
  • 72 posts

Posted 23 April 2014 - 06:17 AM

I'm assuming the forum post you got the from was the YES/NO located here. If I'm correct why not just go with the customizable one?

Edited by bigbaddevil6, 23 April 2014 - 06:24 AM.


#3 CaptiveCreeper

  • Members
  • 22 posts

Posted 25 April 2014 - 03:07 AM

yes that is the one and the code i posted is the custom one from that post but how would you make it so if you have a long list that goes further that the screen can show at one time how would you make it so it scrolls through the list?

#4 HometownPotato

  • Members
  • 62 posts

Posted 26 April 2014 - 04:23 AM

I think this is what you are looking for:
http://computercraft...tils.pagedPrint

#5 CaptiveCreeper

  • Members
  • 22 posts

Posted 29 April 2014 - 02:08 AM

That looks promising i have to do homework right now so i can't check to see if that works (it looks like it will). I will have try that tomorrow.

#6 CaptiveCreeper

  • Members
  • 22 posts

Posted 30 April 2014 - 02:48 AM

Now that i look at it that would only let it scroll down and also i don't know how it would make the program know what index it ends on.

#7 CaptiveCreeper

  • Members
  • 22 posts

Posted 30 April 2014 - 03:56 AM

Actually you gave me a idea of how it may work i have most of it working but i have a problem and i don't know how to fix
local main = {}
for i = 1,50 do
  main[i] = i
  print(i)
end
local index = 1
while true do
selected = index
for index = index, 17 + index do
    if index == selected then print(" > " .. index .. ". " .. main[index] .. " < ")
    else print(index .. ". " .. main[index])
    end
end
local a
local b
a, b = os.pullEvent("key")
if b == 200 and index > 1 then index = index - 1 end
if b == 208 and index < #main then index = index + 1 end
if b == 28 then break end
end
return index

At line 11 when it gets to 17 less than the last value it crashes with error "Attempt to concentrate nil and string"

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 April 2014 - 04:50 AM

You could use:

for index = index, math.min(#main, 17 + index) do

Also this:

local a
local b
a, b = os.pullEvent("key")

Can be condensed to this:

local a, b = os.pullEvent("key")


#9 CaptiveCreeper

  • Members
  • 22 posts

Posted 30 April 2014 - 08:40 PM

I did that and now when it gets to 33 it starts printing 50 at the top and "selecting" meltable lines at once.

#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 May 2014 - 01:36 AM

Maybe throw a "term.clear()" in at the bottom of the loop, see if it makes more sense then.

#11 CaptiveCreeper

  • Members
  • 22 posts

Posted 01 May 2014 - 02:19 AM

When you do that it just shows a blank screen.

#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 May 2014 - 03:23 AM

Sorry, I wasn't specific - I'm guessing you've put it at the end of the "for" loop. I was referring to the "while" loop - just before it repeats. Or you could stick it at the top. Whatever suits you.

#13 CaptiveCreeper

  • Members
  • 22 posts

Posted 01 May 2014 - 03:57 AM

That works perfectly thank you and ya i put it in the for loop.

#14 CaptiveCreeper

  • Members
  • 22 posts

Posted 01 May 2014 - 04:08 AM

How would i make it so that at the end if it is less than 19 lines that it would show them all instead of when you press down it gets rid of the ones above it. If you understand.

#15 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 May 2014 - 07:00 AM

for index = math.min(#main - 17, index), math.min(#main, 17 + index) do

Or something like that, anyway.

In case it's not clear to you, math.min() returns the lowest value out of those you pass to it, whereas math.max() returns the highest.

#16 CaptiveCreeper

  • Members
  • 22 posts

Posted 06 May 2014 - 10:57 PM

Sorry for taking so long to respond. But when i use that line it doesn't select anything.

#17 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 May 2014 - 11:46 PM

You might need to show the current state of your script. As far as I can tell, it should work fine if you dump the line from here directly into the version here.

#18 CaptiveCreeper

  • Members
  • 22 posts

Posted 07 May 2014 - 01:44 AM

local main = {}
for i = 1,50 do
  main[i] = i
  print(i)
end
local index = 1
while true do
term.clear()
selected = index
for index = index, math.min(#main,17 + index) do
    if index == selected then print(" > " .. index .. ". " .. main[index] .. " < ")
    else print(index .. ". " .. main[index])
    end
end
local a
local b
a, b = os.pullEvent("key")
if b == 200 and index > 1 then index = index - 1 end
if b == 208 and index < #main then index = index + 1 end
if b == 28 then break end
end
return index
there you go that is what i have currently

#19 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 May 2014 - 02:54 AM

Ok. Now play spot the difference between what's in that, and the line I gave you here.

#20 CaptiveCreeper

  • Members
  • 22 posts

Posted 08 May 2014 - 10:54 PM

i did that and it did not put the > < around the "selected" item





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users