Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A string bug in 1.2.8-s682 (*solved*)
#1
This does not work:

Code:
#Include "alloc.bas"
Declare function String$ (ByVal NumberOfChars as ubyte, ByVal Char as string) as string
Declare sub PlayScrBasic (byval SkyColor as ubyte)

Ink 7: Paper 0: Flash 0: Bright 1: Over 0: Inverse 0: Border 0: Cls
Print "Hello"

Const Black as ubyte = 0
Const Blue as ubyte = 1
Const Red as ubyte = 2
Const Magenta as ubyte = 3
Const Green as ubyte = 4
Const Cyan as ubyte = 5
Const Yellow as ubyte = 6
Const White as ubyte = 7

PlayScrBasic (Cyan)
End


Function String$ (ByVal NumberOfChars as ubyte, ByVal Char as string) as string

'Dim Chars$ as string

'Dim CharPtr as uinteger
'Dim CharsPtr as uinteger
'Dim CharsPtrDeallocate as uinteger
'CharStr
'NumberOfChars = NumberOfChars + 1
'CharsPtr = Allocate(NumberOfChars)
'Dim CharStr as string at @CharP


''CharP = @Char$
'Return "x" '@Char$

Dim i as ubyte

For i = 1 to NumberOfChars
  Chars$ = Chars$ + Char$
Next i

Return Chars$

End Function

sub PlayScrBasic (byval SkyColor as ubyte)

Dim i as ubyte
Dim Space32$ as string
Space32$ = String$(32, " ")

cls
Paper SkyColor
If SkyColor <> 0 then
  fOR i = 0 TO 12
    'Print at i, 0; String$(32, " ")
    Print at i, 0; Space32$
  Next i
End if
Space32$ = ""

Paper Green
Print at 11, 6; String$(21, " ")

FOR i = 8 TO 21
  Paper Red
  Print at i, 5; " "
  IF i > 11 THEN
    Print at i,5; String$(22, " ")
    IF i > 12 AND i < 21 THEN
      Paper Blue
      Print at i, 0; String$(5, " ")
      Print at i, 27; String$(5, " ")
    End if
  End if
Next i

Paper Yellow
Print at 21, 0; String$(5, "Û")
Print at 21, 27; String$(5, "Û")
Paper Black

end sub

However if I rem out everything that has Space32$ in it and unrem:
'Print at i, 0; String$(32, " ")'
Then it works fine and heap size does not seem to matter. If I press break
and restart the program then it fails on the second run even though it
works fine the first time if I make the changes noted above.

My bat file to compile this is as follows:
@echo off
if exist GAME.TAP del GAME.TAP
zxb Invasion.b --optimize=0 --output=GAME --tap --BASIC --autorun --org=39680 --array-base=0 --string-base=0 --heap-size=1280 --strict-bool --enable-break
ren GAME GAME.TAP

I do not trust this string handling and it would be nice to have a inbuildt
String$(NumChars, Char$) function.

Thanks,

Darkstar.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)