r/Basic • • Nov 19 '22

Basic Anywhere StarTrek with and error.

Basic Anywhere Program

This gets an error on execution about "String Literal contains an un-escaped line break" but I can't seem to find it and Basic Anywhere is not showing me the line

should it move the editor to the line that is erroring?

btw this runs fine in basic.

DECLARE SUB orders ()
DECLARE SUB twirly ()
DECLARE SUB eogtest ()
DECLARE SUB phasor ()
DECLARE SUB photorp ()
DECLARE SUB Impulse ()
DECLARE SUB warpdrive ()
DECLARE SUB BuildSectors ()
DECLARE SUB buildasector ()
DECLARE SUB display ()
DECLARE SUB command ()
DECLARE SUB kattack ()

OPTION BASE 0
RANDOMIZE TIMER
COLOR 14, 0
CLS

DIM SHARED s(9, 9)
DIM SHARED q(9, 9, 4)
DIM SHARED device(8)
DIM SHARED device$(8)
DIM SHARED devname$(8)
DIM SHARED dmg$
DIM SHARED dz, tp, eng, esx, esy, eqx, eqy, bases, klingons, alive
DIM SHARED stat$
DIM SHARED srs, lrs, ida, wda, pha, pho, shg, cmp
DIM SHARED aEmpty, astar, abase, aklingon, aStarship

srs = 1: device$(1) = "SRS": devname$(1) = "Short Range Sensors"
lrs = 2: device$(2) = "LRS": devname$(2) = "Long Range Sensors"
ida = 3: device$(3) = "IDA": devname$(3) = "Impulse Drive Assy"
wda = 4: device$(4) = "WDA": devname$(4) = "Warp Drive Assy"
pha = 5: device$(5) = "PHA": devname$(5) = "Phaser Banks"
pho = 6: device$(6) = "PHO": devname$(6) = "Photon Torpedo Launcher"
shg = 7: device$(7) = "SHG": devname$(7) = "Shield Generator"
cmp = 8: device$(8) = "CMP": devname$(8) = "Library Computer"

aEmpty = 0
astar = 1
abase = 2
aklingon = 3
aStarship = 4

dmg$ = ""

BuildSectors

tp = 10
eng = 3000
dz = INT(klingons * 400 / bases)
esx = INT(RND(1) * 8) + 1
esy = INT(RND(1) * 8) + 1
eqx = INT(RND(1) * 8) + 1
eqy = INT(RND(1) * 8) + 1
dmg$ = "Ship Initial Location (" + STR$(eqx) + "." + STR$(esx) + "," + STR$(eqy) + "." + STR$(esy) + ") "

CLS
orders
twirly


FOR I = 1 TO 8: device(I) = 99: NEXT I

alive = 1
buildasector
CLS
DO
    display
    command
    IF alive THEN kattack
    eogtest
LOOP WHILE alive



END

SUB buildasector
    FOR x = 1 TO 8
        FOR y = 1 TO 8
            s(x, y) = 0
        NEXT y
    NEXT x

    s(esx, esy) = 4

    FOR t = 1 TO 3
        FOR e = 1 TO q(eqx, eqy, t)
            DO
                x = INT(RND(1) * 8) + 1
                y = INT(RND(1) * 8) + 1
            LOOP WHILE s(x, y) <> 0
            s(x, y) = t
            PRINT "Type "; t; " at ("; x; ","; y; ") "
        NEXT e
    NEXT t

END SUB

SUB BuildSectors

    bases = 0
    klingons = 0

    FOR x = 1 TO 8
        FOR y = 1 TO 8

            s = INT(RND(1) * 6) + 1
            IF s > 4 THEN s = 4

            b = INT(RND(1) * 3)
            IF b > 1 THEN b = 0

            k = INT(RND(1) * 4) + b

            q(x, y, astar) = s
            q(x, y, abase) = b
            q(x, y, aklingon) = k
            q(x, y, 4) = 0

            bases = bases + b
            klingons = klingons + k
        NEXT y
    NEXT x

END SUB

