Hey guys,
I've just started with programming and im using a Tutorial on youtube to make my first Jump n Run game. I did exactly as it's done in the Video but i get a Bug Report (fatal error) :'(
The Turorial (I'm German so I needed a German tut...): No.1
No.2
Bug Report:GPC - GLBasic Precompiler V.10.104 SN:409de90b - 2D, WIN32Wordcount:34 commandscompiling:C:\Users\SEBAST~1\AppData\Local\Temp\glbasic\gpc_tempg.cpp: In member function `DGInt __GLBASIC__::TPlayer::Update()':C:\Users\SEBAST~1\AppData\Local\Temp\glbasic\gpc_tempg.cpp:47: error: invalid initialization of non-const reference of type 'bool&' from a temporary of type 'bool'C:/Program Files (x86)/GLBasic/Compiler/platform/Include/glb.h:1182: error: in passing argument 1 of `void __GLBASIC__::INC(T&) [with T = bool]'*** FATAL ERROR - Bitte die Compiler-Ausgabe ins Forum kopieren
My Codes:SETCURRENTDIR("Media") // go to media files
GLOBAL Player AS TPlayer //Spieler erstellenGLOBAL Map AS TMap //Map erstellen
GOSUB InitWHILE TRUE
GOSUB Update GOSUB Render
SHOWSCREEN
WEND
SUB Update:
Player.Update() Map.Update ()
ENDSUB
SUB Render:
Player.Render() Map.Render ()
ENDSUB
SUB Init:
Player.Init (100,100) Map.Init("map0.map")
ENDSUB
//Spieler
TYPE TPlayer
x; y vx; vy //Vektor x,y width%; height% HP% //...
FUNCTION Init: x, y, width% = 16, height% = 32
self.x = x self.y = y self.vx = 0 self.vy = 0
self.width = width self.height = height
ENDFUNCTION
FUNCTION Update:
//Schwerkraft INC self.vy = 0.5
//Bewegung IF KEY(203) THEN DEC self.vx, 1 //links IF KEY(205) THEN INC self.vx, 1 //rechts
// IF KEY(200) THEN INC self.vy, 2 //oben// IF KEY(208) THEN DEC self.vy, 2 //unten
//trägheit self.vx = self.vx* 0.8
//bewege INC self.x, self.vx INC self.y, self.vy
ENDFUNCTION
FUNCTION Render:
DRAWRECT self.x, self.y, self.width, self.height, RGB(255,0,0)
ENDFUNCTION
ENDTYPE
Thank You for any Help guys!
Edit: Changed to code tags /Moru
Hello xxbastianxx! Welcome to the boards! :good:
Instead of [spoiler] try paste your code between code, it is the # button over the smiles.
That makes it a lot faster for us to check it out.
It should look like this:
SETCURRENTDIR("Media") // go to media files
GLOBAL Player AS TPlayer //Spieler erstellenGLOBAL Map AS TMap //Map erstellen
GOSUB InitWHILE TRUE
GOSUB Update GOSUB Render
SHOWSCREEN
WEND
SUB Update:
Player.Update() Map.Update ()
ENDSUB
SUB Render:
Player.Render() Map.Render ()
ENDSUB
SUB Init:
Player.Init (100,100) Map.Init("map0.map")
ENDSUB
//Spieler
TYPE TPlayer
x; y vx; vy //Vektor x,y width%; height% HP% //...
FUNCTION Init: x, y, width% = 16, height% = 32
self.x = x self.y = y self.vx = 0 self.vy = 0
self.width = width self.height = height
ENDFUNCTION
FUNCTION Update:
//Schwerkraft INC self.vy = 0.5
//Bewegung IF KEY(203) THEN DEC self.vx, 1 //links IF KEY(205) THEN INC self.vx, 1 //rechts
// IF KEY(200) THEN INC self.vy, 2 //oben// IF KEY(208) THEN DEC self.vy, 2 //unten
//trägheit self.vx = self.vx* 0.8
//bewege INC self.x, self.vx INC self.y, self.vy
ENDFUNCTION
FUNCTION Render:
DRAWRECT self.x, self.y, self.width, self.height, RGB(255,0,0)
ENDFUNCTION
ENDTYPE
I´m not quite familiar with this one tutorial, but someone will be and getting back to you soon.
Again, welcome aboard!
this should work, i pointed out where the errors were in the code
You'll need to edit what's in the Update(): Function to match his code
as all it does at the moment is move the box downwards
SETCURRENTDIR("Media") // go to media files
GLOBAL Player AS TPlayer //Spieler erstellenGLOBAL Map AS TMap //Map erstellen
GOSUB Init
WHILE TRUE
GOSUB Update
GOSUB Render
SHOWSCREEN
WEND
SUB Update:
Player.Update()
Map.Update ()
ENDSUB
SUB Render:
Player.Render()
ENDSUB
SUB Init:
Player.Init (100,100)
Map.Init("map0.map")
ENDSUB
//Spieler
TYPE TPlayer
x; y; vx; vy; //Vektor x,y width%; height% HP% //...
width% //<###### This was missing
height% //<###### this was missing
FUNCTION Init: x, y, width% = 16, height% = 32
self.x = x
self.y = y
self.vx = 0
self.vy = 0
self.width = width
self.height = height
ENDFUNCTION
FUNCTION Update:
INC self.vy, 0.5 //<####### this was //Schwerkraft INC self.vy = 0.5 should be , instead of =
IF KEY(203) THEN DEC self.vx, 1 //links IF KEY(205) THEN INC self.vx, 1 //rechts
IF KEY(200) THEN INC self.vy, 2 //oben// IF KEY(208) THEN DEC self.vy, 2 //unten
self.vx = self.vx* 0.8
INC self.x, self.vx
INC self.y, self.vy
ENDFUNCTION
FUNCTION Render:
DRAWRECT self.x, self.y, self.width, self.height, RGB(255,0,0)
ENDFUNCTION
ENDTYPE
[code=glbasic]
ATM it cant work, since it is missing a definition of the type TMap.
i'm assuming the map code is in another source code file as shown in the second tutorial video
Hey guys,
Yeah sorry, I was looking for that, but didn't find it. Ty for editing it.
TMap is in a other source. I didn't bring that up, because I wanted the player to work first.
Ty for the Help - the "," was the only mistake! ;) (if u look again I had width, height there - that was correct)
I don't understand why it gives me a bug report which is 100 symbols long just cauz a "," is wrong but ok. ^^
Thank you very much. I ll probably need some more help sooner or later.
Regards,
Seb
Hi xxbastianxx willkomen to the Community!!! but guy =D I think for your first code your use a very complex thing... go bit a bit... You have all the time in the World :D
I don't look what's happends but not worry all the people are here, we using GLbasic everyday and runs very fine.. perhaps you find something in the help or another place in the forum don't works, basically the code it's very very old, and somethings going chaiging whit the time... like the good wine =D !!!
Then only say you wellcome, and try to make more simple things, sure you undertand all the steps for do anything you want...
Regards,
Iván J
Haha :) Ty Ivan!
I've got another bug report, but this time it only says "Syntax error" ... -.-'
[b]Main Code[/b]
SETCURRENTDIR("Media") // go to media files
GLOBAL Player AS TPlayer //Spieler erstellen
//GLOBAL Map AS TMap //Map erstellen
GOSUB Init
WHILE TRUE
GOSUB Update
GOSUB Render
SHOWSCREEN
WEND
SUB Update:
Player.Update()
Map.Update ()
ENDSUB
SUB Render:
Map.Render ()
Player.Render()
ENDSUB
SUB Init:
Player.Init (100,100)
Map.Init("map0.map")
ENDSUB
[b]Map[/b]
CONSTANT tilesize = 16
//Spielkarte
TYPE TMap
data$[]
width% ; height%
scrollx; scrolly
Tilesize% //speichert Frames
FUNCTION Init: Name$
LOCAL chn% = GENFILE ()
LOCAL line$
IF OPENFILE ( chn, name$ , 1) = FALSE THEN END
READLINE chn, line$
width.self = INTEGER (line$)
READLINE chn, line$
width.self = INTEGER (line$)
DIM self.datas[self.width][self.height]
WHILE ENDOFFILE (chn%) = FALSE
READLINE chn% , line$
LOCAL tile$[]
SPLITSTR (line$, tile$[], ",")
FOREACH tile IN tile$[]
x=0
FOREACH tile IN tile$ []
self.datas$ [x][y] = INTEGER(tile)
INC x
NEXT
INC y
WEND
ENDFUNCTION
FUNCTION Update:
ENDFUNCTION
FUNCTION Render:
FOR x = 0 TO self.width - 1
FOR y = 0 TO self.height -1
SELECT self.datas$[x][y]
CASE 0
CASE 1
DRAWRECT x*tilesize, y*tilesize, tilesize, tilesize , RGB(0, 255 ,0)
ENDSELECT
NEXT
NEXT
ENDFUNCTION
ENDTYPE
[b]map0.map[/b]
15 // this is wher it shows me the yellow ARROW of mistake ^^
6
0,0,0,0,0,1,0,0,0,1,1,0,1,0,0
0,0,0,0,0,0,0,0,0,0,1,0,0,0,0
1,0,1,0,0,0,0,0,0,0,1,0,0,1,0
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
I reffer to the tutorials above.
As I created the "map0.map" I couldnt do it like in the video, I clicked on "other" right click and then create new file... it should of opened map0.map in "Other" but it opened in "Sources" so maybe that could be the Problem, but I dont think so.
I've got a screenshot attached to the post. (Green is where it is in the Vid... Red where it is in my Program)
I really appreciate every help! I honor you guys, who can programm well and find mistakes by them selves, unfortunately I'm not that far jet.
Regards,
Seb
[attachment deleted by admin]
In the video he creates "map0.map" which is not a GLBasic file, which means it gets ignored by the compiler. You created "map0.map.gbas" which is a GLBasic file, which is why the compiler checks it. And of cause the map data that you write inside it are not proper GLB syntax, so the compiler is totaly right to give you an syntax error.
Just remove the file from the project, rename it to "map0.map" and add it to the project.
Hey, ty for the idea but it didn't work. The computer allways saves it as .gbas file eventhough i write "map0.map" and press "save". When i open the file, it still shows me "map0.map.gbas"
Why does it do that ? Maybe I ve got some settings wrong ?
Ty for any help!
HI xxbastianxx yes the problem it's because you save the file from GLbasic, alwais you obtain a glbas file, if you want add another file whit another extension, you have to modify out GLbasic, in example if you make a simple txt file and you save whit txt, and then load into the tree of files of GLbasic , you can see this file it's a txt...
GLbasic works whit GLbas files C++ and you can add txt files, fut really I never use never...
don't mind not trouble in this part in C4d, and less in the actual Stable version...
Wellcome to the Boards!!! :good: :booze:
Yes, just rename it in windows, outside of GLB.
So I can open text editor from windows and put in some numbers like
1,1,1,1
0,1,0,1
and it will create my map in gl basic ? :O Sounds weird.
I'm sorry that this easy problem is taking so long, but in the video, he just saves it under map0.map from gl basic into the media file and it works... (look at no2 video I posted. [04:50 min] ... )
A file is a file is a file. As long as you say 'here, use this file!' it does not matter how it was created, it just needs to be there.
No problem, we're here tio help. ;)
The video is old, so obviously something has changed since it was created. GLB is under active development, new features get added etc... From time to time you will find some outdated informations in the helpfile, this forum or 3rd party tutorials, so you need to find a work around if this happens.
Quote from: xxbastianxx on 2013-Feb-14
So I can open text editor from windows and put in some numbers like
1,1,1,1
0,1,0,1
and it will create my map in gl basic ? :O Sounds weird.
I'm sorry that this easy problem is taking so long, but in the video, he just saves it under map0.map from gl basic into the media file and it works... (look at no2 video I posted. [04:50 min] ... )
It is not that much weird, You can have a map made of 0s and 1s, either read from a file or in a DATA statement, and then get that into an array to draw things.
I tried out the videos, but it is done on a alien language I can´t understand! :S :P
I will look at the code later, try to figure it out.
Sorry guys, but I cant get it to work. I just made a .txt file with the editor and used that as my first map ( a set of 1s and 0s like in tut) , it says that it can not open map0.txt ...
Have u got other easy options for me, how i can make my map ? I just dont want it to be too far of the tutorial which i m watching...
It's just a lot nicer if i can see how and if the stuff works, which i'm writing... and if I continue with the tutorial without having the game to work, then it's going to be hard to find out what's the problem.
It would be great if u could post me a code where I can easily see what u did and what i have to do.
Kind Regards,
Seb
What says it can not open map0.txt? And when? Are you sure you named it map0.txt now? Is it in the right folder so the program can find it?
Quote from: xxbastianxx on 2013-Feb-19
...
Have u got other easy options for me, how i can make my map ?
...
One possible route would be to make your map files out of 0 and 1s inside the code, with a DATA command and then you READ that into an array. I did similar on an old board game.
In regards to simplicity, why not just use characters to represent tile and pickup indices and then read the file data in code? For example:
o###o
#S.S#
# #
o#####o o####o
#S S#
# #
# * * #
# #
#S K S#
o#o#########o##o
A data text file doesn't need to be part of the GLB project but just in the local folder. erico's DATA statement suggestion is a perfect start but string arrays work well also, if visual constructing it. Formally, the data text file should be opened and read in code, preferably in index format where each index represents a anim sprite position.
Quote from: kanonet on 2013-Feb-19
What says it can not open map0.txt? And when? Are you sure you named it map0.txt now? Is it in the right folder so the program can find it?
It just says "Not Abel to Open Media/mediapp/map0.txt" or so... It s all correct.
Quote from: matchy on 2013-Feb-20
In regards to simplicity, why not just use characters to represent tile and pickup indices and then read the file data in code? For example:
o###o
#S.S#
# #
o#####o o####o
#S S#
# #
# * * #
# #
#S K S#
o#o#########o##o
A data text file doesn't need to be part of the GLB project but just in the local folder. erico's DATA statement suggestion is a perfect start but string arrays work well also, if visual constructing it. Formally, the data text file should be opened and read in code, preferably in index format where each index represents a anim sprite position.
Hey, Ty for your post, but I m just starting to learn programming so I don't rlly know what you mean. Could you show me in code ?
I seemed to fix the problem with the map... but now it shows me:
"My Jump and Run.gbas"(59) error : user type is not defined : TYPE TMap is not declared
CONSTANT tilesize = 16
//Spielkarte
TYPE TMap // <------------- I have declared it ... ??? WHAT'S WRONG WITH IT!?
data$[]
width% ; height%
scrollx; scrolly
Tilesize% //speichert Frames
FUNCTION Init: Name$
LOCAL chn% = GENFILE ()
LOCAL line$
IF OPENFILE ( chn, name$ , 1) = FALSE THEN END
READLINE chn, line$
width.self = INTEGER (line$)
READLINE chn, line$
width.self = INTEGER (line$)
DIM self.datas[self.width][self.height]
WHILE ENDOFFILE (chn%) = FALSE
READLINE chn% , line$
LOCAL tile$[]
SPLITSTR (line$, tile$[], ",")
FOREACH tile IN tile$[]
x=0
FOREACH tile IN tile$ []
self.datas$ [x][y] = INTEGER(tile)
INC x
NEXT
INC y
WEND
ENDFUNCTION
FUNCTION Update:
ENDFUNCTION
FUNCTION Render:
FOR x = 0 TO self.width - 1
FOR y = 0 TO self.height -1
SELECT self.datas$[x][y]
CASE 0
CASE 1
DRAWRECT x*tilesize, y*tilesize, tilesize, tilesize , RGB(0, 255 ,0)
ENDSELECT
NEXT
NEXT
ENDFUNCTION
ENDTYPE
SETCURRENTDIR("Media") // go to media files
GLOBAL Player AS TPlayer //Spieler erstellen
GLOBAL Map AS TMap //Map erstellen <------------- should be GLOBAL ... ? What did i miss ?
GOSUB Init
WHILE TRUE
GOSUB Render
GOSUB Update
SHOWSCREEN
WEND
SUB Update:
Player.Update()
Map.Update ()
ENDSUB
SUB Render:
Map.Render ()
Player.Render()
ENDSUB
SUB Init:
Player.Init (100,100)
Map.Init("map0.txt")
ENDSUB
(edited for language, please keep it civil. We do have kids here. :) )
I'm sorry...
"Player.gbas"(72) error : wrong argument type : TYPE TMap is not declared I just can not find the Problem...
It would be awesome if someone could help me .. .
TYPE TPlayer
x; y
vx; vy //Vektor x,y
width%
height%
HP%
scrollx; scrolly
//...
FUNCTION Init: x, y, width% = 32, height% = 64
self.x = x
self.y = y
self.vx = 0
self.vy = 0
self.width = width
self.height = height
ENDFUNCTION
FUNCTION Update:
LOCAL width, height
GETSCREENSIZE width, height
//Schwerkraft
INC self.vy, 0.01
//Bewegung
IF KEY(203) THEN DEC self.vx, 1 //links
IF KEY(205) THEN INC self.vx, 1 //rechts
IF KEY(57) AND (Map.CollisionPoint(self.x + 1, self.y + self.height +1) OR Map.CollisionPoint(self.x + self.width -1, self.y + self.height +1)) THEN self.y = -4 //space
//trägheit
self.vx = self.vx* 0.5
LOCAL oldx, oldy
oldx = self.x
oldy = self.y
//grenze
IF self.vy > 8 THEN self.vy = 8
IF self.vy < -8 THEN self.vy = -8
//bewege & kollision
INC self.x, self.vx
IF Map.Collision(self.X+1, self.y+1, self.width-2, self.height-2)
self.x = oldx
ENDIF
INC self.y, self.vy
IF Map.Collision(self.X+1, self.y+1, self.width-2, self.height-2)
self.x = oldx
self.y = oldy
Map.scrollx = - self.x + width/2 + width/2
Map.scrolly = - self.y + height/2 + height/2
ENDIF
ENDFUNCTION
FUNCTION Render:
DRAWRECT self.x + 1 + Map.scrollx, self.y + Map.scrolly, self.width, self.height, RGB(255,0,0)
DRAWANIM PlayerImage, 0, self.x + 1 + Map.scrollx, self.y + Map.scrolly
ENDFUNCTION
ENDTYPE
I can´t help much as TYPES and FUNCTIONS are a still bit over me :-[.
But here is pieces of the SOLARIS code to read a board(like a board game) from code:
// LOAD MAPA > TABULEIRO
RESTORE MAPA // load map
FOR d=0 TO 11 // generate map data
FOR c=0 TO 11
READ m[c][d] // generate m#
IF m[c][d]<1 // generate t# t$
t[c][d]=4 // paint arrays TABULEIRO/GFX
t$[c][d]="."
ENDIF
IF m[c][d]>0
t[c][d]=4
t$[c][d]="+"
ENDIF
NEXT
NEXT
STARTDATA MAPA:
DATA 1, 1, 1, 0, 0, 2, 2, 0, 0, 3, 3, 3
DATA 1, 1, 1, 0, 0, 2, 2, 0, 0, 3, 3, 3
DATA 1, 1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3
DATA 0, 0, 0, 4, 4, 4, 0, 5, 5, 0, 0, 0
DATA 0, 0, 0, 4, 4, 4, 0, 5, 5, 0, 0, 0
DATA 6, 6, 0, 0, 0, 0, 0, 5, 5, 0, 7, 7
DATA 6, 6, 0, 8, 8, 0, 0, 0, 0, 0, 7, 7
DATA 0, 0, 0, 8, 8, 0, 9, 9, 9, 0, 0, 0
DATA 0, 0, 0, 8, 8, 0, 9, 9, 9, 0, 0, 0
DATA 10,10,10, 0, 0, 0, 0, 0, 0, 11,11,11
DATA 10,10,10, 0, 0,12,12, 0, 0, 11,11,11
DATA 10,10,10, 0, 0,12,12, 0, 0, 11,11,11
ENDDATA
That will result in the following 2d arrays:
m[c][d] = exact numbers on the map (from 0 to 11)
t[c][d] = map overlay for players (4= empty , 0/1/2/3= player´s ship landed)
t$[c][d]= map overlay for test print (.=space , +=landable spot)
I hope that helps, I´m appending a picture of the board mockup and a TEST PRINT from ingame of the same.
For a jump and run game, the basics on reading a DATA is similar. But I suggest you read from a file, like Matchy stated, so it is easier to change things later.
Without going into any of your code, it really does seem like you are trying to do too much, without even a basic understanding of the language or syntax of GLBasic. It's all very well being adventurous and looking to create the next big thing, but without the proper groundwork to create strong foundations the walls and roof of your code-house will soon start to crack and fall. Leaving a nice mess that nobody can easily fix.
You are having problems even in the basic loading of sprites and images, without going into the horror that can be arrays, TYPES and OOP.
Step back a bit. Try to do something simpler. Get that understanding upto a level where you can eventually move to do something more challenging code-wise. I suggest just working on ONE aspect at a time, then build upon that.
IMPORTANT
Your posts are NOT bug reports, as these are not bugs within GLBasic, but rather your own poor programming/understanding of the principles of GLBasic. If you continue to have problems, please post these in the appropriate GLBasic forum (GLBasic - EN - http://www.glbasic.com/forum/index.php?board=2.0), NOT in BUG REPORTS.
We are here to help, but sometimes you just have to help yourself first. Baby steps lead to big things. Don't try to run before you can walk.
Hi, thank you for the code!
That should help me make a other map where i can test my programm.
@ Ian. I know that I m new and shouldnt really be doing this kind of big stuff but this project is for school, where we have to make a game (or sth. similar). We allways used Delphi7 before, but I hated it... then I asked a friend if he knew a easier language and he told me that GLBASIC is nice, because you dont have to finish of with a ";" everywhere and the commands are not that complicated... so I started of with a few written tutorials and now I found (then only) complete tutorial on youtube, where step by step we create a game.
I'm sorry to bother you in the wrong section... could you maybe move this Thread where it belongs ? I dont know if I can do that (think i d need to be admin)
Try do the PONG tutorial first then the SECOND GAME tutorial, those should give you a good understandment of how GLB works. :good:
You can´t simply copy parts of code and paste on other codes as it is and expect to work (it can work, but requires knowledge on doing so).
Hey, i went thorugh the video once again and he says he saves the map as byte file... what does that mean in GL Basic ?
Its just a general data file...