Announcement

Collapse
No announcement yet.

Qbasic Tutorial

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Qbasic Tutorial

    For those who griping about RPGM3's limits, heres something you'll like: a programming language. Qbasic is what I program Lancer EX in, and while graphics are a pain in the ***, it is very helpful for custom battle systems and the ilk. First off: you can get it here...I think. Let me know if it doesn't work. Anyway, on to the basics. First off, in this tutorial, t stand for text, and v stands for variable.
    And away we go!

    END Ends the program. I put it first cause I'm like that.

    CLS: Clears the screen. Use this or the screen will be very messy.

    PRINT "t": Prints text. A side note: If you put a variable in the quotes, it will print the exact text, i.e "v$". If you put the variable in a print command but not in quotes, it displays the value of that variable. Note that if you have multiple print commands there is not pause between.

    INPUT "t", v$: Here's where it gets fun. This displays the line of text placed in quotes, then gives the user the chance to type something in. The words typed are then assigned to that varaible.

    Quick Side lesson about variables! There are two kinds, text and numeric. A numeric variable looks like this:

    v

    You CANNOT change a numeric variable with the input command. You change it simply by inputing code like this:

    v = 3

    Text Variables look like this:

    v$

    You can change them with input, and manually. However, to change it manually, you have to use quotes, like this:
    V$ = "cow"

    Also, here's something I do a lot: Use the command input "", z$ to put in a pause.

    If you need to write in a note, putting an apostaphe (sp?) before the line makes it void, so you can write in 'this is my battle system and such.
    With that done, here is your first sample code!

    CLS
    Print "This is my first sample code!"
    input "", z$
    input "What is your name?",n$
    print "Hi, " n$"!"
    end

    Press F5 to run the program. If anyone's intrested, I'll post more.

    #2
    Re: Qbasic Tutorial

    I'm learning how to program in java right now.
    Qbasic looks a lot like java.
    Guess my teacher is right.

    I suck at programming though.

    But it's cool that you're actually using progamming to build a game from scratch.

    Comment


      #3
      Re: Qbasic Tutorial

      Thanks, Kumo! If it would help, I could easily give you Qbasic tips, which, as you said, are a hair away from java tips .

      Comment


        #4
        Re: Qbasic Tutorial

        Thanks, I'll keep you in mind if I have any problems.

        Comment


          #5
          Re: Qbasic Tutorial

          Actually Java is quite different from QBasic, and more similar to C++/C. Java is Object Oriented and compiled, while QBasic is Proceedural and interpreted, so there is quite a bit of difference between the two, though for these simple examples they are kind of similar. For most programming languages you will find that printing, and inputing things is fairly similar, since most language support some kind of print statement (Cs is printf, C++ is cout <<, C# is Console.WriteLine(), and java is System.out.println()), however beyond these Java is much different in how it works from QBasic, so Java would not be the best comparison to use.

          Actually QBasic also has another nice feature for printing things called Locate, which will move the text cursor to that point in the screen so you can overwrite what's there. This feature is not available in many other languages without getting some kind of 3rd party library like Curses, mainly because most people use widgets or graphical interfaces instead of console interfaces. So say you were outputting HP, instead of writing

          100
          95
          90

          Using the print statement to show damage you can do

          hp = 100
          PRINT hp
          hp = hp - 5
          LOCATE 1, 1
          PRINT hp
          hp = hp - 5
          LOCATE 1, 1
          PRINT hp

          which will keep updating the hp in the same location which is 1, 1 (top left corner). This way you don't have to constantly reprint the whole screen just to change an HP value or something like that (printing is pretty slow).

          Another thing you will want to know about is arrays, which are nice for storing character data. Say you want to store 3 characters data and each one has 4 stats, HP, MP, ATT, DEF. You can make a 3x4 array to store this which in QBasic is done by.

          OPTION BASE 1
          [Makes all array acceses start at 1 instead of 0 like in other languages, you can leave this out if you want to start at 0]

          DIM SHARED CHARDATA(3, 4) AS INTEGER
          [DIM provides space for the array
          SHARED makes it available in subroutines
          (3, 4) means a 2D array with 3 columns, and 4 rows, you can have as many dimensions as you want. So to have 2 teams of 3 players it would be (2, 3, 4)
          AS INTEGER means it will store integer numbers, you can use any regular data type if you want Strings use AS STRING, for strings which are all 20 characters long, AS STRING * 20]

          Then to get character 1's HP type
          CHARDATA(1, 1)

          and to set it to 100
          CHARDATA(1, 1) = 100

          This helps save space with code, since having all this in seperate variables is wasteful. And it makes iterating through characters easy, cause you can use variables for the accessors. So to set all characters MP to 50 do

          FOR I = 1 TO 3
          CHARDATA(I, 2) = 50
          NEXT I

          I found some snapshots of a 2 player vs RPG I worked on a long time ago in QBasic.

          http://www.prism.gatech.edu/~gtg445h/CRPGSnapShots.doc

          Just a couple of helpful pointers from an experienced programmer, QBasic is what I programmed in first, and I've been programming in Java for 3 years now.
          Last edited by thetruecoolness; 12-22-2005, 04:46 AM.
          はじめまして。真(しん)の冷静(れいせい)です。どうぞよろしく。
          http://www.thetruecoolness.com/

          5198-2124-7210 Smash

          Comment

          Working...
          X