Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sub not Reconizing Dim as String
#10
this is a snippet, i have moved heaps about. i can get it to run in main sub no problem. but not in the other... 
Code: (Select All)
' ---------- Varable Tables Start Here

Const Diamond_Ti = "d"
Const Diamond_Td = "D"
Const Rock_Fallt = "R"
Const Rock_Stati = "r"
Const HumanPlay = "X"
Const LevelExit = "P"
Const SteelWall = "W"
Const BrickWall = "w"
Const MajicWall = "m"
Const MagicWall = "M"
Const DirtyTile = "."
Const EmptyTile = " "
Const Butterfly = "B"
Const Boxxerfly = "q"
Const Explodebt = "!"
Const explodebx = "@"
Const HumanEdie = "#"
Const Levelopen = "z"
' ---------- Screen Size Settings and Sprites Setups
Const TILEW = 16 '                                      Tile Width
Const TILEH = 16 '                                      Tile Height
Const SHEETCOLS = 8 '                                   Sprite Counter X  8 sprites x 12 sprites on sheet
Const SHEETROWS = 12 '                                  Sprite Counter Y
Const TILECOUNT = SHEETCOLS * SHEETROWS
Const MAP_WIDTH = 40 '                                  Map Width
Const MAP_HEIGHT = 22 '                                 Map Height
Const TOTAL_MAPS = 30 '                                 Total Maps To load into Ram

' ---------- Dimension Arays Shared Vars

Dim Shared SpriteTable As Integer
Dim Shared Sheet As Long
Dim Shared sprite(0 To TILECOUNT - 1) As Long
Dim Shared TestPattern As Integer
Dim Shared MapRom(30, 1 To MAP_HEIGHT) As String
Dim Shared CurrentMap As Integer
Dim Shared MapLines(1 To MAP_HEIGHT) As String
Dim Shared MapComplete As Integer
Dim Shared DiamondFrameCounter As Single
Dim Shared DiamondAnimationSpeed As Single
Dim Shared DiamondCount As Integer
Dim Shared KeyBoardRepeat As Integer
Dim Shared SUBtileChar As String
Dim Shared PlayerX As Integer
Dim Shared PlayerY As Integer

' ---------- Startup Values

TestPattern = 0
SpriteTable = 3
CurrentMap = 5
DiamondAnimationSpeed = 0.05
KeyBoardRepeat = 0.05
MapComplete = 0
DiamondCount = 0

' ---------- Set Screen Mode
Screen _NewImage(320, 224, 32)
$Resize:Smooth


' Test Sprite Sheet

' -----------------------------
' Cross-hatch grid (MAME style)
' -----------------------------
For x = 0 To 320 Step 16
    Line (x, 0)-(x, 223), _RGB(80, 80, 80)
Next
For y = 0 To 224 Step 16
    Line (0, y)-(319, y), _RGB(80, 80, 80)
Next

' -----------------------------
' Draw all sprites in a grid
' -----------------------------
col = 0
row = 0
For i = 0 To TILECOUNT - 1
    _PutImage (col * TILEW, row * TILEH), sprite&(i)
    col = col + 1
    If col >= 20 Then ' 320 / 16 = 20 tiles across
        col = 0
        row = row + 1
    End If
Next
Dim clr&(5)
clr&(0) = _RGB(255, 0, 0)
clr&(1) = _RGB(0, 255, 0)
clr&(2) = _RGB(0, 0, 255)
clr&(3) = _RGB(255, 255, 255)
clr&(4) = _RGB(128, 128, 128)
clr&(5) = _RGB(0, 0, 0)

For i = 0 To 5
    Line (i * 53, 188)-(i * 53 + 52, 223), clr&(i), BF
Next

' -----------------------------
' Corner labels
' -----------------------------
_PrintString (8, 8), "TOP LEFT"
_PrintString (240, 8), "TOP RIGHT"
_PrintString (8, 208), "BOTTOM LEFT"
_PrintString (216, 208), "BOTTOM RIGHT"

' -----------------------------
' Optional color bars (bottom row)
' -----------------------------

Do
    _Limit 7
Loop While InKey$ <> " "


'---------- Timers For Player Field
DiamondTicker:
DiamondFrameCounter = (DiamondFrameCounter + 1) Mod 8
Return

' ==============================================
' Copies the current map from ROM to RAM
' ==============================================
Sub CopyMapFromRom
    Dim rowIndex As Integer

    ' Copy the selected map from ROM into the working array
    For rowIndex = 1 To MAP_HEIGHT
        MapLines(rowIndex) = MapRom(CurrentMap, rowIndex)
    Next rowIndex
End Sub
' ---------------- find player start, count diamonds

