Hello ,
I am trying to program with this language and I receiving strange errors which there is not error in my code.
I have create one project which my game will be.
This project have seperate files for each of my functions.
All my types I have put them in one file types.dba
All my variables I have put them in one file variables.dba
I have create one main file which is my main file to know where my program starts , like similar with c++ we have a main program with the main function.
There is no main function in darkbasic , but I used to have one main file which the main function will be there , I simulate one main function.
In fact there is not main function , but the main game loop. I call this file main.dba
I have all variables and types called from my main file with #include function and I put these files at the top of my program which I will initiate all my global variables and types.
In the top of my main file I have this code
#include "variables.dba"
#include "types.dba"
These files are also in my project.
My viariables files contains this code:
Rem ***** Included Source File *****
global pointer_x
global pointer_y
global pointer_b
global press_down,press_up,press_left,press_right,press_tleft,press_tright
global press_down1,press_up1,press_left1,press_right1
global flip_backdrop
global walking_step
global plevel
global px,py,pdirection
global dim all_levels(10,30,30,4)
And types file contains this code:
Rem ***** Included Source File *****
type my_party
x as integer `my party x on the map
y as integer `my party y on the map
direction as integer `my party direction 1:North 2:south 3:East 4:West
level as integer `my party is on the level
ENDTYPE
global party as my_party
Somewhere in my main file I call one function keyboard_commands()
Which there is one seperate file keyboard_commands.dba which contains all my code which player will have all keyboard input commands like , move player with arrows , turn player arround in the level.
The keyboard_commands.dba file is in the project as well.
somewhere in my program , I need to create one 4 dimensional array which initialize all my levels of my game.
In my variables.dba file I use:
global dim all_levels(10,30,30,4)
Which for me means , I get ready for my 10 levels with 30x30 squares and each square have 4 sides.
So far so good. But somewhere I am calling one function:
Which calls one function from a seperate file init_levels.dba from my project , this file also included in my project , not called with #include command , but just included in my project at the left of my IDE.
I am calling the function init_levels() to empty all cells of my array and give default value 0 to all squares and levels.
The init_levels.dba file contains this code:
Function init_levels()
for plevel=0 to 10
for px=0 to 30
for py=0 to 30
for pdirection=0 to 4
all_levels(plevel,px,py,pdirection)=0
next pdirection
next py
next px
next plevel
ENDFUNCTION
This function scans my big 4dimensional array and put 0 value to everything.
When I run my program , I have this error:
Cannot find structure 'init_levels:plevel' in local declaration inside types.dba.
There is not any type with plevel in my types.dba file
My variable plevel was global and included in variables.dba at the main file at the beginning of my program with #include command.
Why the compiler doesn't recognize my plevel variable and the error is very strange (discribe it as structure) and the IDE does not indicates "highlights" and I don't know where is the error.
All my variables are global , and my types are global and have already initialized at the beginning of the program.
Another one thing I tried , was to run my initializing of my array with type.
Like this:
Function init_levels()
for party.level=0 to 10 <------ the error indicates here
for party.x=0 to 30
for party.y=0 to 30
for party.direction=0 to 4
all_levels(party.level,party.x,party.y,party.direction)=0
next
next
next
next
ENDFUNCTION
And another strange error appeared:
Variable in FOR NEXT loop cannot be a complex data type at line 327.
The line 327 does not exist , but is the line 3 of this file.
The IDE does not calculate the error line correct and as I know in c++ at least , you can use for loop , with structs (types in basic)
Why darkbasic doesn't allow types in one for next loop.
Many times , I tried to program , normaly with this language , and strange errors always received and I stop my game.
And my code was correct...