Jump to content




a way to auto-complete a slowWrite()?


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

#1 CCJJSax

  • Members
  • 262 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()?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (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 by Bomb Bloke, 04 March 2014 - 04:20 AM.


#3 CCJJSax

  • Members
  • 262 posts

Posted 04 March 2014 - 04:23 AM

View PostBomb Bloke, on 04 March 2014 - 04:17 AM, said:

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?

#4 CometWolf

  • Members
  • 1,283 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 by CometWolf, 04 March 2014 - 07:30 AM.


#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 04 March 2014 - 06:16 AM

View PostCometWolf, on 04 March 2014 - 05:24 AM, said:

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.

#6 CometWolf

  • Members
  • 1,283 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 by CometWolf, 04 March 2014 - 07:30 AM.


#7 CCJJSax

  • Members
  • 262 posts

Posted 04 March 2014 - 07:48 AM

View PostCometWolf, on 04 March 2014 - 07:29 AM, said:

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.

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users