Post by Sprout on Aug 25, 2020 2:46:58 GMT
I get this error when I run this code:
loadbmp "player1", "Images\player1.bmp"
loadbmp "furnBmp", "Images\furn.bmp"
loadbmp "furnClickBmp", "Images\furnClick.bmp" 'furn as in furniture
loadbmp "cursorBmp", "Images\cursor.bmp"
loadbmp "chairBmp", "Images\woodChair.bmp"
loadbmp "tableBmp", "Images\woodTable.bmp"
loadbmp "xButtonBmp", "Images\x.bmp"
nomainwin
WindowWidth = 512
WindowHeight = 512
'index for the for loops
i = 0
treeWidth = 54
treeHeight = 69
treeX = WindowWidth / 2 - treeWidth
treeY = WindowHeight / 2 - treeHeight
'positions the tree in the center of the window
furnWidth = 64
furnHeight = 64
furnX = 0
furnY = 420
'booleans
furnButtonClicked = 0
furnMenuOpen = 0
dragging = 0
furnCount = 1 'amount of furniture - 1 because for loops start at 0
dim furnList$(furnCount) 'furniture list for the for loops
furnList$(0) = "chairSprite"
furnList$(1) = "tableSprite"
dim furnImgs$(furnCount) 'furniture images list for the for loops
furnImgs$(0) = "chairBmp"
furnImgs$(1) = "tableBmp"
'amount of space between the furniture pictures in the menu. The variables in there are the next pictures' widths.
'for example: the table's width is 96, and it is 2nd in the array. This means that the 3rd variable in the array will be 96.
dim furnMenuOffsets(furnCount)
furnMenuOffsets(0) = 64
furnMenuOffsets(1) = 64
'next will be 96
dim furnDragDrops$(furnCount) 'the actual furniture you can drag and drop in the window
furnDragDrops$(0) = "chairDragDrop"
furnDragDrops$(1) = "tableDragDrop"
open "Pet Tree" for graphics_nsb_nf as #window
print #window, "setfocus"
print #window, "trapclose [quit]"
print #window, "when characterInput [keyStrokes]"
print #window, "when leftButtonDown [cursorSpriteMove]" 'moves cursor sprite to wherever the mouse is
print #window, "when leftButtonUp [cursorSpriteReset]" 'moves cursor sprite to -10 -10 (a spot where it can't collide with anything on screen) to empty spriteList$
print #window, "addsprite tree player1"
print #window, "spritexy tree "; treeX; " "; treeY
print #window, "addsprite cursorSprite cursorBmp"
'adds a sprite to the cursor.
'this is what I have come up with to treat sprites like buttons in a graphics window.
print #window, "drawsprites"
print #window, "flush"
timer 10, [timerTick]
wait
[timerTick]
gosub [collisions]
gosub [buttons]
wait
[keyStrokes]
char$ = Inkey$
if char$ = "w" then treeY = treeY - 5
if char$ = "s" then treeY = treeY + 5
if char$ = "a" then treeX = treeX - 5
if char$ = "d" then treeX = treeX + 5
if treeX <= 0 then treeX = treeX + 5
if treeX >= 450 then treeX = treeX - 5
if treeY <= 0 then treeY = treeY + 5
if treeY >= 420 then treeY = treeY - 5
'for some reason, 512, the WindowWidth and WindowHeight, is not the border like 0 is.
'so I just did a little bit of guessing and testing to find where the right and bottom border collides with the tree,
'which is around 450 and 420 respectively.
print #window, "spritexy tree "; treeX; " "; treeY
print #window, "drawsprites"
wait
[cursorSpriteMove]
print #window, "spritexy cursorSprite "; MouseX; " "; MouseY
wait
[cursorSpriteReset]
print #window, "spritexy cursorSprite -10 -10"
furnButtonClicked = 0
dragging = 0
wait
[collisions]
print #window, "spritecollides cursorSprite spriteList$"
if spriteList$ = "furnSprite" then furnButtonClicked = 1
if spriteList$ = "xButtonSprite" then xClicked = 1
for i = 0 to furnCount
if spriteList$ = " "; furnList$(i) then 'error happens because of this line of code
print "hi"
'dragging = 1
'print #window, "addsprite "; furnDragDrops$(i); " "; furnImgs$(i)
'print #window, "spritexy "; furnDragDrops$(i); " "; MouseX; " "; MouseY
end if
next
return
[buttons]
if furnButtonClicked = 0 then
print #window, "addsprite furnSprite furnBmp"
print #window, "spritexy furnSprite "; furnX; " "; furnY
end if
if furnButtonClicked = 1 then
furnMenuOpen = 1
print #window, "addsprite furnSprite furnClickBmp"
print #window, "spritexy furnSprite "; furnX; " "; furnY
end if
if furnMenuOpen = 1 then 'creates some sort of menu where you can see all the furniture you have
for i = 0 to furnCount
print #window, "addsprite "; furnList$(i); " "; furnImgs$(i)
print #window, "spritexy "; furnList$(i); " "; furnX + furnMenuOffsets(i) * (i + 1); " "; furnY
next
print #window, "addsprite xButtonSprite xButtonBmp"
print #window, "spritexy xButtonSprite 475 420"
if xClicked = 1 then 'closes the furniture menu
for i = 0 to furnCount
print #window, "removesprite "; furnList$(i)
next
print #window, "removesprite xButtonSprite"
furnMenuOpen = 0
xClicked = 0
end if
end if
print #window, "drawsprites"
return
[quit]
close #window
end
The error happens because of this line of code: spriteList$ = " "; furnList$(i) then ... end if
From what I see, it's just checking if a string is equal to another string in an array. I don't understand why this gives me an error.