SUB command

    PRINT "Command [PTRWIQ?] :"
    DO
        a$ = INKEY$
    LOOP WHILE a$ = ""

    a$ = UCASE$(a$)

    SELECT CASE a$
    CASE "P"
        phasor
    CASE "T"
        photorp
    CASE "R"
        FOR I = 1 TO 8
            IF device(I) < 99 THEN
                r = INT(RND(1) * 5)
                device(I) = device(I) + r
                IF device(I) > 99 THEN device(I) = 99
            END IF
        NEXT I
        dz = dz - 1
        eng = eng + INT(RND(1) * 30)
        dmg$ = "Spent one day repairing systems"
    CASE "W"
        warpdrive
    CASE "I"
        Impulse
    CASE "Q"
        alive = 0
    CASE "-"
        dmg$ = "Q zaps all the klingons here for you, but it cost you days"
        klingons = klingons - q(eqx, eqy, 3)
        days = days - q(eqx, eqy, 3)
        q(eqx, eqy, 3) = 0
        buildasector
    CASE "?"
        CLS
        PRINT "+------------------+------------------------------------------+"
        PRINT "| T Photon Torpedo | Kills one target very dead               |"
        PRINT "| P Phasors        | Kills all targets, takes a lot of energy |"
        PRINT "| W Warp Drive     | Travel to other sectors                  |"
        PRINT "| I Impulse Drive  | Travel within this sector                |"
        PRINT "| R Repair         | Take a day for repair                    |"
        PRINT "| ? Help           | Print this list                          |"
        PRINT "| Q Quit           | End Simulation                           |"
        PRINT "+------------------+------------------------------------------+"
        PRINT
        orders
        twirly
        CLS
    CASE ELSE
        dmg$ = "Directive " + a$ + " is not recognised, please re-state"
    END SELECT
END SUB

SUB display

    stat$ = "GREEN "
    FOR x = -1 TO 1
        FOR y = -1 TO 1
            q(eqx + x, eqy + y, 4) = 1
            IF s(esx + x, esy + y) = 2 THEN stat$ = "DOCKED"
        NEXT y
    NEXT x
    IF q(eqx, eqy, 3) > 0 THEN stat$ = "RED"

    IF stat$ = "DOCKED" THEN
        dmg$ = "Starbase replenish and Repair"
        tp = 10
        eng = 3000
        FOR I = 1 TO 8
            IF device(I) < 99 THEN
                device(I) = device(I) + INT(RND(1) * 10)
                IF device(I) > 99 THEN device(I) = 99
            END IF
        NEXT I
    END IF

    COLOR 14, 0
    LOCATE 1, 1
    PRINT "Enterprise ("; eqx; "."; esx; ","; eqy; "."; esy; ") "
    PRINT "Days:"; dz; " Energy:"; eng; " Photorp:"; tp;
    PRINT "Status:"; stat$; "  SBK "
    PRINT "Bases:"; bases; " Klingons:"; klingons
    PRINT " ========================================================================"
    PRINT "   1  2  3  4  5  6  7  8  DEV %%   1    2    3    4    5    6    7    8"

    FOR x = 1 TO 8
        PRINT RIGHT$(STR$(x), 1); "|";
        FOR y = 1 TO 8
            IF x = esx AND y = esy THEN PRINT "[";  ELSE PRINT " ";
            IF device(srs) < INT(RND(1) * 99) THEN
                PRINT "@";
            ELSE
                PRINT MID$(".*#-+", s(x, y) + 1, 1);
            END IF
            IF x = esx AND y = esy THEN PRINT "]";  ELSE PRINT " ";
        NEXT y
        PRINT "|"; device$(x); ":"; RIGHT$("00" + STR$(device(x)), 2); "|";
        FOR y = 1 TO 8
            IF device(cmp) < INT(RND(1) * 99) THEN
                n$ = "@@@"
            ELSE
                IF q(x, y, 4) = 0 THEN
                    COLOR 14, 0
                    n$ = "..."
                ELSE
                    n$ = ""
                    n$ = n$ + RIGHT$(STR$(q(x, y, 1)), 1)
                    n$ = n$ + RIGHT$(STR$(q(x, y, 2)), 1)
                    n$ = n$ + RIGHT$(STR$(q(x, y, 3)), 1)
                END IF
            END IF
            IF eqx = x AND eqy = y THEN PRINT "[";  ELSE PRINT " ";
            
            COLOR 14, 0
            IF q(x, y, abase) > 0 THEN COLOR 5, 0
            IF q(x, y, aklingon) > 0 THEN COLOR 2, 0
            IF q(x, y, 4) = 0 THEN COLOR 14, 0
            PRINT n$;
            COLOR 14, 0

            IF eqx = x AND eqy = y THEN PRINT "]";  ELSE PRINT " ";
        NEXT y
        PRINT
    NEXT x
    PRINT " ========================================================================"
    PRINT dmg$
    dmg$ = ""
    END SUB

