Author Topic: I'm stumped by this error  (Read 4623 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
I'm stumped by this error
« on: September 06, 2021, 04:33:48 pm »
I'm writing a puzzle game. You start with a phrase spelled with different letters than the ones actually in the phrase. You continue along until you have the original phrase.  The letters appear in one color if you've changed it and another color for the original code. I got it working so the first letter you choose to switch displays properly. But every time you try to change another letter, the lines of the phrase are printed out twice. The second printed line is in a different color. I'm at wits end. Any help would be much appreciated.
Code: QB64: [Select]
  1. GOTO beginning
  2. crap:
  3. PRINT "Error, Line number"
  4. beginning:
  5. WIDTH 80, 50
  6. CONST TRUE = 1
  7. CONST FALSE = 0
  8. CONST numberOfLines = 15
  9.  
  10. DIM SHARED leftArrow$: leftArrow$ = CHR$(0) + "K"
  11. DIM SHARED rightArrow$: rightArrow$ = CHR$(0) + "M"
  12. DIM SHARED translationMatrix$(1 TO 26, 1 TO 2): FOR cl = 1 TO 26: translationMatrix$(cl, 1) = "": translationMatrix$(cl, 2) = "": NEXT cl
  13. DIM SHARED codedPhrase$: codedPhrase$ = ""
  14. DIM SHARED answerPhrase$: answerPhrase$ = ""
  15. DIM SHARED highlightedLetter: highlightedLetter = 0
  16. DIM SHARED attemptedLetters$(1 TO 26, 1 TO 2): FOR cl = 1 TO 26: attemptedLetters$(cl, 1) = CHR$(cl + 64): attemptedLetters$(cl, 2) = "-": NEXT cl
  17. DIM SHARED workingLines$(1 TO numberOfLines)
  18. DIM SHARED initiallyCodedLines$(1 TO numberOfLines)
  19. DIM SHARED newLines$(1 TO numberOfLines)
  20. DIM SHARED answerLines$(1 TO numberOfLines)
  21. DIM SHARED leftPositions(1 TO numberOfLines) AS INTEGER
  22. FOR cl = 1 TO numberOfLines
  23.     workingLines$(cl) = ""
  24.     initiallyCodedLines$(cl) = ""
  25.     newLines$(cl) = ""
  26.     answerLines$(cl) = ""
  27.     leftPositions(cl) = 0
  28. NEXT cl
  29.  
  30. CALL Main
  31. SUB Main
  32.     'first, pick a phrase
  33.     randomPhrase = INT(RND * FileStatus) + 1
  34.     OPEN "Phrases.txt" FOR INPUT AS #1
  35.     FOR x = 1 TO randomPhrase
  36.         LINE INPUT #1, answerPhrase$
  37.     NEXT x
  38.     CLOSE #1
  39.  
  40.     'second, create a code
  41.     usedAlphabet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  42.     FOR allLetters = 1 TO 26
  43.         translationMatrix$(allLetters, 1) = CHR$(allLetters + 64)
  44.         newRndLet:
  45.         randomLetter = INT(RND * LEN(usedAlphabet$)) + 1
  46.         translationMatrix$(allLetters, 2) = MID$(usedAlphabet$, randomLetter, 1)
  47.         IF translationMatrix$(allLetters, 1) = translationMatrix$(allLetters, 2) THEN GOTO newRndLet
  48.         usedAlphabet$ = MID$(usedAlphabet$, 1, randomLetter - 1) + MID$(usedAlphabet$, randomLetter + 1, LEN(usedAlphabet$))
  49.     NEXT allLetters
  50.  
  51.     'third: put the phrase in code
  52.     PRINT "answerPhrase$ = " + answerPhrase$: PRINT
  53.     FOR letter = 1 TO LEN(answerPhrase$)
  54.         answerLetter$ = MID$(answerPhrase$, letter, 1)
  55.         upAnsLet$ = UCASE$(answerLetter$)
  56.         answerLetterNumber = ASC(upAnsLet$) - 64
  57.         IF ASC(upAnsLet$) >= 65 AND ASC(upAnsLet$) <= 90 THEN
  58.             upCodeLet$ = translationMatrix$(ASC(upAnsLet$) - 64, 2)
  59.             IF ASC(answerLetter$) >= 65 AND ASC(answerLetter$) <= 90 THEN
  60.                 codedLetter$ = upCodeLet$
  61.             ELSE
  62.                 codedLetter$ = LCASE$(upCodeLet$)
  63.             END IF
  64.         ELSE
  65.             codedLetter$ = answerLetter$
  66.         END IF
  67.         codedPhrase$ = codedPhrase$ + codedLetter$
  68.     NEXT letter
  69.  
  70.     'next on the list is to center the phrases
  71.     shrinkCode$ = codedPhrase$
  72.     shrinkAns$ = answerPhrase$
  73.     IF LEN(codedPhrase$) >= 60 THEN
  74.         numLine = 0
  75.         DO
  76.             numLine = numLine + 1
  77.             checkHere = 60
  78.             DO
  79.                 checkHere = checkHere - 1
  80.                 findSpace$ = MID$(codedPhrase$, checkHere, 1)
  81.             LOOP UNTIL findSpace$ = " "
  82.             workingLines$(numLine) = MID$(shrinkCode$, 1, checkHere)
  83.             initiallyCodedLines$(numLine) = MID$(shrinkCode$, 1, checkHere)
  84.             leftPositions(numLine) = Center(MID$(shrinkCode$, 1, checkHere))
  85.             answerLines$(numLine) = MID$(shrinkAns$, 1, checkHere)
  86.             shrinkCode$ = MID$(shrinkCode$, checkHere + 1, LEN(shrinkCode$))
  87.             shrinkAns$ = MID$(shrinkAns$, checkHere + 1, LEN(shrinkAns$))
  88.         LOOP UNTIL numLine = 15 OR shrinkCode$ = ""
  89.     ELSE
  90.         workingLines$(1) = codedPhrase$
  91.         initiallyCodedLines$(1) = codedPhrase$
  92.         answerLines$(1) = answerPhrase$
  93.         leftPositions(1) = Center(codedPhrase$)
  94.     END IF
  95.     cs = 1
  96.     '    DO WHILE leftPositions(cs) <> 0
  97.     '        LOCATE , leftPositions(cs): PRINT answerLines$(cs)
  98.     '        cs = cs + 1
  99.     '    LOOP
  100.     PRINT
  101.     '    gg = 1
  102.     '    DO WHILE leftPositions(gg) <> 0
  103.     '        LOCATE , leftPositions(gg): PRINT workingLines$(gg)
  104.     '        gg = gg + 1
  105.     '    LOOP
  106.     '    a$ = P$
  107.  
  108.     'now to display and build the interface
  109.     highlightedLetter = 1
  110.     CALL DisplayScreen
  111.     '    d$ = P$
  112.     plsWt = FALSE
  113.     DO
  114.         '        FOR cv = 1 TO numberOfLines: newLines$(cv) = "": NEXT cv
  115.         getCmd$ = INKEY$
  116.         getCmd$ = UCASE$(getCmd$)
  117.         SELECT CASE getCmd$
  118.             CASE leftArrow$
  119.                 IF highlightedLetter > 1 THEN
  120.                     highlightedLetter = highlightedLetter - 1
  121.                 ELSE
  122.                     highlightedLetter = 26
  123.                 END IF
  124.                 plsWt = TRUE
  125.             CASE rightArrow$
  126.                 IF highlightedLetter < 26 THEN
  127.                     highlightedLetter = highlightedLetter + 1
  128.                 ELSE
  129.                     highlightedLetter = 1
  130.                 END IF
  131.                 plsWt = TRUE
  132.             CASE CHR$(13)
  133.                 FOR cl = 1 TO 26
  134.                     attemptedLetters$(cl, 1) = CHR$(cl + 64)
  135.                     attemptedLetters$(cl, 2) = "-"
  136.                 NEXT cl
  137.                 FOR x = 1 TO numberOfLines
  138.                     workingLines$(x) = initiallyCodedLines$(x)
  139.                 NEXT x
  140.             CASE CHR$(27)
  141.                 END
  142.             CASE "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  143.                 plsWt = TRUE
  144.                 attemptedLetters$(highlightedLetter, 2) = getCmd$
  145.                 numLines = 1
  146.                 DO WHILE workingLines$(numLines) <> ""
  147.                     FOR let1 = 1 TO LEN(workingLines$(numLines))
  148.                         currentLetter$ = MID$(workingLines$(numLines), let1, 1)
  149.                         '                        LOCATE 1, 1: PRINT "currentLetter$: " + currentLetter$: g$ = P$
  150.                         IF CHR$(highlightedLetter + 64) = UCASE$(currentLetter$) THEN
  151.                             replacementLetter$ = getCmd$
  152.                             letCase = ASC(MID$(workingLines$(numLines), let1, 1))
  153.                             IF letCase >= 97 AND letCase <= 122 THEN replacementLetter$ = LCASE$(replacementLetter$)
  154.                             newLines$(numLines) = newLines$(numLines) + replacementLetter$
  155.                         ELSE
  156.                             newLines$(numLines) = newLines$(numLines) + currentLetter$
  157.                         END IF
  158.                         '                        PRINT "**************************************************************************************************"
  159.                         '                        PRINT "newLines$(numLines) = " + newLines$(numLines): k$ = P$
  160.                     NEXT let1
  161.                     numLines = numLines + 1
  162.                 LOOP
  163.         END SELECT
  164.         IF plsWt = TRUE THEN
  165.             plsWt = FALSE
  166.             f = 1
  167.             DO WHILE newLines$(f) <> ""
  168.                 workingLines$(f) = newLines$(f)
  169.                 f = f + 1
  170.             LOOP
  171.             CALL DisplayScreen
  172.         END IF
  173.     LOOP UNTIL SolvedIt = TRUE
  174.  
  175. FUNCTION SolvedIt
  176.     rtn = TRUE
  177.     FOR checkTheLine = 1 TO numberOfLines
  178.         IF workingLines$(checkTheLine) <> answerLines$(checkTheLine) THEN rtn = FALSE
  179.     NEXT checkTheLine
  180.     SolvedIt = rtn
  181.  
  182.  
  183. SUB DisplayScreen
  184.     COLOR 11, 1: CLS
  185.     LOCATE 1, 1: PRINT answerPhrase$
  186.     'print out the quote
  187.     numLines = 1
  188.     DO WHILE leftPositions(numLines) <> 0
  189.         'LOCATE 48, 1: PRINT "leftPositions(numLines) = " + S$(leftPositions(numLines)) + " ": c$ = P$
  190.         LOCATE 11 + numLines, leftPositions(numLines)
  191.         '        PRINT "numLines: " + S$(numLines) + "    workingLine$(numlines), LEN = " + workingLines$(numLines) + ",   " + S$(LEN(workinglines(numLines)))
  192.         '        PRINT "initiallyCodedLines$(" + S$(numLines) + "): = " + initiallyCodedLines$(numLines)
  193.         '        PRINT "answerLines$(numLines)" + answerLines$(numLines)
  194.         '        f$ = P$
  195.         FOR o = 1 TO LEN(workingLines$(numLines))
  196.             wlc$ = MID$(workingLines$(numLines), o, 1)
  197.             icl$ = MID$(initiallyCodedLines$(numLines), o, 1)
  198.             al$ = MID$(answerLines$(numLines), o, 1)
  199.             IF ASC(UCASE$(wlc$)) - 64 = highlightedLetter THEN 'if the letter is highlighted print 11 on 0
  200.                 COLOR 10, 0
  201.             ELSEIF wlc$ = al$ THEN 'the letter is correct
  202.                 COLOR 14, 1
  203.             ELSEIF wlc$ <> icl$ THEN 'the letter has been changed or not changed back to its original code
  204.                 COLOR 15, 1
  205.             ELSE
  206.                 COLOR 10, 1
  207.             END IF
  208.             PRINT wlc$; ': f$ = P$
  209.         NEXT o
  210.         numLines = numLines + 1
  211.     LOOP
  212.     'print out the selectable letters
  213.     spaces = 2
  214.     FOR b = 1 TO 26
  215.         IF b = highlightedLetter THEN
  216.             COLOR 10, 0
  217.         ELSE
  218.             COLOR 14, 1
  219.         END IF
  220.         LOCATE 40, spaces: PRINT attemptedLetters$(b, 1)
  221.         IF b = highlightedLetter THEN
  222.             COLOR 10, 0
  223.         ELSE
  224.             COLOR 12, 1
  225.         END IF
  226.         LOCATE 42, spaces: PRINT attemptedLetters$(b, 2)
  227.         spaces = spaces + 3
  228.     NEXT b
  229.  
  230.  
  231. FUNCTION FileStatus
  232.     IF _FILEEXISTS("Phrases.txt") = 0 THEN
  233.         OPEN "Phrases.txt" FOR OUTPUT AS #1
  234.         PRINT #1, "Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our yesterdays have lighted fools The way to dusty death. Out, out, brief candle! Life's but a walking shadow, a poor player, That struts and frets his hour upon the stage, And then is heard no more. It is a tale Told by an idiot, full of sound and fury, Signifying nothing."
  235.         PRINT #1, "To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; For in that sleep of death what dreams may come When we have shuffled off this mortal coil, Must give us pause"
  236.         PRINT #1, "If someone is able to show me that what I think or do is not right, I will happily change. For I seek the truth, by which no oe ever was truly harmed. Harmed is the person who continues in his self-deception and ignorance."
  237.         PRINT #1, "Funny lines: Before you marry a person, you should first make them use a computer with slow internet to see who they really are. -- Someone asked me, if I were stranded on a desert island what book would I bring... " + CHR$(34) + "How to Build a Boat." + CHR$(34)
  238.         PRINT #1, "Funny lines: I finally realized that people are prisoners of their own phones... that's why it's called a " + CHR$(34) + "cell" + CHR$(34) + " phone. -- Be decisive. Right or wrong, make a decision. The road is paved with flat squirrels who couldn't make a decision."
  239.         PRINT #1, "Funny lines: If at first you don't succeed, then skydiving definitely isn't for you. -- My cell phone is acting up. I keep pressing the Home button but every time I look around, I'm still at work."
  240.         PRINT #1, "Pangrams: Pack my box with five dozen liquor jugs. -- The quick brown fox jumps over the lazy dog. -- My girl wove six dozen plaid jackets before she quit."
  241.         PRINT #1, "EOF"
  242.         CLOSE #1
  243.         numberOfPhrases = 7
  244.     ELSE
  245.         OPEN "Phrases.txt" FOR INPUT AS #1
  246.         numberOfPhrases = 0
  247.         DO
  248.             numberOfPhrases = numberOfPhrases + 1
  249.             LINE INPUT #1, lineCounting$
  250.         LOOP UNTIL INSTR(lineCounting$, "EOF") <> 0
  251.         numberOfPhrases = numberOfPhrases - 1
  252.         CLOSE #1
  253.     END IF
  254.     FileStatus = numberOfPhrases
  255.  
  256. FUNCTION Center (text$)
  257.     Center = INT((80 - LEN(text$)) / 2)
  258.  
  259. FUNCTION S$ (number)
  260.     S$ = LTRIM$(STR$(number))
  261.  
  262.     pause$ = INPUT$(1)
  263.     IF pause$ = CHR$(27) THEN END
  264.     P$ = pause$

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: I'm stumped by this error
« Reply #1 on: September 06, 2021, 04:45:55 pm »
Someone is likely to swoop in with an answer.  Before that happens try out your problem using the debugger version of qb64.  It is stable enough to help you with your problem.

