idril
New Member
Posts: 15
|
Post by idril on Aug 1, 2006 8:27:31 GMT
REM N,S,E,W DATA 0,2,3,0 DATA 1,0,5,0 DATA 0,4,0,1 DATA 3,5,0,0 DATA 4,0,0,2
DIM A(5, 4) FOR B = 1 TO 5 FOR C = 1 TO 4 READ A(B, C) NEXT C NEXT B
This piece of code above is from an example, with a little edit from my hand. There are five rooms, two left en three right. I am trying to make this game and I hoped to use it, but I do not know how.. - I lost the source of the example. - (Before, I tried to follow an engine tutorial in some QBAsic e-zine, but I found out that is yet too difficult.) For my game code watch below. It does have more locations ofcourse, but I removed them. Because else it is really getting too long and it is already. I think there must be a better wat for all the IF THEN statements and I am hoping one of you could help me out with the map and the IF statements. At this forum I already found some interesting topic about Inventory, so I am going to try to change that. Please try to understand that this is going to be my first game and that I am willing to learn. I have read a lot of tutorials and I hope you can give me ideas for directions.
CLS
PRINT "TestGame" PRINT
REM Start position ROOM = 1
REM Inventory Room 1 BAGS = 0 TICKETS = 0
STATUS: IF (ROOM = 1) THEN PRINT "* At the check-in *": PRINT : PRINT "You and your husband are standing before the check-in. There is a huge ship right if front of you and the only thing that is stopping you from entering the ship, is the man that asks you for your tickets. Behind you are people in line waiting to enter the ship." IF (ROOM = 2) THEN PRINT "* In your room *": PRINT : PRINT "The room is decorated with a bed and a nightstand, two chairs, a painting and a mirror. There are two bags here."
WHATNOW: PRINT INPUT "What now?"; A$ A$ = LTRIM$(RTRIM$(UCASE$(A$))) 'INPUT A$
IF A$ = "LOOK" THEN GOTO STATUS IF A$ = "QUIT" OR A$ = "Q" THEN GOTO AREYOUSURE IF A$ = "INVENTORY" OR A$ = "I" THEN GOTO INVENTORY
IF RO = 1 AND A$ = "LOOK SHIP" THEN PRINT "The ship is really really huge.": GOTO WHATNOW IF RO = 1 AND A$ = "LOOK BAGS" THEN PRINT "They are ordinary travel bags with clothes and other stuff in it for the trip. You search the bags for the tickets, but you can not find them in here.": GOTO WHATNOW IF RO = 1 AND A$ = "GO NORTH" OR RO = 1 AND A$ = "GO SOUTH" THEN PRINT "Metal bars prevent you to go there.": GOTO WHATNOW IF RO = 1 AND A$ = "LOOK BARS" THEN PRINT "The metal bars look very heavy.": GOTO WHATNOW IF RO = 1 AND A$ = "PUSH BARS" THEN PRINT "You push, but the metal bars do not buldge. The other passengers who are waiting in the line look really strange at you.": GOTO WHATNOW IF RO = 1 AND A$ = "GO WEST" THEN PRINT "There are too much passengers there to pass by. You can not go there.": GOTO WHATNOW IF RO = 1 AND A$ = "LOOK PASSENGERS" THEN PRINT "The passengers are all waiting for you to enter the ship.": GOTO WHATNOW IF RO = 1 AND A$ = "PUSH PASSENGERS" THEN PRINT "There is no point in pushing the passengers!": GOTO WHATNOW IF RO = 1 AND A$ = "GO EAST" AND TICKETS = 0 THEN PRINT "As you try to sneak through the check-in without showing your tickets the man quickly stands in your way. He is preventing you to enter the ship without showing him your tickets.": GOTO _ WHATNOW IF RO = 1 AND A$ = "GO EAST" AND TICKETS = 1 THEN PRINT "You must give the tickets to the man.": GOTO WHATNOW IF RO = 1 AND A$ = "TALK TO HUSBAND" AND TICKETS = 0 THEN PRINT "You: Honey, do you know where the tickets are? I can not find them.. Your husband: Yes dear, you gave them to me. Your husband gives you the tickets.": TICKETS = 1 AND TALKTOHUSBAND = 1: GOTO WHATNOW IF RO = 1 AND A$ = "TAKE BAGS" AND BAGS = 0 OR RO = 1 AND A$ = "GET BAGS" AND BAGS = 0 THEN PRINT "You take the bags, they are very heavy.": BAGS = 1: GOTO WHATNOW IF RO = 1 AND A$ = "DROP BAGS" AND BAGS = 1 THEN PRINT "You drop the bags and are very relieved.": BAGS = 0: GOTO WHATNOW IF RO = 1 AND A$ = "GO EAST" AND TICKETS = 2 AND BAGS = 0 THEN PRINT "You do not have your bags.": GOTO WHATNOW IF RO = 1 AND A$ = "GO EAST" AND TICKETS = 2 AND BAGS = 1 THEN PRINT "You and your husband enter the ship and go to your room.": RO = 2: GOTO WHATNOW IF RO = 1 AND A$ = "GIVE TICKETS" AND TICKETS = 1 THEN PRINT "You give the tickets to the man. The man says: Thank you, you may now enter the ship.": TICKETS = 2: GOTO WHATNOW IF RO = 1 AND A$ = "SHOW TICKETS" AND TICKETS = 1 THEN PRINT "You show the tickets to the man. The man says: Thank you, you may now enter the ship.": TICKETS = 2: GOTO WHATNOW IF RO = 1 AND A$ = "LOOK TICKETS" AND TICKETS = 1 THEN PRINT "These are the tickets.": GOTO WHATNOW IF RO = 1 AND A$ = "LOOK TICKETS" AND TICKETS = 0 OR RO = 1 AND A$ = "LOOK TICKETS AND TICKETS = 3 " THEN PRINT "You do not have the tickets.": GOTO WHATNOW IF RO = 1 AND A$ = "GIVE TICKETS" AND TICKETS = 0 OR RO = 1 AND A$ = "GIVE TICKETS AND TICKETS = 3 " THEN PRINT "You do not have the tickets.": GOTO WHATNOW IF RO = 1 AND A$ = "SHOW TICKETS" AND TICKETS = 0 OR RO = 1 AND A$ = "SHOW TICKETS AND TICKETS = 3 " THEN PRINT "You do not have the tickets.": GOTO WHATNOW
IF A$ = "" THEN PRINT "Why are you so quiet?": GOTO WHATNOW ELSE PRINT "I do not understand you. Please try again.": GOTO WHATNOW
INVENTORY:
PRINT PRINT "You are now carrying:" IF BAGS = 1 THEN PRINT "- two very heavy bags"; IF TICKETS = 1 THEN PRINT "- two tickets"; IF HOTELKEY = 1 THEN PRINT "- a key"; IF BAGS = 0 AND TICKETS = 0 OR BAGS = 0 AND TICKETS = 2 THEN PRINT "- nothing"; PRINT PRINT "Press any key to return to the game." PRINT DO SLEEP 1 LOOP WHILE INKEY$ = "" GOTO STATUS
AREYOUSURE:
INPUT "Are you sure you want to quit the game?"; AREYOUSURE$ AREYOUSURE$ = LTRIM$(RTRIM$(UCASE$(AREYOUSURE$))) IF AREYOUSURE$ = "NO" OR AREYOUSURE$ = "N" THEN GOTO STATUS IF AREYOUSURE$ = "YES" OR AREYOUSURE$ = "Y" THEN GOTO THEEND IF AREYOUSURE$ = "" THEN GOTO AREYOUSURE ELSE GOTO AREYOUSURE
THEEND:
PRINT PRINT "This is the end of the game." PRINT "Thank you for playing."
|
|
|
Post by Ildûrest on Aug 1, 2006 13:42:38 GMT
The problem with writing these kinds of games in QBasic is that they don't do much to increase your knowledge. The reason is that you can get away with using simplistic methods (at least until the game becomes so large that you lose the determination to finish it).
Firstly: NEVER use GOTO. While it is occasionally the most practical solution, this is extremely rare. I estimate that I write about 300 DO-LOOP/FOR-NEXTs for each GOTO I use.
Secondly: You need to get a better grasp of basic programming structures.
I see you've already mastered IF <condition> THEN <action>
But there's a multi line version too.
IF <condition> THEN <action(s)> <action(s)> <action(s)> END IF
You can also add other options to them, that get checked if the first condition is false...
IF <condition> THEN <action(s)> ELSEIF <another condition> THEN <action(s)> ELSEIF <yet another condition> THEN <action(s)> ELSE <action(s)> END IF
The above will save you having to use GOTOs... if one condition is satisfied, its actions are executed then everything else until the END IF is skipped.
And you clearly want to nest them.
IF RO = 1 THEN IF A$ = "PUSH PASSENGERS" THEN ... ELSEIF A$ = "PUSH BARS" THEN ... ELSEIF A$ = "DROP BAGS" THEN ... ELSE PRINT "What was it you wanted to do?" END IF
But there's an even better improvement. Go find SELECT CASE in QB help.
Once you've digested all that, it's time for me to tell you that your approach STILL is simplistic, and will strangle your game if it gets much larger. So for now, save the game ideas, and once you become more proficient at this art, maybe you'll make a wondrous game.
You'll probably want something else to practise your programming with, then. I suggest something a little easier to finish, and once finished easy to go back and improve. Like these:
-Make an X fly around the screen. You'll need LOCATE here. Once you've make it move, can you make it bounce off the walls?
-Write a program that opens a file, asks you your name, checks if your name is in it, and if not, writes your name to the file. You'll need to use the OPEN command for this.
-Write a program that displays every letter of your name with a different colour. MID$ will be very helpful here. COLOR as well.
These should be fairly challenging, and will probably require you to have a bit of a read of QB help. There may be a few places where you'll get quite stuck, so feel free to come and ask for assistance. Although DO check QB help first.
Hope to see you soon!
-Ildûrest
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 1, 2006 14:22:37 GMT
Hi Ildûrest!
Thank you for your advice.
- I did not know that GOTO is not good to use. So far the .bas I have seen all used them, maybe I do not have the right ones. What I did know is that multi line version of yours. But it made my version even longer in lines. - What do you mean with "nest"? You mean to put the ROOM=1 all together as you did in the example? (As you might have guessed, my orginal language is not English but Dutch.) - And I already have seen programs with SELECT CASE statements and I am familiar with it. I do not see why they are very different than IF THEN statements.. Could you give me some help with understandig why they are different in your opinion?
SELECT CASE:
WHATNOW: PRINT INPUT "What now? "; A$ A$ = LTRIM$(RTRIM$(UCASE$(A$)))
SELECT CASE A$ CASE "LOOK": GOTO STATUS CASE ELSE: PRINT "I do not understand you, please try again." END SELECT As for your last texts, I am not interested in doing any graphics at all but I am Really interested in textadventures.. I have written them in Flash, Ruby and JavaScript before. To make these games interest me very much. A friend of mine told me about QBasic and I decided to give it a try.
Therefore I will not take your advice in the ideas to get more knowledge in QBasic, only if I see that it progresses my text game. However, there is this file load and save thing that I would like to check out and I will make notes of your advice and rewrite. Because I would like to learn more if that improves my text adventure(s). And I would love it when someone could help me with the code above my intro text. I think that changes it all..
EDIT: Maybe I am too fast with my answer and will these challenger do me good.. Okay, I am starting with them if you think it helps.
|
|
|
Post by Ildûrest on Aug 1, 2006 23:44:30 GMT
Well, your English is too good to tell that you speak Dutch. And I took you for a young person who'd recently discovered programming and got over-enthusiastic about a game.
Now my understanding is a bit better.
Anyway, you're into text adventures, so let's talk text adventures. Well, I'll get the truth out of the way first: One of the best ways to write a text adventure is with something called the Text Adventure Development System (www.tads.org).
If that's what you want, I'll understand. Nice meeting you.
If you're still interested in BASIC, then I'll tell you how the basic structure of a scalable (I.e. you can enlarge it without greatly increasing its complexity) text-adventure would look like.
The last exercise I gave you ("Write a program that displays every letter of your name with a different colour. MID$ will be very helpful here. COLOR as well.") was actually quite relevant. The point is to 'cut up' a piece of text into smaller bits.
This is how you need to process user input. You look for keywords, like LOOK, TAKE, PUSH, etc. Then you look at the objects they refer to. Does such an object exist in your inventory or the current location? If so, does the action apply to it? If so, execute the action!
If you treat each of those steps individually, you can make something really quite flexible. You can make GET, TAKE, PICK UP, all cause the same thing to happen, without having to retype the "what happens" part over and over. You can give objects multiple names (desk, table; floor, ground). And it becomes much easier to load your data from a file. In fact I would load EVERYTHING from a file.
The choice is yours to make. If you want to actually get into the pulsating heart of a text adventure, and have fun programming, then you're welcome to stay around. TADS will give you a well-running text adventure quite quickly, and all the working out actions has already been done.
(If you choose to stay, I'll answer all your other questions.)
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 2, 2006 6:30:31 GMT
There are versions of TADS, Inform and Hugo on my computer. Recently I deleted Alan. I played with it for some time, but came to understanding that I want someting else. Maybe something more, like making small games in it. So now I try to understand programming languages, because than you can create more possibilities. It is not going that fast, but I do not mind because this is a hobby to me to learn how to program. As I am a girl this may sound strange, but I think it is much fun. As for my age, I am currently 23 but I think that is still young enough to learn. I have been to a webdesign school and there I learned more about designing and programming for the internet. Now I would to like some other lanuages as well. Text adventures remind me of my old Commodore and I have played them a lot. I would love to make them in all kinds of program languages, so I started. I will make the examples and post them here when ready. If you would like to help me further in programming a good text adventure in QBasic, I would very much appreciate. Maybe you or somebody else of this forum knows how to start by 'giving' me more such challenges after I finished these. EDIT: 2: SCREEN 12 CHALLENGE2: CLS PRINT OPEN "names.txt" FOR OUTPUT AS #1 INPUT "What is your name? ", NAMES$ PRINT #1, NAMES$ CLOSE #1 IF NAMES$ = "" THEN GOTO CHALLENGE2 ELSE OPEN "names.txt" FOR APPEND AS #2 PRINT "Your name is now in the file! Go check it out." CLOSE #2 END IF PRINT PRINT "These names are now in the file:" OPEN "names.txt" FOR INPUT AS #3 INPUT #3, NAMES$ CLOSE #3 PRINT NAMES$ END 3: SCREEN 12 CLS LOCATE 10, 31 COLOR 1: PRINT "I" LOCATE 10, 32 COLOR 2: PRINT "D" LOCATE 10, 33 COLOR 3: PRINT "R" LOCATE 10, 34 COLOR 4: PRINT "I" LOCATE 10, 35 COLOR 5: PRINT "L" END 3a: CLS NAME$ = "Idril" COLOR 1 PRINT MID$(NAME$, 1, 1); COLOR 2 PRINT MID$(NAME$, 2, 2); COLOR 3 PRINT MID$(NAME$, 3, 3); COLOR 4 PRINT MID$(NAME$, 4, 4); COLOR 5 PRINT MID$(NAME$, 5, 5); END Hmm, I am still working on 1. Come to think of it, I never moved something in code before.
|
|
|
Post by Ildûrest on Aug 2, 2006 10:09:24 GMT
Well, you've got the enthusiasm and willingness to have a go, it seems. Your code is not optimal but that's why you're here In any case you're better than many people who have tried to learn to program. Now, we must break this habit of GOTOs and, more importantly, what I will call 'narrow programming'. There is nothing wrong with using GOTO except that its alternatives are MUCH easier to understand when your program gets larger. (Believe me!!!) 'Narrow programming' is a different matter. What I mean is putting too much emphasis on the end result, without allowing for broader methods that are actually better in the end. It's like writing a program to calculate how much tax you pay on an income of $60,000... rather than writing a program that asks you your income and then calculates the tax on it. The first example only helps you for as long as your income matches that amount. The second one is a lot more useful, and only slightly more complex. I think this will convince you: SCREEN 12 LOCATE 10, 31 COLOR 1: PRINT "I" LOCATE 10, 32 COLOR 2: PRINT "D" LOCATE 10, 33 COLOR 3: PRINT "R" LOCATE 10, 34 COLOR 4: PRINT "I" LOCATE 10, 35 COLOR 5: PRINT "L" END
compared to SCREEN 12 Name$ = "IDRIL" FOR I = 1 TO LEN(Name$) LOCATE 10, 30 + I COLOR I : PRINT MID$(Name$, I, 1) NEXT END
BENEFITS: -It's shorter -You can change "IDRIL" to something else and it'll still work -You can make it display on line 12 instead, by only modifying one line -You can actually ask someone for their name with INPUT and display that. While it won't ALWAYS be shorter the 'broad' way, it'll always be easier to modify and you'll probably use less code in the end. (Because even though a single part is longer, you can use it more times over.) Now to a few other matters: Nesting is placing one thing inside another (I'm not quite sure why). SELECT CASE is computationally a bit faster, and is also easier to read and tends to use less space. If you've seen GOTO in tutorials or programs you're looking at out of date tutorials or programs. My aleks.budzynowski.info/host/MATRIX.BAS is pretty impressive, I think, and doesn't use GOTO. Instead use FOR-NEXTs, DO-LOOPs, multi-line IFs, and the occasional EXIT DO / EXIT FOR. LASTLY... In terms of my file reading challenge: I see you figured out OPEN FOR APPEND and OPEN FOR INPUT... To get closer to the goal: First open the file FOR APPEND and CLOSE it again. (This ensures the file exists (creates it if it doesn't), otherwise if you try to OPEN FOR INPUT you get an error if the file is not there.) Then get the user's name. Then open the file FOR INPUT, and use one of these: DO UNTIL EOF(1) LOOP This keeps repeating till you reach the end of the file (in conjuntction with an INPUT #1) And you check each line of the file against the inputted username. If you do not find it (Let's suppose you END if you do find it, so once you leave the loop you can assume you've not found it), you add it by closing and opening FOR APPEND. Try that. Good luck.
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 2, 2006 10:59:52 GMT
Yes, the method as coded by you is shorter and that is better. So I guess that "I" is a repeat code? *Is going to look that up* I believe you on the GOTO thing, but if I do not know another code for it, I am afraid I will use it. Anyhow I will go and look for alternative ways. Hmm, it is true that I did not check if the name was already in the file, I am going to change that.. But if you run the file without having names.txt in the folder the program writes a "NAMES.TXT". Is it still necessary to check if the file exists? *hops onto work again*
|
|
buff1
New Member
Posts: 3
|
Post by buff1 on Aug 2, 2006 14:36:25 GMT
The problem with GOTO is not that the should not be used. It has it's place. The primary problem associated with GOTO are:
It's unconditional. It goes to the routine or line no matter what. This can lead to what is commonly referred to as spaghetti code.
My rule on using GOTO is that it : should be used as infrequently as possible. Should only be used within a routine and not to jump to another routine. i.e. should not be used to go from a gosub/return to another part of the code bypassing the return.
|
|
|
Post by Ildûrest on Aug 3, 2006 5:49:04 GMT
Yes, the method as coded by you is shorter and that is better. So I guess that "I" is a repeat code? *Is going to look that up* Wow, you're behind. Read this bit from a tutorial I'm working on: aleks.budzynowski.info/wiki/quickbasic/tutorial/chapter1#loopsThat should help you use GOTO less as well. But if you run the file without having names.txt in the folder the program writes a "NAMES.TXT". Is it still necessary to check if the file exists? Ok. The program you wrote does not do what it should be doing. Start again and follow my advice. OPEN FOR APPEND creates files if they do not exist. OPEN FOR OUTPUT does the same, except if the file DOES exist then its contents are deleted. (This program is supposed to work over many RUNs so you do not want old names to get deleted!) Let me expand a bit more: EOF(1) is TRUE when you've reached the End Of File 1. (EOF = End Of File) So DO UNTIL EOF(1) .... LOOP lets you read and analyse every line in the file. Now try again. Good luck!
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 3, 2006 8:09:00 GMT
@ buff1 : Add on information is always interesting. Merci. @ Ildûrest : Thank you for your tutorial link. And I think I understand what OPEN FOR APPEND does, it adds info. In the beginning I started with writing an inventory in it (watch below), but I did not know how to go further with it further. CLS OPEN "inventory.txt" FOR APPEND AS #2 CLOSE #2 PRINT "Inventory:" PRINT OPEN "inventory.txt" FOR INPUT AS #1 LINE INPUT #1, INVENTORY$ CLOSE #1 PRINT INVENTORY$ EDIT: I just updated the code above with this I thing to understand better. CLS PRINT "Inventory:" PRINT OPEN "items.txt" FOR OUTPUT AS #1 'maakt of overschrijft een bestand CLOSE #1 'sluit bestaat 1 'voegt dingen in bestand toe: OPEN "items.txt" FOR APPEND AS #2 PRINT #2, "zwaard" PRINT #2, "boek" PRINT #2, "mantel" CLOSE #2 OPEN "items.txt" FOR INPUT AS #3 I% = 1 'maakt variabele met waarde 1 DO WHILE NOT EOF(3) 'loopt tot het einde van bestand 3 LINE INPUT #3, ITEM$ 'line input leest een volledige lijn PRINT ITEM$ I% = I% + 1 'voegt +1 toe om de goede lijn te krijgen LOOP 'eindigt de loop, gaat naar het begin en loopt opnieuw CLOSE #3 'sluit bestand 3 END
|
|
|
Post by Ildûrest on Aug 3, 2006 9:32:56 GMT
Two quick comments: After you've closed a file number, you can use it again. I.e.
OPEN ... FOR APPEND AS #1 CLOSE #1 OPEN ... FOR INPUT AS #1 CLOSE #1
is fine.
The other thing I have to say is you don't need to OPEN FOR APPEND in your second example above. OPEN FOR OUTPUT lets you write to the file as well, it just replaces anything that might have been there already. So just OPEN FOR OUTPUT, then write to the file with PRINT #1, and then you can close the file and OPEN FOR INPUT.
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 3, 2006 10:10:31 GMT
Okay. Understood I think. :-) Serveral hours later.. I think I am going crazy here. This is what I have so far: CLS file$ = "names.txt" 'maakt variabele van bestand
OPEN file$ FOR APPEND AS #1 'opent het bestand of maakt er een CLOSE #1 'sluit bestand 1
PRINT PRINT "These names are now in the file:" PRINT OPEN file$ FOR INPUT AS #1 DO WHILE NOT EOF(1) LINE INPUT #1, A$ PRINT A$ 'IF dataline$ = "" THEN END 'IF NOT dataline$ = "" THEN PRINT "blaat"; dataline$ LOOP CLOSE #1
PRINT OPEN file$ FOR APPEND AS #1 INPUT "What is your name? ", NAME$ IF NAME$ = "" THEN END IF NAME$ = A$ THEN PRINT "Yahoo." PRINT NAME$ WRITE #1, NAME$ CLOSE #1
'search OPEN file$ FOR INPUT AS #1 l = 0 DO UNTIL EOF(1) l = l + 1 LINE INPUT #1, LINE$ 'read a line from the file IF LINE$ = NAME$ THEN PRINT "The name is already on the list." 'ELSE PRINT "You name is not on the list." LOOP CLOSE #1
END I do not know how to make a variable from one line in the file and so much more.
|
|
|
Post by earlofqb on Aug 3, 2006 19:35:09 GMT
Use the Write statement. Check the QB help menu for more information. You're learning quite well. Don't lose hope. In fact, you're actually almost at the point where I'm at with my programming skillz (fortunately for us all, college should kick my skills up a notch or two). The Global Loop (sometimes referred to as Main Loop, or Game Loop) is the primary bit of programming logic related to programming games. Basically (in QB style, of course): Do Until EndGame = CHR(27) 'Or something like that. Basically, do until the user presses Esc key 'some code, for your game. Stuff like setting up the characters, graphics, logic, etc EndGame = Inkey$ Loop End The game will execute so long as the user doesn't press the Escape (Esc) key. Obviously, the way I did it wasn't "proper programming practice", however it works well enough for our purposes Programming takes a lot of time and effort. I've been using QBasic for nearly 18 months now, and am still learning a lot about it (although it'd probably help if I wasn't so distracted by things like my job and developing my game in VB.NET (sorry Ildurest, I know how much you despise it, but it works for me)). Ildurest is certainly the resident QB programmer, and could probably teach a few professionals some tricks. I'd recommend picking up whatever QBasic books you can find (there's very few left, but they do exist), and pick up some general programming books also (try to stay away from C++ -oriented books for now. They'd be much too confusing for you. Visual Basic (the very thing Ildurest claims is rotting people's minds daily) would be a place where you can get some general purpose programming skills. Visual Basic is based off QuickBasic (which QBasic was based off of), so the logic is very similar (except where Object-Oriented Programming is required, such as in user interfaces)). You're learning very quickly and show a real enthusiasm for programming. There's an old axium I subscribe to: so long as you keep trying, you never fail. Don't give up on wanting to learn how to program. It might take you a little while, however eventually we all get the epiphany moment (aka the "aha! moment"). Ildurest is the best teacher around, and he's extremely patient (unless you decide to start programming in Visual Basic, wherein he'll pretty much refuse to acknowledge your presence ). You've found (IMHO) the best place around for learning how to program (in virtually any language, but mostly in QBasic)... period. Text adventures are quite fun to program, however your style isn't practical. For instance: When you prompt the user for input, you don't list what available actions are... well.. available. The user has absolutely no idea what actions they can take, unless they've played the game for years (or designed it). I'd recommend something like: Print "{action 1}" = 1 Print "{action 2}" = 2 'etc Input A$ 'Use Select Case, it's more efficient Select Case A$ Case 1 'Actions for option 1 Case 2 'Actions for option 2 'etc I'd not really worry about the room. A good game should have global options which'll appear throughout the prompts, and room-specific options which'll appear in the appropriate room. Thus, you'll have to use a subroutine or (in higher languages, that are OOP) classes (languages like these are outside the scope of your game. In other words, classes are something you won't have to worry about for a while). In each room, you'd call the GlobalOptions subroutine (or whatever you decide to call it), where it'll display the options and make them available for your use. All you'd have to do (to program the individual rooms) is to remember exactly how many options were in your GlobalOptions subroutine (or use a 3-digit number. With the first number corresponding to the room/global option (ie 0xx for global option, 1xx for first room, etc), and the other two numbers referring to the option (ie 288 referrs to the 88th option for room # 2)). That should make scalability a relatively simple thing (need to add more options to a list? Just add another option to the list. If you're worried about alphabetical order, consult a software engineer (the folks who get paid big money to organise a piece of software before developing it). I'd recommend taking the "software engineer approach" to your next program (write down what all you plan to put in the program. Let it sit for a day or two. Come back to it and write down any new ideas you get or erase old ones)). Rather than use GoTos and GoSubs, call a subroutine (rather bothered me Ildurest wanted to play a game of "wait and see" with you. It works well if the person catches on after a while, however after several days, it's better to instruct the person than to tease them along with "you'll think of alternate methods"). For instance, when you check the items, use: Call Inventory(Bags, Tickets, HotelKey) 'Copy your code from the Inventory "subroutine" you programmed. This works a lot better because, in the editor, it is a separate section (meaning you're focused only on it, and little else). Further, it logs in all the information at once into the subroutine (I didn't see any information exchange in your example. I've a thought that if you executed your game as you typed it in here, it wouldn't run), making comparisons easier. Now, as to the mess of your "rooms and options" block (where you have "If room = 1 and A$ = "look", etc), I'd use the above method of separating the rooms into subroutines, and setting the options into subroutines as well (the is partly Object-Oriented Programming, however I've a feeling you won't be terribly lost by the concept. Basically, we're separating everything into different parts so that we can better manage it all). Then, when you load the game, set the room to 0. Then call some subroutine which'll read what room you're in, and load that subroutine. In each room's subroutine, you'll load a global subroutine which'll hold all the information associated with the character (such as what's in the inventory, how many turns have been taken (if turn-based game), the options available in all the rooms (ie look, go, etc), etc). Then, you'll load the information specific to the room (ie if you've specific options available, specific tasks available, etc). Movement should be it's own subroutine as well, however this is where I'll stop. I've a feeling I've confused you, and that's okay. Personally, it took me months just to understand the basic ideas behind game programming, and you can't be expected to get it all at once. I'll list some game programming websites, and stop for now. gpwiki.org/index.php/Game_Programming_Wiki -The Game Programming Wiki, a very good site for some basic ideas behind game programming. www.htdp.org/ -How To Design Programs site, the basics of software engineering www.gamesbasic.com/portal/index.php -GamesBasic, a flavour of Basic designed solely for programming games. Note: none of us (that I'm aware of) have any experience with this. I listed this as an idea for the future. It's still best to learn in QBasic, as we've all experience with it. Rather than using all caps for your variable names (yes, I know it seems spiffy, to differentiate your variables from your statements by making them all capitals), use Camel Case (example is in the word, "Camel Case". It's where you capitalise the first letter and leave the rest small). Use all Caps only for constants (that practice is going out of style. The new standard is to use c_VariableName to denote a constant). I'd also get in the habit of prefixing your datatypes onto your variables, however I'll get to that whenever you need it (right now, you're fine with your system of doing things). One final note, a few examples: Get in the habit of writing subroutines and using subroutine calls. Thus, the "example" is to write a program using entirely subroutines (ie the main module consists of a remark stating who the author is, a few subroutine calls, and an end statement) Get in the habit of using loops and subroutines rather than GoTos. Thus, the "example" is to rewrite one of your programs (print out the old one and start a new program. Rewrite it from scratch (don't copy anything, just look and emulate it in your new code), and test the program) using loops and subroutines rather than GoTos. Get in the habit of positioning text all over the screen. The example is to write a piece of code where you position some text all over the screen. After you're done with that, set a loop where you simply run through the loop to print the text. This'll teach you the limits of QB's printing abilities and set you up with simplifying your code. Finally, if you want more practice, put it all in different colours like Ildurest suggested before. Being able to position text precisely where you want it will come in very handy with your game. Practise reading and writing data to a file (basically, the same stuff you've been doing, but get creative with it). Get creative with sound. Write a program or two where you just mess around with the sound commands. This'll prove useful whenever your game needs to alert the user to a problem (some people don't notice text too well, and putting it in a bright colour won't help colour-blind people). Write a program that'll relieve stress and/or provide a laugh. Learn that programming can be as relaxing as it is challenging. My favourite program is a simple delayed reaction program, where you input a math problem and it'll display the answer to the previous one. It's rather enjoyable in that I find it amusing that I can program a computer to respond improperly to logic. Some other ideas include a "Earl Must Die" program (where you write, all over the screen, "Earl must die!". I don't mind if you use my name, and it should provide some relief to a stressed mind (telling you all that about object-oriented programming would make anyone want me dead). If you worry someone else named Earl might see the program and take offense, write "Earl Roger Euradere (of Levitt, Alberta, Canada) must die!" (I rather doubt someone else named Earl Roger Euradere lives in the same town I do, so you're safe here, so long as you don't actually fly to my town and wish to kill me)). You could also write some strange program to give to a friend (I'll never forget the one program I wrote, which simply said "32r1 pwnd j00, -/_", which translated, means "Earl pwnd you Z". It is a reference to my former girlfriend's poor programming abilities (let's face it, the world probably would've been better off without her learning how to infect my computer with an infinate loop of the Numa Song)). I've rambled on enough for that one, with one important little idea: try to get some of your friends interested in programming. Of course, don't force it on them either. One of my least favourite things to see is someone I know who won't stop droning on and on about some perverse (and I do mean perverse. This stuff could be listed as xxx material in some provinces) anime she found online (if you're bloody going to look at pr0n, look at it! Don't involve your ex-boyfriend in it, you bugger!). So, try not to be annoying and drone on about programming like she does about anime, but see who's interested. You'd be surprised how many people enjoy the prospect of controlling a machine which has seemingly enslaved them (Z especially liked that idea. Unfortunately, that control spread to other aspects of her life ), or about extending the functionality of preexisting programs. There's plenty of ideas for programs out there. I keep a notepad with me all the time so I can write down ideas for new programs. Sure, a lot of them have been done, but I use them for teaching purposes. First, I'll program it the "easy way" (simple structure, etc. You're basic "narrow-minded program"), then I'll re-do it the "hard way" (check the help for functions and keywords which'll simplify the structure, add some features to it, etc). Most of my programs are terrible, however they've all taught me something or another about programming. Sorry for droning on myself, however there's a lot to respond to, and my Internet's been dead for the past hour (lots of time to look in my books for ideas on what to comment on).
|
|
idril
New Member
Posts: 15
|
Post by idril on Aug 4, 2006 9:27:22 GMT
*Woot* I think I have done it. Without using GOTO. You do not want to know how many test files I have used to make this.. Also, I tried to use less tutorials, but find out myself. Well, that takes some time, but now the second version is done. Hopefully, in time, I become quicker in this. Please tell me what you think of it. I very much appreciate your help. ;D Challenge 2 - Version 2: SCREEN 12 CLOSE CLS file$ = "NAMES.TXT" OPEN file$ FOR APPEND AS #1 CLOSE #1
PRINT PRINT "These names are now in the file:" PRINT OPEN file$ FOR INPUT AS #2 DO WHILE NOT EOF(2) LINE INPUT #2, a$ PRINT a$ LOOP CLOSE #2
PRINT OPEN file$ FOR APPEND AS #3 INPUT "What is your name? ", Name$ Name$ = LTRIM$(RTRIM$(UCASE$(Name$))) IF Name$ = "" THEN END CLOSE #3
FindString$ = Name$ OPEN file$ FOR INPUT AS #4 DO WHILE NOT EOF(4) LINE INPUT #4, a$ Lines& = Lines& + 1 IF INSTR(1, a$, FindString$) > 0 THEN PRINT PRINT "Your name is already in the file." PRINT "The name is found it at line "; Lines& PRINT "This program will now end. Goodbye!" END PRINT END IF LOOP
PRINT "The name is not found." CLOSE #4 OPEN file$ FOR APPEND AS #5 WRITE #5, Name$ PRINT "Your name is now written to the file." PRINT CLOSE #5 PRINT "Thank you for using this program."
CLOSE END And I see that there is a long reply above; which I am going to read right now! So beware of the edit in this message in a couple of minutes. EDIT: Okay, it took me some minutes than I thought. Here we go. @ earlofqb : Thank you for all your information. It is a lot, but that is okay, I like it!! As you can see I have used the WRITE statement in the challenge version 2. If that is what you mean? Haha, I do not think I am at the same point as you but much more below. Like doh. Usually I do not go to deep in languages (well, besides ASP, PHP and JavaScript as I have done a webdesign school). But this time I would like to do it right and this language looks very interesting and learn-able. Instead of DO UNTIL I found out that you could also use DO WHILE. That way, I did not have to use these GOTO things. Well I am sure it could be done otherwise, but I will wait and see other people their comments on it. You wrote "Programming takes a lot of time and effort". So true. Ever since I started with webdesign, everytime I totally forget how long it takes to create something. And it takes even longer to edit. But that is okay if you learn. At least, I think so. I also believe that this forum is a good option. For a while I have been reading Pete's QBasic Site's, QBasicnews's, QBasic.com and QBasic.at's forum but I did not post because I think these forums are too large. I feel more comfortable to post here. There is a "Learn how to programm for Dummies" in Dutch and I have bought it. There is some information on QBasic in it, but not enough. Most of the time I try to read standards/statements and puzzle from there. I think I will let the text adventure rest for a while. As I am aware that there might be more basics to know before I can give it a good go. And that will be my goal from now on. If you have got a good challenge for me (text adventure based), than that will be more than welcome! I am not so good in thinking how little pieces of a game in little programms should look like. (< Not sure this sentence is a good translastion of what I have in my mind.) Just a quick note: You said "I've a thought that if you executed your game as you typed it in here, it wouldn't run". But I test everything I code and it runs fine. As for the Variable names.. When I have seen that Ildurest did not used them, I did not used them in my next version. So I am trying to watch and learn. Reading yoor "Earl Must Die" text is making me laugh, ofcourse I do not want good teachers to be gone, I enjoy this too much. And than your final note where I see that there are 'challenges' hidden in it. Thank you very much for them, you are a good inspiration source.
|
|
|
Post by earlofqb on Aug 4, 2006 17:08:27 GMT
What I meant by the statement "your code might not execute", was that the way you typed it did not allow data to be passed to what I can only presume to be a subroutine (I'm definately not used to GoTos. Even a GoSub would've been clearer for me. If it's meant to be a GoSub, kindly take care to convert it). For example, in your Inventory subroutine, you don't pass any data that will state whether or not you have an item or whatnot. Unless they're all global variables (I didn't see any global declarations, so I presume all code to use local variables), this code wouldn't execute properly (meaning that while it'll display a result, it won't be the proper result. Ie you could be carrying an item, but since the data isn't passed, it'll act as though you're not carrying anything). Software design (thinking how "little pieces of a game in little programs should look like") is an acquired skill. I've only recently begun thinking in terms of software design (you should've seen me try to program the very program which would become the basis of my thesis in my high school QB class. I went through at least 5 dozen revisions because I'd think of a new feature that'd definately improve the program, only to find that the current code wouldn't easily support it (so I'd re-write it from scratch to fix that)). However, it is a skill that will prove most useful later on in life, as you'll save both time and money (if you're paid on a salary basis, you definately don't want to spend hours doing work you won't be paid extra for. If you're paid on an hourly basis, your customers will complain and word will spread that your work is "shoddy" and "poor"). Basically, to get the ideas of software engineering, just do as I'd mentioned in my past post: buy a notepad and write down features for your program. Once you've all the ideas situated, let the notepad sit and work on another project (or do something else, such as go back to work (rather funny story. Basically, I was so caught up in a project that I'd forgotten to go to work. Almost got fired ) or "socially network" (the new-age version of "go out with friends and have fun". Apparantly, nothing sounds "cool" anymore unless it sounds like a computer term)). After a while (a few days or so), go back to the project and look over it. If you can think of new ideas, write them down. Once all new ideas are written, organise the project on paper, and get an idea of how you'll program it. This is where I greatly encourage the use of thinking of a program as a collection of modules (sure, QBasic isn't an OOP language, however the ideas behind it will still work. You just have to modify the style you do it in, is all). Write down how you'll use certain subroutines to perform certain actions (for your game: one subroutine will hold the data for the rooms, another will hold player information, etc). I'll do a quick example of my favourite math game, the "CIP (Computer Incompetancy Program) program" DECLARE SUB Header () '************************* '* * '* Earl Euradere * '* Magic 8 Crew * '* 22-09-05 * '* QBX * '* CIP * '* * '*************************
'Header is a subroutine which clears the screen and displays the title screen
' and REM are equivalent statements, they both mean "Remark" 'The computer ignores remarks. They are only for the programmer to read 'They help the programmer fully understand the program, as the original programmer's notes are often helpful 'It is considered "nice" to remark on any major segment of programming code, or whenever things are complicated or need explained 'It is also nice to remark at the beginning of any functions or subroutines, to explain their purpose.
'Call the Header subroutine, which clears the screen and prepares it for input
CALL Header
REM This program uses "delayed output" to annoy anyone who enters a math problem REM It works by remembering the first answer to a question and storing it. REM On the second question, it calculates the second answer, but prints the first answer REM It then replaces the first answer with the second answer's result, creating an infinate "off by one problem" math engine REM On the first problem, the first "answer" will always be 0. REM Written in modular form, for clarity of code.
REM One giant loop, until the user enters a non-numeric value
REM Dimension the variables
'The DIM statement means "Dimension". This tells the computer to set aside memory for the variables 'This is considered "nice" because back in the early computing age, memory was small, so to not dimension variables would fill the entire memory with one variable 'Now (at least in QBASIC), Dimensioning is only necessary for arrays 'In other languages (including Visual Basic), dimensioning is necessary for all things, as it forces the programmer to think of how much memory the program will use
DIM strNum1 AS STRING DIM strNum2 AS STRING DIM strOperator AS STRING DIM strOperandProper AS STRING
DIM intNum1 AS DOUBLE DIM intNum2 AS DOUBLE
DIM dblAnswer AS DOUBLE DIM dblAnswer2 AS DOUBLE
'Set the program's first answer to be 0
dblAnswer2 = 0
DO UNTIL LCASE$(strNum1) = LCASE$("Exit") 'Until the user enters Exit
INPUT "Please enter the first number of your expression, enter Exit to exit ", strNum1 'Ensure the program actually exits the program
IF LCASE$(strNum1) = "exit" THEN
EXIT DO END IF INPUT "Please enter the operator of your expression ", strOperator INPUT "Please enter the second number of your expression ", strNum2
'Cast (Convert) the case from strings to integer values
intNum1 = VAL(strNum1) intNum2 = VAL(strNum2)
'Make sure that the user entered only numberical numbers into the strNum1 and strNum2 variables
IF ASC(strNum1) < 58 AND ASC(strNum1) > 47 AND ASC(strNum2) < 58 AND ASC(strNum2) > 47 THEN strOperandProper = "Yes"
SELECT CASE strOperator 'Depending on what the user entered in strOperator, it will pick what will happen 'Select Case is equivalent to a large If...Then..ElseIf... (etc)...Else block CASE "+" 'This makes it easier to read and undersand, and far easier to program dblAnswer = intNum1 + intNum2 'Add the answers
CASE "-"
dblAnswer = intNum1 - intNum2 'Subtract the answers
CASE "*"
dblAnswer = intNum1 * intNum2 'Multiply the answers
CASE "/"
IF intNum1 <> 0 THEN
dblAnswer = intNum1 / intNum2 'Divide the answers if the first number isn't 0
ELSE PRINT "Invalid operand in position one. Division by 0 impossible"
EXIT DO 'Exit the loop, and in this program, ending the calculator
END IF
CASE ELSE 'If the user entered an invalid operator (not +, -, *, or /)
PRINT "Invalid operator. Non +, -, *, or / operator"
EXIT DO
END SELECT
ELSE
PRINT "Invalid operad(s). Please enter a number next time!"
SLEEP 3
strOperandProper = "No"
END IF
'If the user entered proper numbers into the program, then print the answer
dblAnswer2 = INT(dblAnswer2) dblAnswer = INT(dblAnswer)
IF strOperandProper = "Yes" THEN
'Display the answer PRINT PRINT "The answer is "; dblAnswer2 SLEEP 3 'This tells the computer to wait 3 clock cycles (roughly 3 seconds) for the user to read the information, before going to the next line of code
dblAnswer2 = dblAnswer
END IF
CALL Header 'Clear the screen and display the header line
LOOP 'Finish the loop
END 'End the program
SUB Header
'This subroutine clears the screen and displays the header for the program
CLS
'Dimension the variables
DIM intLength AS INTEGER DIM intLength2 AS INTEGER
DIM dblLength AS DOUBLE DIM dblLength2 AS DOUBLE 'The LEN function takes the length of a string
intLength = LEN("Illogical Calculator") 'Find the length of the sentence dblLength = ((80 - intLength) / 2) 'Calculate the middle of the screen, adjusting for the length of the sentence
'Find the length of the second sentence (the warning), and calculate the middle of the screen based on the length of the second sentence
intLength2 = LEN("Notice: All numbers must be between -1.798 E 308 and 1.798 E 308") dblLength2 = ((80 - intLength2) / 2) PRINT SPACE$(dblLength); "Illogical Calculator" 'Print the sentence in the middle of the screen PRINT 'Print an empty line for clarity later on 'The limits on a Double-precision variable are near enough to infinity that one needn't actually inform the user 'Still, out of kindness, I did
PRINT SPACE$(dblLength2); "Notice: All numbers must be between -1.798 E 308 and 1.798 E 308" 'Warn the user of entering too large of numbers PRINT 'Print a nice line to separate the header from the program
END SUB
Sorry for boring everyone about that, however the code does show how more efficient Select Case is, and how to put subroutines into a program (although it doesn't pass any data, and it certainly could be enhanced with further subroutines (ie the math part could be a separate procedure)). So, my question to you is, "Can you program something similar to this?". By "similar" I don't mean another illogical math program, but something that displays the same ideas of code clarity and still maintains enough "easy to read"-ness for a beginner to learn from (the CIP program was originally designed to get my brother interested in programming. That's why practically every line is commented). Some ideas include a simple text parser (create a story about something in Notepad, and have the program read the story and output a list of how many times the word "the" was used). How about a program which can manipulate files a specific times (ie at 1 pm it creates a file, saying "it is now 1 pm", and at 2 pm it'll create another file, declaring it to be 2 pm, and deletes the 1 pm file. Once you've done that, how about merging the files into one thing (ie instead of a file named "2pm", "3pm", etc, how about one file (named something like "time") that will hold the current time?). Once you've done that, how about creating another program that it will display the time in the bottom-right corner of the screen (ie merge it into a simple game and have the clock running like the Windows Clock does)? Have it run in real time for added fun. There are countless ideas, and QBasic is a good language to develop them in. Rather quick and powerful (for its time) and capable of doing a vast majority of anything you'd like it to do (whenever you can't get it to outright do something, you can link it with some assembly code or C/C++ code to get it to do that. At one time, there was a brief movement to write an OS in QB, however it was aborted because they found out that 90% of the code would be assembly and C++ code, with QB code serving only as a sort of DOS interface).
|
|
|
Post by Mikrondel on Aug 4, 2006 23:38:50 GMT
EDIT: idril, I'm the same person as Ildûrest
Earl, I think I'm going to email the proboards staff to see if I can get a length limit on your posts!!
And a second thing: I can see you've never played a proper text adventure. That's quite a shame.
Of course, idril, you're free to give lists of actions as Earl suggested. But I think writing real interactive fiction (as your first program tried to do) would be much more fun.
Firstly I would not use WRITE to write to the file, as it inserts quotation marks and such. PRINT # should be fine.
Now I do not see the point of opening and closing the file here:
OPEN file$ FOR APPEND AS #3 INPUT "What is your name? ", Name$ Name$ = LTRIM$(RTRIM$(UCASE$(Name$))) IF Name$ = "" THEN END CLOSE #3
You can INPUT from the keyboard without having the file open.
Otherwise, congratulations on a perfect program! It's almost the same as I would have written it. Good job. Terrific use of INSTR (although you wouldn't need to if you used PRINT # instead of WRITE #)
You're going to advance very quickly, I see.
In fact, at the rate you're learning, I think it would be a waste if you went on to Visual Basic. If you want to learn another language, the most beautiful and involving language that there is, go to C. From what I've seen already, YOU would handle it very well.
If you really have used PHP extensively, you should have a basic understanding of functions. Functions which return nothing are equivalent to QB's SUBs. (Functions which return something are equivalent to QB's FUNCTIONs) I hope you have a basic understanding of how arguments are passed to functions. It's much the same in QB.
However, I disagree with the idea of making every room a subroutine. I much prefer the idea of making every room an object. You will need a lot less code this way. I'll say more about this after you've understood QB's arrays and TYPEs.
Now...
Exactly what I've been helping you to try to avoid. Recall the printing 1 letter at a time example that I gave you. Program broadly and your initial work needs more planning, and more complex code, but the difficulty of debugging and modifying your program drops very low.
Now, a quick arrays lesson. An array is a list of variables that are told apart by NUMBERS. Each of the variables has its own number.
You have to tell QB to reserve space for an array, because it can't tell how large you want it to be. This is done with DIM ArrayName (0 TO 20) DIM AnotherArray (1 TO 5)
Then to access the elements of an array, you put a number or variable in parentheses after it: ArrayName(0) = 50 ArrayName(20) = 99
Or
FOR I = 1 TO 5 AnotherArray(I) = 6 - I NEXT
Arrays have many purposes, but the main one is to let the same code deal with many different variables (without having to rewrite the code hundreds of times).
Compared to RAM access (arrays are stored in RAM), hard disk access is slow. So if you have 2000 names that you want to be easily editable, you'll store them in an array, and only write to hard disk (i.e. save to file) once you want to permanently save your changes. In the 'names' program you could read all the names into an array (each in a different element), and thus you'd only have to read the file once, and then work on the copy stored in the array. (At the moment you read once for displaying the names, and read once for checking that a name is not in the file)
You may want to try doing that now.
Each line of the file must increase the array variable by 1
A string array can be declared DIM Names (0 to 500) AS STRING or DIM Names$ (0 to 500)
The problem is you don't actually know how many names there are and QBasic is limited to less than 1MB of RAM. So making your array too large will waste space and too small will not let you load all names. Forget that for now and use 501 as a "theoretical maximum" for the names in the file.
Good luck!
|
|
|
Post by earlofqb on Aug 5, 2006 3:35:02 GMT
Yes, I am a n00b what's "never played a real text adventure". In fact, my only real experience with them is a 5-minute demo a friend showed me of DarkMUD (or something like that) and Zed (of Uncyclopedia fame, ie not a true text adventure). I'm not really into them sorts of games (although Zed is fairly fun), playing mostly FPS (first person shooter) and TBS (turn-based strategy) games. Thus, you can see why I chose to suggest the code be written in modules: because TBS games (which I'm most familiar with) typically hold all information in modules or classes (depending on the language. Even with an OOP language, the classes aren't really classes, merely "advanced modules"). I apologise for the gamer's bias towards developing according to the most familiar styles. The idea for even putting things in modules derived from my poor memory. I forgot that QB has the TYPE data type. Of course, as I've never used it (could you maybe do one of your famous Ildurest explanations and post it on your website (that way I can download it and have fun offline)?), I probably wouldn't have thought to use it anyway. The concept of putting it in modules was to emulate the basic functionality of a class (encapsulation of data, keeping the code separate from the main program, etc). It wasn't to make things overly complicated, even though that would be the end result of it. Wow, I just realised what a complete n00b I am at programming in QB. Well, as most websites are so horribly out of date on my favourite programming language, it was inevitable I wouldn't have learned much since my high school QB class (which only taught us the most basic functions). Perhaps I'll spend the next few hours downloading tutorials from Ildurest... Anyway, 90% of my post was my simple code for the Illogical Calculator (or CIP, or whatever I decide to call it at any particular time). Needless to say, the CIP/IC/ w/e it is, was written for a pure beginner's understanding (so no critiquing it, please!). Someday I'll update it for a "professional's approach" and it'll be worthy of spiffiness in code. Hopefully before then, I'll learn a thing or two about programming (unfortunately, almost all my progress in programming is in Visual Basic (because in 2 months, I'll have a college course, and it'd be rather nice to know the entire language so I can effectively pwn the entire school (possibly even the professors). Yes, it's illogical, because in 6 months I'll have a C++ class, and in a year, a Java class. Well, that's the way my twisted mind works), and some very small progress in C++ (not C )). Looks like I better stop shopping at the local bargain outlet and go to a "real" bookstore and pay exuberant amounts for a general-purpose programming book (even though 90% of "beginner's guides" use C++, which definately isn't a language for beginners). Anyone know of any good general-purpose programming books? Keep in mind I generally abhor online money deals and that sort of stuff, so kindly don't take the "initiative" to post a link to Amazon.com or barnesandnoble.com or something like that.
|
|
|
Post by Ildûrest on Aug 5, 2006 10:49:28 GMT
I must say, one of the best programming books I know of is called QBASIC.HLP I confess to having never bought a book on programming. I 'inherited' two books, 'Learning IBM BASIC' and 'Programming in BASIC for the IBM Personal Computer', which were both long before QB's time and used GOTO extensively. I read them a little, found out how to use arrays and bubble sort, then realised I was far more advanced than them. I occasionally try flicking through programming books at the library, but I mostly find stuff that's out of date or that's already obvious to me. TYPE is not a data type. In a sense it's a way of defining new data types. Essentially it lets you jam several variables together into a single unit. It's like an array that uses names, not numbers, to tell variables apart, and can have multiple datatypes in one. Examples should tell: TYPE Object X AS INTEGER Y AS INTEGER Name AS STRING * 10 END TYPE DIM Ball AS OBJECT Ball.X = 2 PRINT Ball.Name DIM Obj(0 to 10) AS OBJECT Obj(0).Name = "Dog" Obj(0).X = 5 FOR I = 1 to 4 Obj(I).Name = "Thing" Obj(I).X = I * 2 NEXT EDIT: I just realised that I'd forgotten to say that I've been planning to write a text adventure engine for a while. So idril, I can come up with large amounts of code OK, I've said it.
|
|