Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Writing out characters from a variable with a small delay
- $blah = "From the beginning of time man has sought its own destruction, in this time of despair only one hero may rise amongst the ranks to deter evil from taking its place in the world. Will you be this hero? Can you stand up for what is right? Can you protect the helpless from there own demise? You hero, our are only hope."
- Function Write-Char{ #this function grabs each character in a variable and writes it out to screen with a small delay, causing a very familiar Final Fantasy or Zelda affect.
- Param
- (
- #Specify the characters to write to screen
- [Parameter(Mandatory=$true)]
- [Alias("characters")]
- [string]$text,
- #Specify the delay between characters
- [Parameter(Mandatory=$false)]
- [Alias("pause","wait")]
- [string]$delay='15'
- )
- $i=0
- Do {
- If ($i -eq $host.ui.RawUI.BufferSize.Width){ #this logic detects if the current character would force the window to scroll, and if so will write to a new line
- Write-Host ($text.Substring($i,1))
- }
- else{ #if the current character won't cause the window to scroll horizontally, then add the current character to the line
- Write-Host ($text.Substring($i,1)) -NoNewline
- }
- Start-Sleep -Milliseconds $delay #amount of time to wait between each character
- $i++ #increment $i to move to the next character
- }
- Until ($i -eq ($text.Length - 1))
- }
- Write-Char -characters $blah
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement