![]() |
|
How to word wrap in batch - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: How to word wrap in batch (/Thread-How-to-word-wrap-in-batch) |
How to word wrap in batch - PInkleton - 03-26-2013 I have been working on a game coded in simple batch commands, however my issue is word wrapping. Such as Hi how are you can turn into Hi how are y ou. ![]() When it says "are in order", I would like order to go to the next line without me having to space it myself. How to word wrap in batch - PInkleton - 03-26-2013 I have been working on a game coded in simple batch commands, however my issue is word wrapping. Such as Hi how are you can turn into Hi how are y ou. ![]() When it says "are in order", I would like order to go to the next line without me having to space it myself. RE: How to word wrap in batch - noize - 03-26-2013 Well, the simple answer is, you can't. Nothing to do with it, I'm sorry. Anyhow, maybe I can help you with this idea. I mean, I guess this is probably a simple random choice between winning or losing against the enemy (I really do hope it isn't a fixed result). You could create a file (like points.txt) with the initial value of 0. It gets (e.g.) to 20 as you win the first fight. Then to 15 if you lose a new fight or to 30 if you win it. You could put some different kind of enemies (a wank, an average one and a stronger one) and read the value from the text file (set a limit, like 50, or else, once got to an high number is no longer a game; then you can decrease and get again to max. 50), and the more points you have, the more chances to win. You could have something like Code: set a=%random%&set b=%random%
if %a% GTR %b% (
rem WON!
for /f "delims=" %%j in ('type points.txt') do set cp=%%j
rem Points.txt should contain only a number!
set /a np=cp+5
<nul set /p useless-var-i-just-use-this-little-known-excapement-to-avoid-line-feeds,-also-for-customized-pause-commands,-as-you-can-see-beneath=%np%>points.txt
rem Such a long var-name
rem Actually just a echo would look fine, but this can avoid troubles at some times while needing to get content of a file to variable,
rem as you should do for the read-from-points.txt
rem ########################
rem <nul set /p pause=Press any key...
rem pause
rem ########################
rem the above gives you a Press any key... with the pause on the same line, so it looks like the autenthical one.
rem just a thing that looks way stylish to me.
)
if %b% GTR %a% (
rem LOST!
rem Just do the same but decreasing points
)
if "%a%"=="%b%" (
rem You are now friends! LOL (How about the chances to get this result?!)
)Don't know if have been useful; hope so. RE: How to word wrap in batch - noize - 03-26-2013 Well, the simple answer is, you can't. Nothing to do with it, I'm sorry. Anyhow, maybe I can help you with this idea. I mean, I guess this is probably a simple random choice between winning or losing against the enemy (I really do hope it isn't a fixed result). You could create a file (like points.txt) with the initial value of 0. It gets (e.g.) to 20 as you win the first fight. Then to 15 if you lose a new fight or to 30 if you win it. You could put some different kind of enemies (a wank, an average one and a stronger one) and read the value from the text file (set a limit, like 50, or else, once got to an high number is no longer a game; then you can decrease and get again to max. 50), and the more points you have, the more chances to win. You could have something like Code: set a=%random%&set b=%random%
if %a% GTR %b% (
rem WON!
for /f "delims=" %%j in ('type points.txt') do set cp=%%j
rem Points.txt should contain only a number!
set /a np=cp+5
<nul set /p useless-var-i-just-use-this-little-known-excapement-to-avoid-line-feeds,-also-for-customized-pause-commands,-as-you-can-see-beneath=%np%>points.txt
rem Such a long var-name
rem Actually just a echo would look fine, but this can avoid troubles at some times while needing to get content of a file to variable,
rem as you should do for the read-from-points.txt
rem ########################
rem <nul set /p pause=Press any key...
rem pause
rem ########################
rem the above gives you a Press any key... with the pause on the same line, so it looks like the autenthical one.
rem just a thing that looks way stylish to me.
)
if %b% GTR %a% (
rem LOST!
rem Just do the same but decreasing points
)
if "%a%"=="%b%" (
rem You are now friends! LOL (How about the chances to get this result?!)
)Don't know if have been useful; hope so. RE: How to word wrap in batch - ArkPhaze - 03-30-2013 Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... RE: How to word wrap in batch - ArkPhaze - 03-30-2013 Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... RE: How to word wrap in batch - noize - 03-30-2013 (03-30-2013, 03:36 AM)ArkPhaze Wrote: Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... Yes... well... that's not easy... Maybe you could also do that by setting the text to variables and then using %var:~0,numberofcharsyouwantperline%. Anyhow, I can't think of a reason I would do that for. RE: How to word wrap in batch - noize - 03-30-2013 (03-30-2013, 03:36 AM)ArkPhaze Wrote: Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... Yes... well... that's not easy... Maybe you could also do that by setting the text to variables and then using %var:~0,numberofcharsyouwantperline%. Anyhow, I can't think of a reason I would do that for. RE: How to word wrap in batch - ArkPhaze - 03-30-2013 (03-30-2013, 05:53 PM)noize Wrote:(03-30-2013, 03:36 AM)ArkPhaze Wrote: Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... That's almost just the same method that I just explained. Only doing it like that would be no different than the edge of the right buffer cutting off the text, since you are still measuring by chars not words... Code: set text=some words go here
echo %text:~0,7%"some wo" is not what the OP wants to see. RE: How to word wrap in batch - ArkPhaze - 03-30-2013 (03-30-2013, 05:53 PM)noize Wrote:(03-30-2013, 03:36 AM)ArkPhaze Wrote: Actually, the simple answer is you can, it's just hard to do. If you fool around with mode to set the number of columns then you should know how big your buffer is and how many chars can fit into a row. From there, you can probably loop through substrings of the variable for the text and count and decide where to split the words off. Although I'm not sure why you would take the time to do so... That's almost just the same method that I just explained. Only doing it like that would be no different than the edge of the right buffer cutting off the text, since you are still measuring by chars not words... Code: set text=some words go here
echo %text:~0,7%"some wo" is not what the OP wants to see. |