SUB eogtest
' end of game testing

    IF eng < 50 THEN
        alive = 0
        PRINT "Your ship is so low on energy that only life support "
        PRINT "works. You are drifting, uncontrolled, waiting for   "
        PRINT "rescue from the nearest ...                          "
        PRINT "Klingon"
    ELSE
        IF klingons = 0 THEN
            alive = 0
            PRINT "You have destroyed every last Klingon! Earth is safe "
            PRINT "You and your crew are heros. Next stop -Risa!        "
        ELSE
            IF dz = 0 THEN
                alive = 0
                PRINT "Time is up. "; klingons; " Klingon warships are "
                PRINT "now headed for earth. They will take up the     "
                PRINT "battle in sector 001"
            END IF
        END IF
    END IF
         
END SUB

SUB Impulse
    IF device(ida) < INT(RND(1) * 99) THEN
        dmg$ = "Impulse Drive is Offline"
    ELSE
        INPUT "Specify in sector destination x,y"; x, y
        IF s(x, y) <> 0 THEN
            dmg$ = "Navigation inhibited, destination occupide"
        ELSE
            IF eng < 50 THEN
                dmg$ = "Not enough energy for impulse transit"
            ELSE
                s(esx, esy) = 0
                esx = x
                esy = y
                s(x, y) = 4
                eng = eng - 50
                dmg$ = "Transit Completed"
            END IF
        END IF
    END IF
END SUB

SUB kattack
    CLS
    PRINT "Klingons Attack!"
    FOR x = 1 TO 8
        FOR y = 1 TO 8
            IF eqx = x AND eqy = y THEN

                FOR x1 = 1 TO 8
                    FOR y1 = 1 TO 8
                        IF s(x1, y1) = aklingon THEN
                            PRINT "Klingon at"; x1; ","; y1; "fires ";
                            d = INT(RND(1) * 8)
                            s = INT(RND(1) * 8)
                            IF device(shg) < INT(RND(1) * 99) THEN
                                PRINT devname$(s); " damaged ("; d; ")";
                                device(s) = device(s) - d
                                IF device(s) < 0 THEN device(s) = 0
                            ELSE
                                PRINT d; "damaged absorbed by shields";
                                device(shg) = device(shg) - d
                                IF device(shg) < 0 THEN device(shg) = 0
                            END IF
                            PRINT
                        END IF
                    NEXT y1
                NEXT x1

            ELSE

                IF q(x, y, abase) > 0 AND q(x, y, aklingon) > 0 THEN
                    PRINT "Starbase at"; x; ","; y; "is under attack";
                    IF INT(RND(1) * 99) < 5 THEN
                        q(x, y, abase) = q(x, y, abase) - 1
                        bases = bases - 1
                        PRINT ",destroyed";
                    END IF
                    PRINT
                END IF

            END IF
        NEXT y
    NEXT x
    PRINT "---";
    twirly
    CLS
    display
END SUB

SUB orders
    PRINT "                                              "
    PRINT " Current SitRep:                              "
    PRINT " ===================================================="
    PRINT " Current Location "
    PRINT " Sector ("; eqx; eqy; ")"
    PRINT " System ("; esx; esy; ")"
    PRINT " ===================================================="
    PRINT " You have "; bases; " bases for repair and resupply"
    PRINT " The Klingon invasion force numbers "; klingons
    PRINT " We estimate they will begin the attac on earth "
    PRINT " in "; dz; " days"
    PRINT " ===================================================="
    PRINT
END SUB