https://www.qb64.org/forum/index.php?topic=4119.0

FellippeHeitor spent an ungodly amount of time making it work.  Having an answer is nice.  But figuring it out with the proper tools go'es further than just an answer.
Trust me it's easier to use once you get the hang of it.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: I'm stumped by this error
« Reply #2 on: September 06, 2021, 05:09:39 pm »
I hate to sound like a Newbie but how exactly do you start debug mode?

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: I'm stumped by this error
« Reply #3 on: September 06, 2021, 05:29:09 pm »
Download the code from the link.  I also suggest reading the whole message post, to get an idea what to do.
extract it to a new directory.  Say. "qb64-debug" it's independant so you don't want to destroy your working qb64 directory.
Start the new version.  Load your problem code.  Add: "$debug" to the top line of your code.
Hit F7 to get it all going.

At this point follow the Function prompts.  ie: set a break point, step your code. add watch variable points.

You could step through all your code and watch the output display.  Once you determine your problem point set a breakpoint there.  So when you just hit F5 to start it will stop before your problem area.  Then you can step. Watch output and variables.  It should become obvious where your problem is.  Stepping in your head, you can miss it.  Stepping your code is slower than full out running.  And mistakes can be seen.

TRUST ME IT GOING TO BE FUN.

 
« Last Edit: September 06, 2021, 05:32:09 pm by doppler »

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: I'm stumped by this error
« Reply #4 on: September 06, 2021, 05:41:20 pm »
I just found another error on line 84. codedPhrase$ should have been shrinkCode$ -- I didn't notice because it worked as I intended.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: I'm stumped by this error
« Reply #5 on: September 06, 2021, 05:46:24 pm »
worked as I intended.

