Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rouge line breaks
#1
I'm having trouble with a program I'm working on. This is a file editing type program designed to design a file for a game I'm working on. It's far from done, and I'm stuck.

First, a summary of what is does: You make, delete, edit, and rearrange commands that will be saved to a file and used in a game as instructions on a conversation. This is modelled after a the trigger editor in Warcraft III if any of you know what that is (probably not though... All of you seem too mature.) As of now, I have four commands: set color, display text, wait for key press, and clear screen, all of which are interpreted in the game I made.


The part I'm having trouble with is the editing of displaying text. It edits the string, but shifts the whole screen up. I don't know what else to say... Can anyone help? Here is the code.

Code:
DECLARE FUNCTION gettext$ (theString$)
DECLARE SUB cleanupbottom ()
DECLARE SUB edit (index!)
DECLARE SUB shiftrangeup (top!, bottom!)
DECLARE SUB delete (index!)
DECLARE SUB shiftdown (which!)
DECLARE SUB shiftup (which!)
DECLARE FUNCTION numcommands! ()
DECLARE SUB dispmenu (x!, y!)
DECLARE FUNCTION valueof$ (thing AS STRING)
DECLARE SUB dispcoms (x!, y!, selected!)
DECLARE FUNCTION parsefordisp$ (toparse AS STRING)
DIM SHARED comm$(100)
DIM SHARED argument$(100)
selected = 1
comm$(1) = "setcolor"
argument$(1) = "4"
comm$(2) = "disptext"
argument$(2) = "And the Panda o' Doom reigns over the land"
comm$(3) = "wait"
argument$(3) = ""
comm$(4) = "deeaatthh"
argument$(4) = "moo?"
comm$(5) = "clear"
argument$(5) = ""


DO
        IF press$ = CHR$(0) + CHR$(80) AND selected < numcommands THEN selected = selected + 1
        IF press$ = CHR$(0) + CHR$(72) AND selected > 1 THEN selected = selected - 1
        IF LCASE$(press$) = "u" AND selected > 1 THEN CALL shiftup(selected)
        IF LCASE$(press$) = "d" AND selected < numcommands THEN CALL shiftdown(selected)
        IF LCASE$(press$) = "t" THEN CALL delete(selected)
        IF LCASE$(press$) = "e" THEN CALL edit(selected)


        CLS
        CALL dispmenu(70, 1)
        CALL dispcoms(1, 1, selected)
      
        DO: press$ = INKEY$: LOOP WHILE press$ = ""
LOOP

SUB cleanupbottom
LOCATE 22, 1
PRINT "                                                                              "
PRINT "                                                                              "
END SUB

SUB delete (index)
CALL shiftrangeup(index, numcommands)
comm$(numcommands) = "": argument$(numcommands) = ""
END SUB

SUB dispcoms (x, y, selected)
i = 1
COLOR 8, 7
LOCATE x, y
PRINT "Command        Argument"
COLOR 0, 0
DO WHILE comm$(i) <> ""
        IF i = selected THEN COLOR 15, 0 ELSE COLOR 7, 0
        IF comm$(i) = "setcolor" THEN
                LOCATE y + i, x
                PRINT "Set Color:"
                LOCATE y + i, x + 15: COLOR 4, VAL(argument$(i)): PRINT "  "
        ELSEIF comm$(i) = "disptext" THEN
                PRINT "Display Text:"
                LOCATE y + i, x + 15: PRINT parsefordisp$(valueof$(argument$(i)))
        ELSEIF comm$(i) = "wait" THEN
                PRINT "Wait for key press"
        ELSEIF comm$(i) = "clear" THEN
                PRINT "Clear screen"
        ELSE
                IF selected <> i THEN COLOR 8
                PRINT "Command not recognized"
        END IF

        i = i + 1
LOOP
END SUB

SUB dispmenu (x, y)
LOCATE y, x: COLOR 15, 0: PRINT "N"
LOCATE y, x + 1: COLOR 7, 0: PRINT "ew"

LOCATE y + 1, x: COLOR 7, 0: PRINT "Dele"
LOCATE y + 1, x + 4: COLOR 15, 0: PRINT "t"
LOCATE y + 1, x + 5: COLOR 7, 0: PRINT "e"

LOCATE y + 2, x: COLOR 15, 0: PRINT "E"
LOCATE y + 2, x + 1: COLOR 7, 0: PRINT "dit"

LOCATE y + 3, x: COLOR 7, 0: PRINT "Move "
LOCATE y + 3, x + 5: COLOR 15, 0: PRINT "D"
LOCATE y + 3, x + 6: COLOR 7, 0: PRINT "own"

LOCATE y + 4, x: COLOR 7, 0: PRINT "Move "
LOCATE y + 4, x + 5: COLOR 15, 0: PRINT "U"
LOCATE y + 4, x + 6: COLOR 7, 0: PRINT "p"

