Jump to content




Terminal Glasses


5 replies to this topic

#1 HVENetworks

  • Members
  • 8 posts
  • LocationSweden

Posted 09 May 2018 - 04:08 PM

I have made a program which will display different short "animated" messages, currently "Creative Age" for testing.

But it seems like it could be a lot more simplified than to write it for every frame.

It basically adds another letter each 0.2 seconds and keeps it on screen for 3 seconds, then take the letter off one by one every 0.2 seconds.

Here's my code: https://pastebin.com/jAsBzCkg

Spoiler

How do I delete or move my post?

#2 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 09 May 2018 - 04:10 PM

Uhh... maybe write an API that will handle the writing?

#3 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 09 May 2018 - 04:13 PM

A couple of things you can do:

Use a loop instead of os.reboot() in order to loop forever:
while true do
  -- Your current code
end

Use a loop in order to display characters
If we look at the code, it's pretty much "add one character until it's all filled out, then remove one character". Let's represent this as a loop:
while true do
  local message = "Creative Age"
  for i = 1, #message do -- For the start of the string up to its length
	p.clear()
	p.addText(3, 3, message:sub(1, i)) -- Get the first i characters
	sleep(0.2)
  end
  sleep(3)
  for i = #message - 1, 1, -1 do -- From the end of the string down to the beginning again (note the -1)
	p.clear()
	p.addText(3, 3, message:sub(1, i)) -- Get the first i characters
	sleep(0.2)
  end
end

Reuse the text object
The labelPlayers object has setText method, which means we don't need to clear and recreate it every time:
p.clear()
local labelPlayers = p.addText(3, 3, "")
while true do
  local message = "Creative Age"
  for i = 1, #message do -- For the start of the string up to its length
	labelPlayers.setText(message:sub(1, i)) -- Get the first i characters
	sleep(0.2)
  end
  sleep(3)
  for i = #message - 1, 1, -1 do -- From the end of the string down to the beginning again (note the -1)
	labelPlayers.setText(message:sub(1, i)) -- Get the first i characters
	sleep(0.2)
  end
end

Edited by SquidDev, 09 May 2018 - 04:13 PM.


#4 HVENetworks

  • Members
  • 8 posts
  • LocationSweden

Posted 09 May 2018 - 04:49 PM

The reboot is required. This is just one part of the program.

#5 HVENetworks

  • Members
  • 8 posts
  • LocationSweden

Posted 09 May 2018 - 05:15 PM

It works :)
Thank you very much

#6 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 09 May 2018 - 05:37 PM

You can just edit your last comment instead of bumping

EDIT: Like this. Oh, and *bump*

Edited by EveryOS, 09 May 2018 - 05:38 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users