Ah, the old it did what I said error.
10 Bang head against wall : goto 10

Honestly try using the debugger version too.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #6 on: September 06, 2021, 06:36:33 pm »
Never mind I am still trying to figure out how this is supposed to work, so
1. high light letter
2. press the letter you think it should be
3. prest-o change - o two lines appear after the first change ;(

« Last Edit: September 06, 2021, 06:46:09 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #7 on: September 06, 2021, 08:32:24 pm »
These replacement blocks will get you closer:
Code: QB64: [Select]
  1.             Case "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
  2.                 plsWt = TRUE
  3.                 attemptedLetters$(highlightedLetter, 2) = getCmd$
  4.                 numLines = 1
  5.                 Do While workingLines$(numLines) <> ""
  6.                     For let1 = 1 To Len(workingLines$(numLines))
  7.                         currentLetter$ = Mid$(workingLines$(numLines), let1, 1)
  8.                         '                        LOCATE 1, 1: PRINT "currentLetter$: " + currentLetter$: g$ = P$
  9.                         If Chr$(highlightedLetter + 64) = UCase$(currentLetter$) Then
  10.                             replacementLetter$ = getCmd$
  11.                             letCase = Asc(Mid$(workingLines$(numLines), let1, 1))
  12.                             If letCase >= 97 And letCase <= 122 Then replacementLetter$ = LCase$(replacementLetter$)
  13.                             Mid$(workingLines$(numLines), let1, 1) = replacementLetter$  '<<< here you were building longer and longer lines
  14.                         Else
  15.                             Mid$(workingLines$(numLines), let1, 1) = currentLetter$  '<<< here you were building longer and longer lines
  16.                         End If
  17.                         '                        PRINT "**************************************************************************************************"
  18.                         '                        PRINT "newLines$(numLines) = " + newLines$(numLines): k$ = P$
  19.                     Next let1
  20.                     numLines = numLines + 1
  21.                 Loop
  22.         End Select
  23.         DisplayScreen
  24.         _Limit 60
  25.         'If plsWt = TRUE Then
  26.         '    plsWt = FALSE
  27.         '    f = 1
  28.         '    Do While newLines$(f) <> ""
  29.         '        workingLines$(f) = newLines$(f)
  30.         '        f = f + 1
  31.         '    Loop
  32.         '    Call DisplayScreen
  33.         'End If
  34.  

but you have a logic problem eg, if you replace all the s with l and then need to replace all the l with s, you will never get 2nd word, lines, right.

« Last Edit: September 06, 2021, 08:37:09 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #8 on: September 06, 2021, 08:56:33 pm »
BTW your code worked the first time with a letter change because newLines$() were completely blank so the first change of letters replaced newLines$()... oh hey that means there may be another way to fix this... be right back.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #9 on: September 06, 2021, 09:02:35 pm »
Yep! this works too at line 150 add this line (to your original code):
Code: QB64: [Select]
  1. Erase newLines$
  2.  
that way newLines$() starts empty at each rebuild.

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: I'm stumped by this error
« Reply #10 on: September 07, 2021, 12:29:49 am »
thanks

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #11 on: September 07, 2021, 05:45:06 am »
Quote
but you have a logic problem eg, if you replace all the s with l and then need to replace all the l with s, you will never get 2nd word, lines, right.

I have figured out how to handle this logic problem of replacements.

You have 3 sets of lines:
1. The original Answer set
2, that gets coded into a Coded Set
3. and a Working set than transitions from the Coded set to the Answer set and yes, as you have, the Coded set is solved when the Working set matches the Answer set.
Note: forget about another NewLines set that's just more fiddle.

I suggest when you set up the Coded Set you also set up the Working set with all "*" where there are letters in the Answer set. BTW, this is how we do it with Hangman.

Now for displaying the Puzzle in transition from Coded to Answer (NOT like Hangman) where the Working set still has a * show the Coded letter in the Coded Color (I suggest a better contrast between Coded say Blue to Answer say Red) and where there is a letter in the Answer set show that letter with the Answer color. So in fixing the Display sub find the letter AND color to print one letter at a time. If the Working set still shows a * display the Coded set letter and color, where it is not a * show the Working set letter in the Working set color.

So how to change a Coded character to the replacement letter in the Working set?
1. Find where the coded letter is in the Coded set, column x

Code: QB64: [Select]
  1. lastX = 1 'before Loop
  2. While x <> 0
  3. x = INSTR(lastX, Coded$(lineNum), ChangeLetter$)
2. Use MID$ sub to change that letter only in the Working set;
Code: QB64: [Select]
  1. MID$(Working$(lineNum), x, 1) = ReplacementLetter$
  2.  
that replaces the * with the letters plus you can easily change letters you have replaced already to different ones.

« Last Edit: September 07, 2021, 05:48:40 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #12 on: September 07, 2021, 06:03:19 am »
As far as setup goes, lay out the Answer set centered as you like then line for line, letter for letter, build the Working set with "*" where there is a letter and the other characters or blanks where they are.
« Last Edit: September 07, 2021, 06:05:41 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: I'm stumped by this error
« Reply #13 on: September 07, 2021, 06:12:27 am »
Quote
So how to change a Coded character to the replacement letter in the Working set?
1. Find where the coded letter is in the Coded set, column x

Code: QB64: [Select]
lastX = 1 'before Loop
WHILE x <> 0
x = INSTR(lastX, Coded$(lineNum), ChangeLetter$)
2. Use MID$ sub to change that letter only in the Working set;
Code: QB64: [Select]
MID$(Working$(lineNum), x, 1) = ReplacementLetter$
WEND
 
that replaces the * with the letters plus you can easily change letters you have replaced already to different ones.



Forgot to update lastX should be:
Code: QB64: [Select]
  1. lastX = 1 'before Loop
  2. WHILE lastX <> 0
  3.   x = INSTR(lastX, Coded$(lineNum), ChangeLetter$)
  4.   ' 2. Use MID$ sub to change that letter only in the Working set;
  5.   if x <> 0 MID$(Working$(lineNum), x, 1) = ReplacementLetter$
  6.   lastX = x
  7.  
« Last Edit: September 07, 2021, 06:14:25 am by bplus »

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: I'm stumped by this error
« Reply #14 on: September 07, 2021, 02:00:45 pm »
I finally was able to work around the errors. Thank you all. Now I am going to add a menu with options to add a new phrase to Phrases.txt or load a saved game. Those SUBs are easy enough. Thanks again