|
Answer» Ok I'm trying to set it up so when a certain variable is equal to a certain thing Dos picks from three predetermined words and echos on of them at random, any way at doing this?TRY this
Code: [Select]set word1=<watever phrase> set word2=<wateverphrase> set word3=<wateverphrase> if '%<watever variable>%'=='<watever thing>' ( set /a rnd=%random% %%3 + 1 >nul if '%rnd%'=='1' ( echo %word1% pause exit) if '%rnd%'=='2' ( echo %word2% pause exit) if '%rnd%'=='3' ( echo %word3% pause exit) )
ok this part states the three preditermined words Code: [Select]set word1=<watever phrase> set word2=<wateverphrase> set word3=<wateverphrase> this creates a random number( between 1 and 3) Code: [Select]set /a rnd=%random% %%3 + 1 >nul does this work for you? Yeah, works like a charm thanks!your quite welcome, if you need help with anything else, give one of us a holler Well now I'm having issues again. For some reason or another dos doesn't like these lines of code. Code: [Select]@echo off set DC1=10 if '%DC1%'=='10' ( set /a ST=%random% %%3 + 1 >null pause if '%ST%'=='3' ( pause set DC1= King goto :Done ) if '%ST%'=='2' ( pause set DC1= Queen goto :Done ) if '%ST%'=='1' ( pause set DC1= Jack goto :Done ) goto :DC2 ) :DC2 echo %DC1%, this is DC2. pause :Done echo %DC1%, this is DONE. pause The two different done statements aren't going to be apart of the finial code its just there so I know if its even running threw the other if statements. Now I'm guessing it has some thing to do with having the if statements inside a unfinished if statement but I'm not completely sure on this. It always PRINTS "10" to the SCREEN instead of one of the three words and it always hits DC2 instead of DONE so it appears to me for some reason or another its ignoring Code: [Select]pause if '%ST%'=='3' ( pause set DC1= King goto :Done ) if '%ST%'=='2' ( pause set DC1= Queen goto :Done ) if '%ST%'=='1' ( pause set DC1= Jack goto :Done )I know it picks a random number because it creates the null file but after that it just JUMPS for no reason. None that I can see atleast. Thanks in advance for all help.I'm guessing KISS doesn't live here anymore. I probably missed something, but why make this so complicated?
Code: [Select]@echo off set DC1=10 if '%DC1%'=='10' set /a ST=%random% %%3 + 1 if '%ST%'=='3' set DC1= King if '%ST%'=='2' set DC1= Queen if '%ST%'=='1' set DC1= Jack
echo %DC1%, this is OVER DONE.
Sometimes fall thru logic makes sense. ST can only have one value per run, so it drops thru the VALUES that are false.
ok i change it so there isnt the if statement inside the other if. and also i changed the null because this ">null" makes a file, this doesnt ">nul".
Code: [Select]@echo off set DC1=10 if '%DC1%'=='10' ( set /a ST=%random% %%3 + 1 >nul pause ) if '%ST%'=='3' ( pause set DC1=King goto :Done ) if '%ST%'=='2' ( pause set DC1=Queen goto :Done ) if '%ST%'=='1' ( pause set DC1=Jack goto :Done ) goto :DC2 :DC2 echo %DC1%, this is DC2. pause :Done echo %DC1%, this is DONE. pause does this work?Works great, thanks again for the help.
|