2
\$\begingroup\$

I'm currently making a text based choose your own adventure game with possible RPG elements.

I'm somewhat new at programming. My father is very good ad QB64, but isn't always able to help me with my problems. I'm not asking about story help but with ways I could make my code run more efficiently. I've recently replaced a lot of if statements with select case, which in turn has helped with a lot of bugs. but I'm not sure what else would be effective.

SCREEN 12
DIM SHARED age%, gender$, Name$
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
menu:
CLS
PRINT
PRINT "=============================="
PRINT "THE LOST FOREST: THE BEGINNING"
PRINT "=============================="
PRINT " The Choose Your Own Adventure"
PRINT "=============================="
PRINT "What Will Your Heros Name be?:";
Name$ = Ask$(5, 1, CSRLIN, POS(0), 11, 0)
CLS

COLOR 15, 0
PRINT Name$ + "How Old will Your Hero be?: ";: age% = VAL(Ask$(3, 0, CSRLIN, POS(0), 15, 0))
'INPUT "", age%

CLS
age:
IF age% < 21 THEN PRINT "Your Hero is Not Old Enough to go on This Journey"
IF age% > 100 THEN PRINT "Your Hero Falls Over and Dies from Old Age"; " GAME OVER"
IF age% < 21 THEN END
IF age% >= 100 THEN END



Gender:
COLOR 15, 0

PRINT Name$ + " What is Your Gender (M/F/ECT): ";: INPUT "", gender$
CLS
ready:
COLOR 15, 0
Saythis "Are You Ready to go Onto This Grand Adventure?: " 'saythis is a sub to wrap text when it gets close to the end of the screen
ready$ = LCASE$(Ask$(3, 1, CSRLIN, POS(0), 15, 0))
CLS

IF INSTR(1, ready$, "y") THEN GOTO story ELSE
GOTO ready
IF INSTR(1, ready$, "n") THEN
    GOTO rus
ELSE GOTO ready

END IF

rus:

CLS


PRINT "are you sure that you dont want to go on this adventure?:", hello$
ready$ = LCASE$(Ask$(3, 1, CSRLIN, POS(0), 15, 0))
IF INSTR(1, hello$, "y") THEN END else
GOTO rus

IF INSTR(1, hello$, "n") THEN GOTO story ELSE
GOTO rus

story:
CLS
Saythis "    A long time ago, when sorcery rained supreme, there lived a powerful sorcerer, his name was Steve (placeholder name). he struck fear even among the most powerful of sorcerers and warriors of his time. He overthrew the High Wizard ma’ster but was slightly weakened in the process. most thought being loyal would save their lives, but Steve still enjoyed killing even those most loyal to him. he ruled for many years, until one day an outsider with blackened armor and a sword able to cut through even the strongest of foes like margarine, confronted Steve and challenged him to a battle, Steve thought him mad and struck him with a spell that should've killed him instantly, but the outsider stood there, unharmed, and drove his sword into Steves chest. After that day the stranger faded into history but Steve is believed to still be alive, his soul, trapped in the hero's sword. now a new hero is born but unknown to anyone, he will once again strike down Steve"
INPUT "type anything to continue: ", story$
IF story$ = "" THEN GOTO pub
pub:

CLS
saving

Saythis "You Stand Inside Your towns local Pub, Tipsy Merry Men surround you, Most of Them you Recognize, Over by The bar maiden, is Smith, The Smith, Aptly Named Fellow Who means well But isn't all That Smart, He Dropped out of School at a young Age to Pursue His Trade, like his Father. Over Near the door is johnson the apprentice Carpenter, Commonly has to Visit Smith, He can't seem to keep from breaking his tools, although he is clumsy he is Very ambitious learner willing to learn from his mistakes instead of getting upset from them. And Sitting next to you is Your best friend Michael Mconline, You've been best friends for most of your life, he wants to become a Night of the Land, but he doesn't have the gold to pay for the training."
INPUT "What Will you Do Next?: ", choice$
SELECT CASE choice$
    CASE "talk to smith"
        GOTO DlogS
    CASE "talk to Micheal"
        GOTO Micheal_dialog
    CASE "talk to Johnson"
        GOTO DlogJ
    CASE "go outside"
        GOTO outside
    CASE ELSE
        GOTO pub
END SELECT


Micheal_dialog:
Saythis "You look ever to your best friend and"

outside:

PRINT ""
Saythis "   You stand outside the Pub, across the road is the lake, about 50 meters west of the lake stands your house, down the road is the town center and the Fountain. Just behind the foutain is the Town Hall "
INPUT "Where will you go?: ", Location$
IF Location$ = "go back inside" THEN GOTO pub

