Reputation: 221
I'm trying to make a simple game in BASIC in QB64. I'm used to programming C# and am not shure how I should kinda make 'objects' (as far as possible) in BASIC with QB64 and use them by including them where I need.
I have my main Game.bas:
REM $INCLUDE: 'Includes.bas'
DrawWorld
REM $INCLUDE: '\Objects\Nodes\NodesMethods.bas'
Then the Includes.bas:
REM $INCLUDE: 'Settings.bas'
REM $INCLUDE: 'Assets.bas'
REM $INCLUDE: '\Objects\Nodes\Nodes.bas'
Settings.bas simply sets up stuff like FULLSCREEN etc. and Assets.bas load sound into memory. Those are just static code.
Nodes.bas however holds 'nodes' from my 2D world map:
TYPE Node
nodeType AS INTEGER
nodeName AS STRING
x AS INTEGER
y AS INTEGER
END TYPE
DIM SHARED numOfNodes AS INTEGER
DIM SHARED nodes(numOfNodes) AS Node
LOCATE 1, 1: PRINT "PLEASE WAIT, LOADING..."
LOCATE 2, 1: PRINT "Loading map nodes..."
numOfNodes = 100
REDIM nodes(numOfNodes) AS Node
FOR i = 1 TO numOfNodes
nodes(i).x = INT(RND * 2000)
nodes(i).y = INT(RND * 2000)
NEXT
This creates some nodes for the map with random position and this works fine. However now I want to draw them to and I want to be able to call the draw code whenever I need the screen updated so I want to put that in a SUB. Since no code is allowed after SUBs I put this SUB in WorldMethods.bas which is included at the end of the main Game.bas (see above). Then I call the DrawWorld method in my main Game.bas which works fine.
My problem: inside NodesMethods.bas I still see a syntax error saying "Invalid expression on line 3". I'm guessing it doesn't know what nodes is (but i'm not shure). I can't include Nodes.bas there because it's already included in Includes.bas (and twice is not allowed). I also can't move this SUB higher since SUBs must be at the end. I can put the whole Nodes.bas and NodesMethods.bas content together at the end, but I will have more types and then SUBs need to be at the bottom again.
SUB DrawWorld
FOR i = 1 TO numOfNodes
CIRCLE (nodes(i).x, nodes(i).y), 1, 15
NEXT
END SUB
Question 1: what's the problem on line 3 here Question 2: is this the way to work with these includes? How can I do this better?
Thanks in advance :)
Upvotes: 0
Views: 26