Sub DisplayMapASCII
    Dim rowIndex As Integer

    Screen 0
    Width 80, 25

    Cls ' Clear screen for clean output

    For rowIndex = 1 To MAP_HEIGHT
        Print MapLines(rowIndex)
    Next rowIndex

    Print "Press any key to continue..."
    Do While InKey$ = ""
        _Limit 30 ' Limit CPU usage
    Loop

End Sub

Sub LoadSpriteTable
    Dim tileIndex As Integer, row As Integer, col As Integer, x As Integer, y As Integer

    ' Free previous sheet if needed
    If Sheet& <> 0 Then _FreeImage Sheet&

    ' === Load the sprite sheet based on SpriteTable ===
    Select Case SpriteTable
        Case 1 To 20
            Sheet& = _LoadImage("l0_sprite_" + Right$("00" + LTrim$(Str$(SpriteTable)), 2) + ".png", 32)
        Case Else
            Print "Invalid SpriteTable number: "; SpriteTable
            End
    End Select

    If Sheet& = -1 Then
        Print "Error loading sprite sheet l0_sprite_"; Right$("00" + LTrim$(Str$(SpriteTable)), 2); ".png"
        End
    End If

    ' === Cut into individual sprites ===
    tileIndex = 0
    For row = 0 To SHEETROWS - 1
        For col = 0 To SHEETCOLS - 1
            x = col * TILEW
            y = row * TILEH

            ' Free old tile if it exists
            If sprite&(tileIndex) <> 0 Then _FreeImage sprite&(tileIndex)

            ' Insert New Sprites
            sprite&(tileIndex) = _NewImage(TILEW, TILEH, 32)
            _PutImage (0, 0)-(TILEW - 1, TILEH - 1), Sheet&, sprite&(tileIndex), (x, y)-(x + TILEW - 1, y + TILEH - 1)
            tileIndex = tileIndex + 1
        Next
    Next

    _FreeImage Sheet&
End Sub

'$Include: 'RamTable.bi'

SpriteTable = 3 '                   Sprite Table / Color Map
LoadSpriteTable

Cls
TestPattern = 0

If TestPattern = 1 Then
    '$Include: 'TestScreenSprites.lnk'
    _MouseMove 20, 40 'center mouse pointer on screen
    End
End If

'$Include: 'Maps.lnk'

' ---------- Load Map Number
CurrentMap = 5

CopyMapFromRom

If TestPattern = 2 Then
    DisplayMapASCII
    End
End If

' ---------- Timers
DiamondFrameCounter = _FreeTimer
On Timer(DiamondFrameCounter, DiamondAnimationSpeed) GoSub DiamondTicker
KeyBoardRepeat = _FreeTimer

On Timer(KeyBoardRepeat, KeyBoardRepeat) GoSub KeyBoardRoutine ' ticks turn on/off to synce as needed





_FullScreen
' ---------- Draw Screen
Timer(DiamondFrameCounter) On
For i = 1 To 300
    DisplayMapGraphics
    _Limit 30
Next i
Timer(KeyBoardRepeat) On

Do
    DisplayMapGraphics
    _Limit 30
    GoSub KeyBoardRoutine:
Loop While InKey$ <> " "
'Timer(DiamondFrameCounter) Off
End

' ---------- KeyBoard Routine for movement
KeyBoardRoutine:
SHFT% = _KeyDown(100303) Or _KeyDown(100304)
QUIT% = _KeyDown(27)
KeyBoardUP% = _KeyDown(18432)
KeyBoardDN% = _KeyDown(20480)
KeyBoardLT% = _KeyDown(19200)
KeyBoardRT% = _KeyDown(19712)

If KeyBoardUP% = -1 Then

End If

If KeyBoardDN% = -1 Then

End If

If KeyBoardLT% = -1 Then

End If

If KeyBoardRT% = -1 Then

End If

Return

' ---------- All Sub Routines from Here.. Subs before Functions

''$Include: 'ConfigureMap.lnk'
'$Include: 'TimerCounter.lnk'
'$Include: 'LoadMapFromRom.lnk'
'$Include: 'DisplayMapAsAscii.lnk'
'$Include: 'Sprites.lnk'

' ---------- Display Screen Graphics