DlogS:

CLS
PRINT "you walk up to Smith and greet him"
PRINT "1: chat weapons"
PRINT "2: joining up"
PRINT "3: current events"

INPUT " what will You Say?: ", DlogS$

IF INSTR(1, dlog$, "eat") THEN PRINT "you shoudnt do that"

SELECT CASE dlog$

    CASE "joining up"
        GOTO teamupsmith

    CASE "chat weapons"
        GOTO weaponchat


    CASE "current events"
        GOTO CES
    CASE ELSE
        GOTO DlogS

END SELECT




weaponchat:

CLS
check_1% = 1

Saythis "You ask smith about any recent weapons hes made recently,"
Saythis "He says that he hasn't had any jobs due to how small the town is, but he goes on about a recent job where he had to fix a plow, but the plow was fine, the ox was just stubbern and pretended that he couldnt pull it. You ask him if hes willing to make some wepons, he agrees, but you tell him that when you know what wepons you will need you'll put in the request"
INPUT "", weaponchat$
weponchat$ = LCASE$(Ask$(3, 1, CSRLIN, POS(0), 15, 0))
check_1% = 1
SELECT CASE weaponchat$

    CASE "return"
        GOTO DlogS
    CASE "back"
        RETURN
    CASE ELSE
        GOTO weaponchat
END SELECT

teamupsmith:
CLS
PRINT "You ask Smith if he would like to join up and go see if the rumors are true"
PRINT " he says that he has some things he needs to finish but when he does he might"
IF check_1% = 1 THEN PRINT "I also have to make those weapons you requested"
PRINT "what will you do?: ";
INPUT teamupS$
SELECT CASE teamupS$
    CASE "return"
        GOTO DlogS

END SELECT



CES:
CLS
Saythis "you talk to smith about recent events that have been going on, he says that alot of soldiers have been passing through the village recenty, and a lot of injured coming back. he wonders what could be doing this to so many soldiers, he hasnt heard of any war or alot of citizens being drafted"
INPUT "what will you do? :"; CES$

INPUT "", CES$
SELECT CASE CES$
    CASE ""

    CASE ""

    CASE ""

    CASE ELSE
        GOTO CES

END SELECT
DlogJ:
CLS
'not sure what will happen here
'johnson is the carpenter
Saythis "you start to walk towards johnson but when he gets up go greet you, but he trips on his own feet and falls flat on his face, you help him up as he appoligized for his clumbsines, you tell him"
PRINT "1: you should be more careful"
PRINT "2: you cluts learn to walk"
PRINT "3: its ok, ive done that before"

PRINT "what will you say? (1,2,3...)"; DlogJ$

SELECT CASE DlogJ$
    CASE "1 "

    CASE "2"

    CASE "3"

    CASE ELSE
        GOTO DlogJ


END SELECT
Smithery:
CLS
' you will get smith as an ally here
PRINT "placeholder"; smithery$
SELECT CASE smithery$
    CASE ""

    CASE ""

    CASE ""

    CASE ELSE
        GOTO Smithery

END SELECT
Town_Hall:
CLS
'get a special item here that my help
PRINT "placeholder"; Town_hall$
SELECT CASE Town_hall$
    CASE ""

    CASE ""

    CASE ""

    CASE ELSE
        GOTO Town_Hall

END SELECT


carpender:
CLS
' get johnson as a ally here



Dark_Lord_Encounter:
CLS
'dark lord attempt to stop the proficy from becoming true by killing everyone









SUB wrong_weird_input
    IF INSTR(1, dlog$, "eat") THEN PRINT "you shoudnt do that"
    PRINT "i dont think you should do that"
    PRINT "press e to return"
    IF INKEY$ = ("e") THEN RETURN

END SUB



SUB Saythis (text$)

    x = 1
    WHILE x <= LEN(text$)
        y = 80

        DO
            IF INSTR(y + x, text$, " ") > x + 79 THEN
                y = y - 1
            ELSE
                EXIT DO
            END IF

        LOOP
        PRINT MID$(text$, x, y)
        x = x + y

    WEND

END SUB



SUB Stats
    strength% = 3
    stamina% = 3
    agility% = 3
    critchance% = 3
    IF experiencetotal% = levelup% THEN
        strength% = strength% + 2
        stamina% = stamina% + 1
        agility% = agility% + 2
        critchance% = critchance% + 1


    END IF


END SUB

