Music Banter

Music Banter (https://www.musicbanter.com/)
-   The Lounge (https://www.musicbanter.com/lounge/)
-   -   Batch Programming (https://www.musicbanter.com/lounge/43550-batch-programming.html)

Guybrush 08-27-2009 06:00 AM

Batch Programming
 
Okay, okay - I realize I probably couldn't have made a more nerdy thread and I guess it's doomed to die an embarassing death, but I was wondering, have or do anyone else here do any batch programming? :D

Yes, it's pretty weak as far as programming go and yes, there's not much you can do with it but I used to play around with it as a kid (started with fiddling around in the autoexec.bat) and so I picked it up again a couple of years ago to see if I could do something interesting with it. Once I got my imagination going, it seems I could.

The very easiest though perhaps not the most useful thing I wrote was this little thing which generates a random number between 1 and whatever value you want.

Code:

@echo off
if "%1"=="" goto missing
if "%1"=="?" goto missing
if "%1"=="/?" goto missing

:random
set /a trandom=(%random%*%1/32768)+1
goto result

:missing
echo.
echo This file generates random numbers from 1 to the number you define.
echo.
echo To define a number, as an example - just write like this : "tdrandom 6".
echo That gives you a random number between 1 and 6.
echo.
echo You can edit this file and remove the last line if you want to keep
echo the random variable in the memory for use with other files.
echo.
echo -- Tore
goto end

:result
echo.
echo Result = %trandom%

:end
set trandom=

(%1 means the first command line argument and %random% means a number between 1 and 32767 or something)

For windows people, if you want to try it, just copy and paste this into a text file, save it as whatever.bat (changing the filetype to "bat" rather than "txt")and then click the start menu, choose run and write "cmd" in the box and press enter. You will open the command prompt. Navigate to where the file is and write the filename, that will run it.

This is of course the simplest thing I did, I've advanced beyond this and I found that there are some charming features to this old batch stuff. I especially like the way you can do for-loops (I can post examples later on)!

So, anyone else here who have fiddled around with this ancient art? :p

Freebase Dali 08-27-2009 09:39 AM

Yea that reminds me of Qbasic programming back in the day. We used to mess with batch programming as an aside and make what you'd basically call macros to make quick work of repetetive actions.
I started getting into dos-based scripting but eventually moved away from it.
Now that I'm taking a VisualBasic programming class in college, I'll probably start messing with this type of stuff again, but more along the VB and C++ lines.

Guybrush 08-27-2009 01:47 PM

The only "real" programming I've done besides this is php which is rather useful I find. Batch is just for fun of course. A funny thing about batch is the way you can divide your code into different sections and then jump to the different ones using the goto command. You can also use that in order to create for-oops ..

Code:

:start
@echo off
set /a var="1"
echo.

:loop
echo %var%
set /a var=%var%+1
if "%var%"=="101" goto end
goto loop

:end
set var=

This script would list numbers from 1 to 100, each on a separate line (set defines a variable - /a that it's a numerical value, echo outputs something to screen, goto jumps to different sections in the script and if runs a command when the if-criteria is met).

In the above example, there's an if-argument that when fulfilled jumps to the end of the script .. But if it's criteria is not met, the "goto loop" command will run instead, making the program run through the loop section one more time. I think it's a quite charming and intuitive way of doing it :)

Freebase Dali 08-27-2009 02:15 PM

That's pretty much how Qbasic runs. Each instructional line is given a numerical address and you assign a result with the GOTO command by listing the numerical address of the desired code. Eg.. "IF Y = 1 GOTO 15".

But yea.. I wouldn't set about trying to learn Basic this late in the game. C sharp and C++ is pretty much the standard for programmers, and Visual Basic for developers. VB macros kick more ass than console code anyhow. ;)

Zer0 08-31-2009 05:14 PM

I've never done batch programming. I'm pretty experienced in JAVA, 8051 chip assembly code, VHDL code and some C code. I learned JAVA as my main programming language instead of C++ which is a bit of a pain in the balls as regards job opportunities.

That code looks very similar to chip assembly code so i can kinda work out what's going on.
In the second set of code a variable is set to '1'.
The loop then increments the variable by 1
When the variable gets to '101' it breaks the loop

Seltzer 08-31-2009 08:49 PM

I haven't done that much batch programming in DOS - I've spent more time doing BASH stuff in Linux. But DOS and batch programming shouldn't be underestimated... Back in high school I was trying to gain access to a local hard drive and there were all these fancy security restrictions in place so that only network drives could be opened. As soon as you opened C in explorer, the window would close and iirc, local drives were protected from basic DOS browsing etc. But I was able to gain access by opening DOS and typing subst z: c:\ which creates a completely unrestricted virtual Z drive mirroring the contents of c:. That's what they get for ignoring low level DOS security.


Dijkstra once said that it's almost impossible to teach good programming to students who have had prior exposure to BASIC and as potential programmers they are mentally mutilated beyond hope of regeneration. Well I hope not because QBasic was my first language. :laughing:

Anyway I'm familiar with C, C#, Java, MATLAB, TCL/TK, SQL, AVR and MIPS assembly. I'm learning C++ now because a guy in my class recommended I apply for a job at the forklift robotics firm where he manages a few interns, and C++ is the lingua franca there. I'd like to learn Python and PHP at some point in the future.

My next personal project is to write a basic operating system but I have no idea when I'll get started because I'm quite busy atm. I'd love to do it for my fourth year project next year so that I have an excuse to spend all my time on it... but knowing the university, they'd sooner have me do choose some unnecessarily academic and pointless project from a pre-defined list. I know I'd learn a hell of a lot more from writing an OS than doing some fruitless vapid Java project.

Guybrush 09-01-2009 01:44 AM

Hehe, I started making a fighting fantasy game in batch (based on the the real thing, Steve Jackson and Ian Livingstone's "The Warlock of Firetop Mountain" from 1982) .. in which you play a character that has certain ability scores, pick up inventory and fights monsters along the way as he progresses through a dungeon.

[img]http//org/1.jpg[/img]

http://g/2.jpg

It's good enough for that at least :D Rather lengthy project though, so many rooms to write (~350)!

Freebase Dali 09-01-2009 12:21 PM

LOL... Tore that's awesome.

I used to do that in QB too.
I remember trying to even do graphic interactions but I could never work out the code right. There used to be all kinds of code snipplets for different functions that I used to scour on the net and try to use, but I think I was setting my goals unreasonably high when I set out to make a Mortal Kombat remake... lol.. Yea that ended up consisting of "press any key to continue..." then a random flash of colors and an odd looking brown formation, then a blue screen.

mr dave 09-01-2009 06:49 PM

Quote:

Originally Posted by toretorden (Post 727876)
Hehe, I started making a fighting fantasy game in batch (based on the the real thing, Steve Jackson and Ian Livingstone's "The Warlock of Firetop Mountain" from 1982) .. in which you play a character that has certain ability scores, pick up inventory and fights monsters along the way as he progresses through a dungeon.

http://l/1.jpg

http://l/2.jpg

It's good enough for that at least :D Rather lengthy project though, so many rooms to write (~350)!

that looks AWESOME!

please please please hook us up when you're done. :thumb:

Guybrush 09-02-2009 03:11 AM

Quote:

Originally Posted by mr dave (Post 728147)
that looks AWESOME!

please please please hook us up when you're done. :thumb:

Haha, thanks! If I ever finish it, I will :D

The reason I'm making it is I played that game in it's book form when I was a kid and I recently found it again on a flea market, but the book was badly tattered. Every time I look in it, more pages come loose, so why not write it up as a game instead?

This is the book!

http://homepages.tesco.net/~parsonsp...images/ff1.jpg


All times are GMT -6. The time now is 10:51 PM.


© 2003-2024 Advameg, Inc.