259 posts
Posted 04 March 2014 - 02:57 AM
I found that there is a limit to how fast you can do a textutils.slowWrite()/textutils.slowPrint(). I have it maxed out but it just isn't fast enough. It's not even a long string, but it just lasts for a second longer than I'd like. Is there a way that I can make it end the slowWrite() on an os.pullEvent() mid slowWrite()?
7083 posts
Location
Tasmania (AU)
Posted 04 March 2014 - 04:17 AM
Basically it writes at a rate of one character per second, divided by the rate you specify. After each character it sleeps. The minimum time it can sleep will either be one tick or however long it takes for any other running scripts to yield.
You'd need to implement your own version of the function, such that no "sleep"s are used. You'd instead start your own timer operation at the start, which covers the total amount of time you're willing to wait. For each character, you rig another timer set at the character printing speed you want. If the first timer expires before all the other ones do, then you just dump whatever remains of the string on-screen and move on.
Are you familiar with
working with timer events?
Edited on 04 March 2014 - 03:20 AM
259 posts
Posted 04 March 2014 - 04:23 AM
Basically it writes at a rate of one character per second, divided by the rate you specify. After each character it sleeps. The minimum time it can sleep will either be one tick or however long it takes for any other running scripts to yield.
You'd need to implement your own version of the function, such that no "sleep"s are used. You'd instead start your own timer operation at the start, which covers the total amount of time you're willing to wait. For each character, you rig another timer set at the character printing speed you want. If the first timer expires before all the other ones do, then you just dump whatever remains of the string on-screen and move on.
Are you familiar with
working with timer events?
Yeah, I'm familiar with them. I was just hoping I could be lazy and not have to write it lol. In that case, if I were to create a function like this
function textutils.slowWrite( Text, Time )
-- code
end
would it overwrite the native CC one? Or would it even be wise to do that in the first place?
1281 posts
Posted 04 March 2014 - 05:24 AM
This should be easy enough with the parallel api.
local text = "this is a test"
local cursX,cursY = term.getCursorPos()
parallel.waitForAny(
function()
textutils.slowWrite(text)
end,
function()
os.pullEvent()
term.setCursorPos(cursX,cursY)
print(text)
end
)
Your suggestion would indeed overwrite the original. Just back it up beforehand.
backupSlowWrite = textutils.slowWrite
Edited on 04 March 2014 - 06:30 AM
7508 posts
Location
Australia
Posted 04 March 2014 - 06:16 AM
This should be easy enough with the parallel api.
local text "this is a test"
local cursX,cursY = term.getCursorPos()
parallel.waitForAny(
function()
textutils.slowWritetext)
end,
function()
os.pullEvent()
term.setCursorPos(cursX,cursY)
print(text)
end
)
bug fix time dude. maybe even run it just to make sure what you
think it does.
1281 posts
Posted 04 March 2014 - 07:29 AM
Blah, i missed a parentheses and equal sign. Writing code on my phone isn't the easiest thing in the world…
Edited on 04 March 2014 - 06:30 AM
259 posts
Posted 04 March 2014 - 07:48 AM
Blah, i missed a parentheses and equal sign. Writing code on my phone isn't the easiest thing in the world…
I caught those two, have yet to test it though. I've been working on other parts for the day. I always forget about the parallels.
7083 posts
Location
Tasmania (AU)
Posted 04 March 2014 - 09:20 AM
Just bear in mind that, as written, it'll do more or less what you asked for but likely not at all what you want.
(It needs to be rigged to wait for a specific event. Not just the first of those that'll be generated, say, between every character slowWrite prints out, or one produced if a user presses a key, or if a rednet message comes in, or…)
Really I think the smoothest result would be gained by printing more then one character at a time.