Sub DisplayMapGraphics
    Dim camX As Integer, camY As Integer ' Player/camera position in tiles
    Dim startCol As Integer, startRow As Integer
    Dim endCol As Integer, endRow As Integer
    Dim drawX As Integer, drawY As Integer
    Dim rowIndex As Integer, colIndex As Integer
    Dim tileChar As String
    Dim spriteIndex As Integer

    ' -----------------------------
    ' Window size in tiles
    ' -----------------------------
    Const WINDOW_WIDTH = 40
    Const WINDOW_HEIGHT = 22


    ' -----------------------------
    ' Find player position in map
    ' -----------------------------
    For rowIndex = 1 To MAP_HEIGHT
        For colIndex = 1 To MAP_WIDTH
            If Mid$(MapLines(rowIndex), colIndex, 1) = HumanPlay Then
                camX = colIndex
                camY = rowIndex
                Exit For
            End If
        Next colIndex
    Next rowIndex

    ' -----------------------------
    ' Determine visible window bounds
    ' -----------------------------
    startCol = camX - (WINDOW_WIDTH \ 2)
    startRow = camY - (WINDOW_HEIGHT \ 2)
    endCol = startCol + WINDOW_WIDTH - 1
    endRow = startRow + WINDOW_HEIGHT - 1

    ' Clamp to map edges
    If startCol < 1 Then startCol = 1
    If startRow < 1 Then startRow = 1
    If endCol > MAP_WIDTH Then
        endCol = MAP_WIDTH
        startCol = endCol - WINDOW_WIDTH + 1
        If startCol < 1 Then startCol = 1
    End If
    If endRow > MAP_HEIGHT Then
        endRow = MAP_HEIGHT
        startRow = endRow - WINDOW_HEIGHT + 1
        If startRow < 1 Then startRow = 1
    End If

    ' -----------------------------
    ' Draw visible map
    ' -----------------------------
    For rowIndex = startRow To endRow
        For colIndex = startCol To endCol
            tileChar = Mid$(MapLines(rowIndex), colIndex, 1)

            ' Map character to sprite index
            Select Case tileChar
                Case HumanPlay
                    spriteIndex = 0
                Case LevelExit
                    ' You could animate or alternate between 48 and 49
                    spriteIndex = 49
                Case Boxxerfly
                    spriteIndex = 72 + DiamondFrameCounter
                Case Butterfly
                    spriteIndex = 88 + DiamondFrameCounter
                Case "d", "D"
                    spriteIndex = 80 + DiamondFrameCounter
                Case "r"
                    spriteIndex = 56
                Case "M"
                    spriteIndex = 51
                Case "m"
                    spriteIndex = 51 + DiamondFrameCounter Mod 4
                Case DirtyTile
                    spriteIndex = 57
                    'Case "!", "@"
                    '    spriteIndex = 1 + ((colIndex + rowIndex) Mod 3) ' 1-3
                Case SteelWall
                    spriteIndex = 49
                Case BrickWall
                    spriteIndex = 4
                Case Else
                    spriteIndex = 48 ' fallback
            End Select

            ' Draw tile
            drawX = (colIndex - startCol) * TILEW
            drawY = (rowIndex - startRow) * TILEH
            _PutImage (drawX, drawY), sprite&(spriteIndex)
        Next colIndex
    Next rowIndex
End Sub
' ---------------- find player start, count diamonds
Sub LookforPlayerStartPosition:
    For rowIndex = 2 To 21 ' Y
        For colIndex = 2 To 38 ' X
            SUBtileChar = Mid$(MapLines(rowIndex), colIndex, 1)
            If SUBtileChar = Diamond_Ti Then DiamondCount = DiamondCount + 1
            If SUBtileChar = HumanPlay Then
                PlayerY = rowIndex
                PlayerX = colIndex
            End If
        Next colIndex
    Next rowIndex
End Sub
Reply


Messages In This Thread
Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 12:25 AM
RE: Sub not Reconizing Dim as String - by bplus - 10-05-2025, 12:44 AM
RE: Sub not Reconizing Dim as String - by bplus - 10-05-2025, 01:47 AM
RE: Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 04:21 AM
RE: Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 04:37 AM
RE: Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 05:46 AM
RE: Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 07:58 AM
RE: Sub not Reconizing Dim as String - by bplus - 10-05-2025, 01:38 PM
RE: Sub not Reconizing Dim as String - by pmackay - 10-05-2025, 01:40 PM
RE: Sub not Reconizing Dim as String - by bplus - 10-05-2025, 01:55 PM
RE: Sub not Reconizing Dim as String - by bplus - 10-05-2025, 03:21 PM
RE: Sub not Reconizing Dim as String - by pmackay - 10-16-2025, 11:18 AM
RE: Sub not Reconizing Dim as String - by bplus - 10-16-2025, 11:54 AM
RE: Sub not Reconizing Dim as String - by pmackay - 10-16-2025, 01:41 PM
RE: Sub not Reconizing Dim as String - by pmackay - 10-16-2025, 03:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,220 12-19-2025, 12:51 PM
Last Post: Heimdall
  Illegal string-number conversion Herve 7 769 07-07-2025, 09:53 AM
Last Post: a740g
  need help printing a scaled string in a custom font to a 32-bit image madscijr 9 1,159 07-03-2025, 04:48 PM
Last Post: SMcNeill
  DIM - AS - VARIABLE TYPE likely bug bartok 25 5,467 05-06-2024, 08:21 PM
Last Post: SMcNeill
  How to reorder string variable x factorial different ways? Circlotron 13 2,651 04-27-2024, 02:43 AM
Last Post: PhilOfPerth

Forum Jump:


Users browsing this thread: 1 Guest(s)