SUB lvl

    level% = 1
    levelup% = 50
    experience% = 5
    experiencetotal% = 0

    IF experiencetotal% = levelup% THEN
        level% = level% + 1
    ELSE experiencetotal% = experiencetotal% * 1.25
    END IF
    IF experiencetotal% = levelup% THEN
        experience% = experience% + 1
    END IF
END SUB





SUB saving





    OPEN "save1.txt" FOR OUTPUT AS #1
    PRINT Name$
    PRINT age%
    PRINT gender$
    PRINT #1, Name$
    PRINT #1, age%
    PRINT #1, gender$




    CLOSE #1






END SUB




































DECLARE FUNCTION Ask$ (Length%, Cat%, x%, y%, ForeColor%, BackColor%)


















FUNCTION Ask$ (Length%, Cat%, x%, y%, ForeColor%, BackColor%)

    LOCATE x%, y%, 1
    COLOR ForeColor, BackColor

    a = x%
    b = y%

    COLOR ForeColor%, BackColor%
    Variable$ = SPACE$(Length%)
    DO
        DO 'wait for keyboard input
            MyData$ = INKEY$
        LOOP WHILE MyData$ = ""

        IF MyData$ = CHR$(13) THEN
            Ask$ = Variable$
            EXIT FUNCTION
        END IF


        SELECT CASE Cat% 'check what category. cat 0 is number only
            CASE 0

                SELECT CASE ASC(MyData$) 'check ascii value of input

                    CASE 48 TO 57 '0 through 9
                        IF LEN(RTRIM$(Variable$)) < Length% THEN 'if length of user input is less than max length
                            LOCATE a, b 'reset cursor
                            b = b + 1 'add one to our length marker
                            MID$(Variable$, (b - y%), 1) = MyData$ 'make cursor spot the new data
                            PRINT MyData$;
                        END IF
                END SELECT

            CASE 1 'alpha numeric

                SELECT CASE ASC(MyData$)

                    CASE 48 TO 57 '0 through 9
                        IF LEN(RTRIM$(Variable$)) < Length% THEN
                            LOCATE a, b
                            b = b + 1
                            MID$(Variable$, (b - y%), 1) = MyData$
                            PRINT MyData$;
                        END IF

                    CASE 65 TO 90, 97 TO 122, 32 '0 through 9
                        IF LEN(RTRIM$(Variable$)) < Length% THEN
                            LOCATE a, b
                            b = b + 1
                            MID$(Variable$, (b - y%), 1) = MyData$
                            PRINT MyData$;
                        END IF





                END SELECT


        END SELECT


        SELECT CASE ASC(MyData$)
            CASE 8 'backspace
                IF b > y% THEN

                    MID$(Variable$, b - y%, 1) = " "
                    b = b - 1

                    LOCATE x%, y%
                    PRINT Variable$ + " ";
                    LOCATE a, b
                END IF

        END SELECT

        SELECT CASE MyData$
            CASE (CHR$(0) + CHR$(75)) 'left arrow
                IF b > y% THEN
                    b = b - 1
                    LOCATE a, b
                END IF

            CASE (CHR$(0) + CHR$(77)) 'right arrow
                IF (b - y%) < Length% THEN
                    b = b + 1
                    LOCATE a, b
                END IF

            CASE (CHR$(0) + CHR$(72)) 'up arrow
                x = x

            CASE (CHR$(0) + CHR$(80)) 'left arrow

                x = x
            CASE (CHR$(0) + CHR$(83)) 'del
                Variable$ = MID$(Variable$, 1, b - y%) + RTRIM$(MID$(Variable$, (b + 2) - y%))

                LOCATE x%, y%
                PRINT Variable$ + " ";
                LOCATE a, b

                ' CASE "~"
                END
        END SELECT




    LOOP

END FUNCTION

I'm not asking for a debugger, (I couldn't pay you for your time anyway), but asking for assistance with ways to improve code that isn't effective to have (that probably sounds like debugging).

\$\endgroup\$
  • \$\begingroup\$ Welcome to Code Review. There are some minor issues with your question, mostly its title and description. We expect your description to tell us about more about your project, for example what kind of text adventure we have at hand, whether you care about handling of incorrect input and similar decisions. Your title on the other hand should describe your project, not your concerns about the project. After all, we review your code/project, not your concerns, although we try to answer them during said review. See How to Ask for some examples. \$\endgroup\$ – Zeta Feb 28 at 6:13
  • \$\begingroup\$ I've took the liberty to change your question title into your game's name. That ought to attract more views. \$\endgroup\$ – Zeta Feb 28 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.