-2

As long as I know, some special characters can be displayed if you echo them using "". I'm simply stuck on the code, trying to figure out where I can change for this to work. I can't see the problem. Code from here. What i need is a special code that can do write animations for me, and then exit. Just like that. I've copied the code from there, modified so it could be called using typewriter.bat "text" "charsnum-1", like typewriter "Hello" 4. Though I don't really understand Batch Hybrids, and, even knowing how to interpret code, I can't see where the symbols are getting stuck at.

To reproduce my problem: typewriter.bat "Hello?" 5

Code:

@if (@CodeSection == @Batch) @then

@echo off
setlocal

color 70
set charnuu=%2

call :split chars %1

:begin
for %%i in (%chars%) do call :type "%%~i"
exit /b
goto begin

:split <var_to_set> <str>
setlocal enabledelayedexpansion
set "line="
set "str=%~2"
for /L %%I in (0,1,%charnuu%) do set line=!line! "!str:~%%I,1!"
endlocal & set "%~1=%line%"
goto :EOF

:type <char>
cscript /nologo /e:JScript "%~f0" "%~1"
goto :EOF

@end
// end batch / begin JScript chimera
function pause() { WSH.Sleep(Math.random() * 50 + 50); }
function odds(num) { return !(Math.round(Math.random() * num) % num) }


pause();

if (odds(300)) WSH.Echo('');
if (!odds(400)) WSH.StdOut.Write(WSH.Arguments(0));

This code isn't showing common symbols or even the basic ones, like ?. Maybe I am too tired to see it. Help me.

user692942
  • 16,398
  • 7
  • 76
  • 175
  • 2
    Question marks can't be used in regular `for` loops - see [this question](https://stackoverflow.com/questions/51644168/why-cant-you-use-a-question-mark-in-a-batch-for-loop) for more details. Also, that script doesn't do what you think it does and if you read rojo's comment at the bottom, you'll see that it's a script designed to simulate a screensaver by deliberately adding a chance of typos to the string. This is not something that you want. – SomethingDark Sep 01 '21 at 18:16
  • I would advise that you try to explain the purpose of the script, what you want to pass to it as arguments, and what exactly you'd like to happen. My best guess is that you want the end user to input two arguments, _(a string and an integer)_, and then appear like a typewriter to type that string character by character up until integer number of characters have been typed. If that's what you want to do, then there's no necessity for a hybrid script at all, it can be done using a batch file with standard built-in utilities. – Compo Sep 01 '21 at 18:36
  • @Compo Really? How? Also, yes, exactly. –  Sep 01 '21 at 20:09
  • @SomethingDark Yes, I know, I removed the typos chances on this one. I'm making a game on Batch, so modding and understanding the game will be easy, but I want some animations, sounds... everything that a normal game can do... Without too much graphic schemes. –  Sep 01 '21 at 20:10
  • @SomethingDark Also, yes, typos on games can be good anyways too. Especially the random ones. –  Sep 01 '21 at 20:11
  • @Compo If you can show me how I would do it without any hybrids, I would mark your answer. –  Sep 01 '21 at 20:18

1 Answers1

1

Question marks can't be processed by regular for loops, but you can get around that by not processing the individual letters with a loop at all and just iterating over the entire string as a whole:

@echo off

REM Just kinda honor-system the string length since this is proof of concept
REM     but remember that string indices start at 0
set "string=%~1"
set "string_length=%~2"

REM Generate a backspace character for later
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"

REM The setlocal is down here instead of at the top like it usually is to handle
REM     strings that contain exclamation points.
REM There's a period followed by a backspace before the substring is printed in
REM     case the current character happens to be a space (which otherwise
REM     wouldn't get printed).
REM The timeout /t 0 is because timeout is an external command that technically
REM     needs a few milliseconds to start up, so setting the wait period to 0
REM     seconds actually generates a pause shorter than 1 second.
setlocal enabledelayedexpansion
for /L %%A in (0,1,%string_length%) do (
    <nul set /p "=.%BS%!string:~%%A,1!"
    >nul timeout /t 0
)
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
  • Really a great amount of knowledge right there! But I'm getting the text `.H.e.l.l.o.?` instead of what I would expect, maybe I implemented something wrong? Thanks for the `timeout /t 0` tip! But I still consider a silent `ping` or a `timeout /t 1` a little more accurate to the time I want in. Thanks for the help! –  Sep 01 '21 at 20:22
  • ah, it looks like StackOverflow didn't include the backspace character that's supposed to be there after the `.`; I've updated the code to include a more visible backspace character – SomethingDark Sep 01 '21 at 20:30
  • Oh! Got it. Gonna search it up. Can you paste it somewhere where I can copy or something like that? –  Sep 01 '21 at 21:10
  • Also, do you know someone who answered how to make a char counter in batch pure? –  Sep 01 '21 at 21:19
  • @TheVaskonselo, please use the search box at the top of each page of this site. It should be used to locate questions and answers with your specific search terms and tags. We are not your personal search engine, locating and linking pages to your requirements, so that you don't have to put in any effort yourself. – Compo Sep 01 '21 at 21:27
  • @Compo The difference between "Hey, search a answer about that topic" and "Do you know someone who answered it? Would be a great help" seems clear to me. One is someone being lazy, the other is someone asking to some recommendation *if possible*. I hope it is as clear to you. –  Sep 01 '21 at 21:32
  • @TheVaskonselo, the search box allows you to put in simple terms, so if you want to search for questions about counting string characters in a batch file, what I'd begin with would be [count string characters \[batch-file\]](https://stackoverflow.com/search?q=count+string+characters+%5Bbatch-file%5D). After all, it's not rocket science, almost everyone with a computer knows how to use a search facility nowadays. Technically, I know someone who answered it, so the direct answer to that question would be **yes**! What else could I offer? their contact details? or something else? – Compo Sep 01 '21 at 21:36
  • @Compo Also, already found a solution. Not the best one, but some. That 100% does not fit on what I'm doing, and I don't know how to do better, or why you expect me to make another question just about this: FOR %%? IN (_tempfile.txt) DO (echo %%~z?)>_tempfile.txt& set /p _strlenght=<_tempfile.txt& set /a _strlenght=%_strlenght%-6 ... That is the result on it. –  Sep 01 '21 at 21:59
  • 1
    There is no way you should expect somebody to have had a 100% identical question. The idea is that you research and adapt solutions, this site is a resouce for code you can adapt to your specific situation, by researchng any commands used yourself. It is not a site which writes code for you to your exact requirements, gives you links to, or names of people who can, or performs your searches and research for you. If you have another question about code you've found, researched, adapted and run which fails in some way, then you have a new question. Here we deal with one issue per question post. – Compo Sep 01 '21 at 22:39
  • @Compo Yes, and that is why I asked if he knows some solution that fits on my problem too, so I wouldn't need to make another question here... wtf –  Sep 02 '21 at 11:24
  • @TheVaskonselo, read my comments. You do not ask, you use the search facility! Please stop trying to defend an undefendable position. If you have a question which is on topic, follows the guidelines within the content of [ask], and which is separate from that already asked and answered here, then create a new question for it. Just because somebody has answered for you already here, does not tie them into a one to one support deal with you moving forward. Please show a little more respect, follow the site guidelines, and you will be more likely to get from this site the help which it delivers. – Compo Sep 02 '21 at 12:00