我正在使用預先製作的批量聊天功能,並且希望通過我自己的觸摸來改善它。需要多種顏色的批量聊天幫助
當有人在聊天說了些它會鍵入這樣的: [John]: Hello World
我想要做的是另一種顏色比程序的其餘部分得到[John]
。 我無法使它工作。我很樂意有人幫我繞過這個。
編輯:call:
命令不起作用。我嘗試過不同的批次,如colormsg和ctext。他們都沒有工作。我認爲問題在於>> log.dat
。
下面的代碼:
@echo off
rem: Matthew Merchant ScriptingMadness.blogspot.com
rem ###### TITLE SCREEN ############
title Batch Chat Room
echo.
echo WELCOME TO THE CHAT!
echo:
echo:
echo Commands:
echo just hit ENTER to update screen.
echo.
set /p username=What is your name?
echo %username% has joined. >> log.dat
cls
goto CHATLOOP
REM ############################
REM ########## CHAT LOOP ##########
set lastmessage=""
:CHATLOOP
cls
type log.dat
echo.
echo.
set /p message=Say:
rem set message checker value
set thismessage="%message%"
rem check for exit
if %thismessage% == "EXIT" echo %username% has left the chat room. >> log.dat
if %thismessage% == "EXIT" exit
rem -----------------
rem check for clear
if %thismessage% == "CLS" echo %username% has cleared the chat log. > log.dat
if %thismessage% == "CLS" set message=Empty
if %thismessage% == "CLS" set lastmessage="Empty"
if %thismessage% == "CLS" goto CHATLOOP
rem ------------------
rem check for same message as last time
if %thismessage% == %lastmessage% goto CHATLOOP
rem if all checks out, go ahead and post this message
echo [%username%]: %message% >> log.txt
rem save value for next test
set lastmessage="%message%"
goto CHATLOOP
REM ################################
如果你還是不明白我的意思。 見上文: 我想%username%
在另一種顏色比%message%
此外,請參閱[此問題](http://stackoverflow.com/questions/15015025/creating-colors-in-the-middle-of-a-批行/ 15017779#15017779)尋求更多幫助。 – 2013-03-08 23:44:16
那些不起作用。所有使用命令「call」的東西都不起作用。試過像colormsg這樣的不同批次,我認爲問題在於「>> log.dat」。 – user2149978 2013-03-09 13:55:10
你爲什麼如此確定'call'不會工作?在你的情況下實現多種顏色的一種方法可能是用更復雜的顯示文件內容的方法替換你的「類型log.dat」。您可能需要逐行解析文件,並在每行中將用戶名與其餘內容分開,然後以不同的顏色顯示每個文件。是的,您可能需要爲您的問題學習其他內容,例如如何解析批處理文件中的文本文件。但至少只是不要拒絕一個簡單的「不會工作」的建議,而無需思考和嘗試。 – 2013-03-09 19:14:13