SUB phasor
    IF device(pha) < INT(RND(1) * 99) THEN
        dmg$ = "Phasors offline "
    ELSE
        IF q(eqx, eqy, aklingon) = 0 THEN
            dmg$ = "No valid targets in sector"
        ELSE
            DO
                INPUT "Phasor bank charge percentage: (0 to 99)"; chg
            LOOP WHILE chg > 99 OR chg < 0
            IF chg * 10 > eng THEN
                dmg$ = "Not enough energy to charge to that level"
            ELSE
                kills = 0
                FOR t = 1 TO q(eqx, eqy, aklingon)
                    IF INT(RND(1) * 99) < chg THEN
                        q(eqx, eqy, aklingon) = q(eqx, eqy, aklingon) - 1
                        klingons = klingons - 1
                        kills = kills + 1
                    END IF
                NEXT t
                eng = eng - (chg * 10)
                buildasector
                dz = dz - 1
                dmg$ = STR$(kills) + " Klingons destroyed" + STR$(q(eqx, eqy, aklingon)) + " remain."
            END IF
        END IF
    END IF
END SUB

SUB photorp
    IF device(pho) < INT(RND(1) * 99) THEN
        dmg$ = "Torpedo Launcher offline"
    ELSE
        IF tp = 0 THEN
            dmg$ = "No Photon Torpedos"
        ELSE
            INPUT "Specify Target x,y"; x, y
            IF s(x, y) <> aklingon THEN
                dmg$ = "Launch inhibit - target is not a hostile"
            ELSE
                tp = tp - 1
                tx = esx
                ty = esy
                CLS
                DO
                    PRINT "Track: "; tx; ","; ty
                    IF tx > x THEN tx = tx - 1
                    IF tx < x THEN tx = tx + 1
                    IF ty > y THEN ty = ty - 1
                    IF ty < y THEN ty = ty + 1
                LOOP WHILE s(tx, ty) = 0
                IF s(tx, ty) = aklingon THEN
                    s(tx, ty) = 0
                    klingons = klingons - 1
                    q(eqx, eqy, aklingon) = q(eqx, eqy, aklingon) - 1
                    dmg$ = "Klingon at" + STR$(tx) + "," + STR$(ty) + " Destroyed"
                END IF

                IF s(tx, ty) = astar THEN
                    dmg$ = "The star burps"
                END IF

                IF s(tx, ty) = abase THEN
                    dmg$ = "That was OUR base"
                    s(tx, ty) = 0
                    bases = bases - 1
                    q(eqx, eqy, abase) = q(eqx, eqy, abase) - 1
                END IF
                PRINT dmg$
                twirly
            END IF
        END IF
    END IF

END SUB

SUB twirly
    c$ = "-/|\"
    row = CSRLIN
    col = POS(0)
    slant = 0
    DO
        LOCATE row, col
        PRINT MID$(c$, slant + 1 MOD 4, 1);
        slant = (slant + 1) MOD 4
    LOOP WHILE INKEY$ = ""
END SUB

SUB warpdrive
    IF device(wda) < INT(RND(1) * 100) THEN
        dmg$ = "Warp drive is offline"
    ELSE
        INPUT "Specify Destination Quadrant x,y"; x, y
        d = ABS(eqx - x) + ABS(equ - y)
        IF d * 30 > eng THEN
            dmg$ = "Energy available is insufficient for warp transit"
        ELSE
            eng = eng - d * 30
            dz = dz - d
            eqx = x
            eqy = y
            esx = INT(RND(1) * 8 + 1)
            esy = INT(RND(1) * 8 + 1)
            buildasector
            dmg$ = "Record Ship Arrival"
        END IF
    END IF
END SUB

Thanks In Advance!

1 Upvotes

50 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Nov 21 '22

I will see what I can do.

When newer versions of BAM come out what is the best way to lift the code in older version into the newer version?

I have been opening the older version - copy the code to a local text editor then open the new version, paste it in, save it over the older version's HTML file.

1

u/CharlieJV13 Nov 21 '22

The easiest way for you to bring your programs from one version of BASIC Anywhere Machine to another is to get out of the IDE "interface" to get into the TiddlyWiki native interface, and drag your program "tiddlers" from one to the other for import.

I've got to come up with an easy "drag this link" from the IDE to another IDE without dropping into the TiddlyWiki interface.

I'll try to do a video about that in the next day or two to show how easy it is.