Jump to content


IliasHDZ

Member Since 11 Mar 2017
Offline Last Active Aug 05 2018 11:00 AM
-----

Topics I've Started

Make a sentence

04 August 2018 - 02:53 PM

So we are gonna make sentences with the replies being the words.
What you need to do is to type a word that you think would be a good next word of the previous reply.
If you feel like the sentence can end, then you can add a dot and the next reply can begin a new sentence with a word of choise.

Example:

I

make

cool

stuff

that

you

hate.

Now i am gonna begin with the word:

A patato

[TUTORIAL] A fix for the flickering effect.

31 July 2018 - 12:34 PM

Fixing the flickering effect!

Introduction
This is a common thing that happens when you are making a GUI program.

Today, i will show you how to fix this effect.
This is a method i found that uses the Window (API)
- Window API
- This is why you should use Computercraft 1.6 or higher


How it works
This is very easy to understand.

First, we make a Window that is the same size as the monitor.
Then at the beginning of rendering, we will redirect to the window.
Then at the end, we will redirect back to the main terminal and we will show the window.

The code
Here we have an example code:
function render()
	paintutils.drawFilledBox(5, 5, 30, 16, colors.green)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.red)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.blue)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.black)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.blue)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.white)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.lightBlue)
end
while true do
	os.pullEvent()
  
	render()
end
If you trigger an event (for example pressing a key).
The rectangles wil start to draw and you can see the flickering effect.

To fix this, we will first add a "getSize" function at the begin of the code. This is needed to give the window the size of the monitor.
I added the "term.current" function to redirect back to the main terminal.
local w, h = term.getSize()
local currTerm = term.current()

After that, we will make the window:
local window = window.create(currTerm, 1, 1, w, h, false)

Then at the beginning of the render function, we will add this:
This is to redirect to the window (This means if we draw something now on the screen. It will be drawn in the window)
term.redirect(window)

At the end of the render function, we will add this:
This is to redirect back to the main terminal (If we draw something now. It will be drawn normally) and
to show and hide the window.
term.redirect(currTerm)
window.setVisible(true)
window.setVisible(false)

You will end up like this:
local w, h = term.getSize()

local currTerm = term.current()
local window = window.create(currTerm, 1, 1, w, h, false)

function render()
	term.redirect(window)

	paintutils.drawFilledBox(5, 5, 30, 16, colors.green)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.red)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.blue)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.black)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.blue)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.white)
	paintutils.drawFilledBox(5, 5, 30, 16, colors.lightBlue)
  
	term.redirect(currTerm)

	window.setVisible(true)
	window.setVisible(false)
end
while true do
	os.pullEvent()

	render()
end

If you now test it out.
It would normally work.

If you are having problems.
You can post everything in the comment section below.
That is it for the fix.