END SUB

SUB edit (index)
IF comm$(index) = "setcolor" THEN
        FOR i = 1 TO 7
                LOCATE 23, 18 + i * 5: COLOR 0, i: PRINT "     "
        NEXT i
        sel = 1
        COLOR 15
        DO
                LOCATE 22, 15 + sel * 5: COLOR 15, 0: PRINT " "
                LOCATE 22, 20 + sel * 5: COLOR 15, 0: PRINT "ê"
                LOCATE 22, 25 + sel * 5: COLOR 15, 0: PRINT " "
                DO: press$ = INKEY$: LOOP WHILE press$ = ""
                IF press$ = CHR$(0) + CHR$(77) AND sel < 7 THEN sel = sel + 1
                IF press$ = CHR$(0) + CHR$(75) AND sel > 1 THEN sel = sel - 1
                IF press$ = CHR$(13) THEN EXIT DO
        LOOP
        argument$(index) = STR$(sel)
ELSEIF comm$(index) = "disptext" THEN
        
        argument$(index) = gettext$(argument$(index))
        'argument$(index) = "THIS is edited"
END IF

CALL cleanupbottom
END SUB

FUNCTION gettext$ (theString$)
maxcp = 75
cp = LEN(theString$)
LOCATE 22, 1
PRINT (theString$ + "_")
DO
        DO: press$ = INKEY$: LOOP WHILE press$ = ""
        IF press$ = CHR$(8) THEN
                IF LEN(theString$) > 0 THEN
                        theString$ = MID$(theString$, 1, LEN(theString$) - 1)
                        cp = cp - 1
                        LOCATE 22, cp + 1: PRINT ("_ ")
                END IF
        ELSE
                theString$ = theString$ + press$
                cp = cp + 1
                IF cp > maxcp + 1 THEN cp = cp - 1
                LOCATE 22, cp: PRINT (press$ + "_")
        END IF
LOOP WHILE press$ <> CHR$(13)
gettext$ = theString$
END FUNCTION

FUNCTION numcommands
i = 1
DO WHILE comm$(i) <> ""
        i = i + 1
LOOP
numcommands = i - 1
END FUNCTION

FUNCTION parsefordisp$ (toparse AS STRING)
        IF LEN(toparse) > 40 THEN toparse = CHR$(34) + MID$(toparse, 1, 40) + "..." + CHR$(34)
        parsefordisp$ = toparse
END FUNCTION

SUB shiftdown (which)
SWAP comm$(which), comm$(which + 1)
SWAP argument$(which), argument$(which + 1)
which = which + 1
END SUB

SUB shiftrangeup (top, bottom)
IF top > bottom THEN SWAP top, bottom
FOR i = top + 1 TO bottom
        comm$(i - 1) = comm$(i)
        argument$(i - 1) = argument$(i)
NEXT i
END SUB

SUB shiftup (which)
SWAP comm$(which), comm$(which - 1)
SWAP argument$(which), argument$(which - 1)
which = which - 1

END SUB

FUNCTION valueof$ (thing AS STRING)
'This is used so it doesn't directly access an array member, which changes it
valueof$ = thing
END FUNCTION
Reply
#2
A sticky situation.

You have to separate the screen from the program. Using POINT(x,y) is a bad idea, for example. So is relying on PRINT.

You can still use print, though. You'll have to modify things.

You'll need a separate array for strings that are typed in or whatnot.

Then, you need lines of code that say what line number your first line (on the screen) is on. You can then print to screen from there. So, every time you exceed the screen space, you are just moving down by another line...

Does that make sense?

Also, don't forget PRINT by default adds a carriage return (ENTER). To remove it, add ; to the end.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
Sorry I don't have time to save it now, but it looks like your problem is that you're writing to the forbidden row at the bottom of the screen. Every write to that will cause the screen to scroll up one line.

If you want to write there, you have to either add a ; to the end of your print statement, or else switch to directly editing memory rather than using PRINT.

For an editor, POKEing straight to memory would be the faster/better solution:
Code:
DEF SEG = &hB800
POKE row - 1 * 160 + (column - 1 * 2)

I'm not sure if that was your problem at all... but it looked like it.
Reply
#4
Quote: it looks like your problem is that you're writing to the forbidden row at the bottom of the screen.
:???: I don't get what you're saying exactly... Where am I writing to the forbidden line?

Quote:You'll need a separate array for strings that are typed in or whatnot.
Argument$ keeps track of what is typed in as far as I know. I probably don't understand what you're saying. :-?

Anyway, I've tried more things, and I've discovered that if I replace
Code:
argument$(index) = gettext$(argument$(index))
with
Code:
input argument$(index)
, it works. So my problem is in the gettext sub? I think?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)