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

mr dave 09-02-2009 03:45 AM

i don't remember that specific book but i do remember playing at least one of their books back in the day too. i wonder if publishers still put out crazy 'choose your own' adventure books...

HOLY CRAP new version in 3 weeks haha

Warlock of Firetop Mountain: Amazon.ca: Steve Jackson, Ian Livingstone: Books

Guybrush 09-02-2009 04:06 AM

Wow, what a strange coincidence! If they're republishing the others in the series, I guess I might just buy them. I find the games funny still :p

mr dave 09-02-2009 04:46 AM

haha yeah it doesn't seem like something many others are doing anymore. i remember having some cool robin hood books like that too.

i even had some cool ninja adventure book that just ended. no climax no final battle. just you're at level 3 in the dungeon now and nothing. not even an advertisement for another book in the possible series. it was really cool until that point but so lame at the same time.

Seltzer 09-02-2009 06:13 AM

Wow that looks like an ambitious project! Text RPGs were a bit before my time (the Baldur's Gate series was the pinnacle of my childhood gaming) but I'd be keen to see the results if/when you're finished.

Engine 10-17-2012 08:46 PM

I don't know if this is the right place to post a question I have, but I didn't want to start a new thread.
Can anyone tell me how to write php script that essentially does everything that the MB polls do? Display voting options, then retrieve and display results?

Guybrush 10-17-2012 11:43 PM

Quote:

Originally Posted by Engine (Post 1241442)
I don't know if this is the right place to post a question I have, but I didn't want to start a new thread.
Can anyone tell me how to write php script that essentially does everything that the MB polls do? Display voting options, then retrieve and display results?

Perhaps you can find one on the net somewhere?

What's it for? Are you writing your own website from scratch using php?

Engine 10-18-2012 12:19 AM

Quote:

Originally Posted by tore (Post 1241473)
Perhaps you can find one on the net somewhere?

What's it for? Are you writing your own website from scratch using php?

I'm sure I can find examples of what I need in online tutorials and such but I thought to ask here because I'm sure it's a simple thing for some of you. I'm only semi-literate in php but I understand how it works.
I'm in a class learning to create a database and I'll use more than php for that. This php script I'm writing is just a preliminary exercise and I realized that the polls here are doing exactly what I need to make mine do. And they look more elegant than what I would come up with on my own.

Engine 10-19-2012 12:12 AM

No help?
Freebase, I'm sorry I called you all those names and stuff.
I know you can write the code I want in 5 - 10 minutes. Be your best friend? :o:

Guybrush 10-19-2012 12:32 AM

Although I'm somewhat familiar with php, combining that with database stuff is something I've never done before so I'm not much help. I'd be interested in seeing the answer, though.

If you need a die roller in batch, I'm your man.

Engine 10-19-2012 12:49 AM

Quote:

Originally Posted by tore (Post 1241810)
Although I'm somewhat familiar with php, combining that with database stuff is something I've never done before so I'm not much help. I'd be interested in seeing the answer, though.

If you need a die roller in batch, I'm your man.

I've done that!

Quote:

<html>
<head>
<title>Roll the Dice</title>
</head>
<body>
<h1>Roll The Dice</h1>
<form action="dice.php" method="GET">
<p>How many dice?</p>
<input size="4" name="Number">
<input type="submit" value="Roll the dice!">
</form>
<?
$number_of_dice = $_GET['Number'];
if ($number_of_dice) {
$count = 0;
while ($count < $number_of_dice){
$dieroll=rand(1,6);
print "<p>$dieroll</p>";
$total=$total+$dieroll;
$count++;
}
print "Total = $total";
}
?>
</body>
</html>
If you want, I'll show you the voting app once I figure it out. But I assure you it will look like shit compared to an MB poll.

Zer0 10-19-2012 05:59 AM

Quote:

Originally Posted by Engine (Post 1241442)
I don't know if this is the right place to post a question I have, but I didn't want to start a new thread.
Can anyone tell me how to write php script that essentially does everything that the MB polls do? Display voting options, then retrieve and display results?

I'm not really that familiar with PHP but it's something that can be done fairly easily in Java.

Are you using MySQL for the database by the way or just Microsoft Access? Here's some info on using PHP and MySQL, showing you how to create database connections and using SQL queries to retrieve information. It might be of some help.

PHP MySQL Introduction

If you haven't already you should also sign up to stackoverflow.com and post your problem there. It's a brilliant resource for finding coding solutions.

Stack Overflow


All times are GMT -6. The time now is 09:25 PM.


© 2003-2025 Advameg, Inc.