No, I meant that it can prevent these errors. Since you are switching so often, it might be possible that you forgot to switch it back to the folder where the current file is stored in.
When using my way, you don't even have to worry about where the exe is stored in.. But when using your code, the media files ALWAYS have to be in the darkbasic directory.
sync rate 0:sync on
`----------
`---Menu---
`----------
Menu:
set text size 24
load bitmap "Menu screen-RPG Game.bmp"
Blue=RGB(0,128,255)
White=RGB(255,255,255)
Set camera View 0,0,1,1
ink white,0
do
set cursor 10,100 : print screen fps()
text 280, 180, "New Game"
text 280,200, "Load Game"
text 280,220, "Controls"
text 280,240, "Exit"
`print menu items
If mousex() > 280 and mousex() < 350 and mousey() > 180 and mousey() < 190
ink blue,0:text 280,180,"New Game"
if mouseclick()=1
goto main
Endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 350 and mousey() > 200 and mousey() < 210
ink blue,0:text 280,200,"Load Game"
if mouseclick()=1
wait 1000
goto Load
Endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 340 and mousey() > 220 and mousey() < 230
ink blue,0:text 280,220,"Controls"
if mouseclick()=1
goto Controls
endif
else
ink white,0
endif
If mousex() > 280 and mousex() < 330 and mousey() > 240 and mousey() < 250
ink blue,0:text 280,240,"Exit"
if mouseclick()=1
End
endif
else
ink white,0
endif
sync
loop
Load:
cls
load bitmap "menu screen-loadgame.bmp"
`LOADING THE SAVED GAME
ink white,0
Do
Dim Stats#(20,3)
load array "RPG_Save.dat",Stats#(0)
set cursor 50,100:print "Name: Jozers"
set cursor 240,100:print "Level: "; stats#(11,1)
set cursor 330,100:print "Race: "; racename$
set cursor 450,100:print "Class: ";Classname$
if mousex() > 0 and mousex() < 480 and mousey() > 75 and mousey() < 125
ink blue,0
set cursor 50,100:print "Name: Jozers"
set cursor 240,100:print "Level: "; stats#(11,1)
set cursor 330,100:print "Race: "; racename$
set cursor 450,100:print "Class: ";Classname$
if mouseclick()=1
goto loadloop
endif
else
ink white,0
endif
sync
Loop
Controls:
load bitmap "menu screen-Controls.bmp"
do
if keystate(14)=1 then goto menu
sync
loop
`----------
`---MAIN---
`----------
Main:
`-----------
`---STATS---
`-----------
Dim Stats#(20,3)
stats#(1,1)=100
stats#(2,1)=15
stats#(3,1)=10
stats#(4,1)=13
stats#(5,1)=12
stats#(6,1)=13
stats#(7,1)=12
stats#(8,1)=12
stats#(9,1)=14
stats#(10,1)=12
stats#(11,1)=1
stats#(12,1)=0
stats#(13,1)=0
stats#(14,1)=0
stats#(15,1)=0
stats#(16,1)=100
stats#(17,1)=0
stats#(18,1)=0
stats#(19,1)=0
stats#(20,1)=0
loadloop:
#include "LoadMatrix.dba"
`------
`ARRAYS
`------
`declare the MatEdit variables
Dim BigMatrix(600,600,1)
Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)
Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)
Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)
Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)
Dim MOffsetX(25): Dim MOffsetY(25)
Dim MWire(20): Dim MGhost(20): Dim Lock(20)
Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)
Dim MatWidth#(20): Dim MatHeight#(20)
Dim TilesX(20): Dim TilesZ(20)
Dim MatHi#(20): Dim MatLo#(20)
`load the matrix
LoadMatrix("Game",1)
set camera view 0,0,640,480
`Scenery
`Fog
fog on
set ambient light 45
load object "Barbarian.3ds",1
scale object 1,500,500,500
yrotate object 1,270
fix object pivot 1
`scenery
`NPC
make object cube 120,5
`Saving Game Variables
skychange=20
Darken=199
do
rem Get current object position
stats#(13,1)=object position x(1)
stats#(14,1)=object position y(1)
stats#(15,1)=object position z(1)
oldxpos#=stats#(13,1)
oldypos#=stats#(14,1)
oldzpos#=stats#(15,1)
`Arrays for Magic
Dim Magic$(6)
Magic$(1)="Fire"
Magic$(2)="Bolt"
Magic$(3)="Ice"
Magic$(4)="Cure"
Magic$(5)="-"
Magic$(6)="-"
`Arrays for Items
Dim Items$(6)
Items$(1)="Potion"
Items$(2)=""
Items$(3)=""
Items$(4)=""
Items$(5)=""
Items$(6)=""
If keystate(23)=1
set cursor 150,150:Print "Inventory!!!!"
set cursor 150,160:print stats#(1,1);"/";stats#(16,1)
set cursor 150,170:print "strength: ";stats#(2,1)
set cursor 150,180:print "Intelligence:";stats#(3,1)
endif
Battle=Battle+1
if Battle>100
Battle=0
Set cursor 100,120:Print "Battle Battle Battle"
wait 1000
goto Battle
endif
set cursor 100,100:print Battle
`DAY-NIGHT CYCLE
DayNight=DayNight+1
if DayNight=SkyChange
if Darken>199 then Add=0
if Darken<40 then Add=1
If Add=1 then Darken=Darken+1
If Add=0 then Darken=Darken-1
fog distance darken
if Add=1
COLOR BACKDROP rgb(0,0,55+Darken)
color ambient light rgb(55+Darken,55+Darken,55+Darken)
else
COLOR BACKDROP rgb(55,55,55+Darken)
color ambient light rgb(55+Darken,55+Darken,55+Darken)
endif
DayNight=0
endif
`SAVE GAME IF 'K' KEY IS PRESSED
if keystate(37)=1
save Array "RPG_Save.dat",Stats#(0)
text 10,460, "Game Saved"
endif
set cursor 10,10 : print stats#(1,1);"/";stats#(16,1)
rem health bar
if upkey()=1 or keystate(17)=1 then stats#(13,1)=newxvalue(stats#(13,1),yAng#,0.3) : stats#(15,1)=newzvalue(stats#(15,1),yAng#,0.3)
if downkey()=1 or keystate(31)=1 then stats#(13,1)=newxvalue(stats#(13,1),yAng#,-0.3) : stats#(15,1)=newzvalue(stats#(15,1),yAng#,-0.3)
if leftkey()=1 or keystate(30)=1 then yAng#=yAng#-5
if rightkey()=1 or keystate(32)=1 then yAng#=yAng#+5
yAng#=wrapvalue(yAng#)
Yrotate object 1,yAng#
position object 1,stats#(13,1),stats#(14,1),stats#(15,1)
set cursor 80,10:print ChrName$
set cursor 80,25:print racename$
set cursor 80,40:print classname$
set cursor 400,10:print "";get date$()
set cursor 400,25: print "";get time$()
set cursor 150,10:print "Level: ";lvl
set cursor 250,10:Print "Experience: ";EXP
`update the camera
chase_cam(1)
position object 1,stats#(13,1),Get ground height(1,stats#(13,1),stats#(15,1))+0.5,stats#(15,1)
sync
loop
`----------
`--BATTLE--
`----------
Battle:
set text to normal
set text size 24
`Delete Current objects
delete matrix 1
`Make Matrix
success=LoadMatrix("BATTLE",1)
`Load Character(s)
position object 1,10,0,10
point object 1,10,0,30
`Make plain for menu
make object plain 10,3.25,0.5
position object 10,0,-0.95,2
lock object on 10
load bitmap "Menu_bar copy.bmp",2
get image 2,0,0,325,50
texture object 10,2
delete bitmap 2
box BTimer#+500,405,600,412
load bitmap "time bar.bmp",2
set current bitmap 2
box 500,405,600,412
delete bitmap 2
make object plain 11,2,0.2
position object 11,0.05,1.1,2
lock object on 11
`Load Opposition
load object "idle.x",100:append object "punch.x",100,50
scale object 100,10,10,10
position object 100,10,0,40
`Set Fog On
fog on
`Health
Gobhpmax=15
Gobhp=Gobhpmax
sec#=1
ink white,0
Etimer#=50
monnum=rnd(3)
set cursor 400,400:print monnum
Dim monstat(10)
load array "Monster Stats/Monster_stats_" + str$(monnum) + ".dat",monstat(10)
do
`---------------
`---Formulars---
`---------------
`Derived Stats
Att#=Stats#(2,1)+weapatkbonus
Defence#=stats#(8,1)+Armdefbonus
Magic#=Stats#(3,1)
`Physical Damage Attack Formula
PBaseDmg#=Att#+((att#+stats#(11,1))/32)*((att#*stats#(11,1))/32)
`Magical Damage Attack Formula
MBaseDmg#=6*(Magic#+stats#(11,1))
set cursor 75,85:print MBaseDmg#
set cursor 75,75:print PBaseDmg#
set cursor 30,30:print mousex()
set cursor 30,45:print mousey()
healthtemp#=stats#(1,1)
maxhealthtemp#=stats#(16,1)
hptest#=healthtemp#/maxhealthtemp#
hptest#=hptest#*100
set cursor 10,40:print screen fps()
text 40,405,"Jozers"
set cursor 10,10:print Monstat(1,1);"/";Monstat(5)
if menu =0
set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
if hptest#<30 and hptest#>20
ink rgb(250,230,10),0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
if hptest#<20
ink white,0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
ink rgb(200,0,0),0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
else
ink white,0:set cursor 205,410:print stats#(1,1);"/";stats#(16,1)
endif
endif
endif
ink white,0
`Battle Timer system
BTimer#=BTimer#+sec#
set cursor 100,100:print BTimer#
`----------
`---Menu---
`----------
if menu = 1
center text 200,356,"Attack"
center text 320,2,"Select!"
center text 200,380, "Defend"
center text 200,404,"Special"
center text 200,428,"Magic"
center text 200,452,"Item"
if mousex() > 190 and mousex() < 220 and mousey() > 356 and mousey() < 366
ink blue,0:center text 200,356,"Attack"
if mouseclick()=1
monstat(1)=monstat(1)-PBaseDmg#
sec#=1
menu=0
BTimer#=0
endif
else
ink white,0
Endif
if mousex() > 190 and mousex() < 220 and mousey() > 380 and mousey() < 390
ink blue,0:center text 200,380, "Defend"
if mouseclick()=1
menu=0
BTimer#=0
sec#=1
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 404 and mousey() < 414
ink blue,0:center text 200,404,"Special"
if mouseclick()=1
printitem=0
printmag=0
printspec=1
if object exist(13)=0
make object plain 13,0.3,0.4
position object 13,0,-0.4,1
lock object on 13
endif
menu = 0
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 428 and mousey() < 438
Ink blue,0:center text 200,428,"Magic"
if mouseclick()=1
printitem=0
printmag=1
printspec=0
if object exist(13)=0
make object plain 13,0.3,0.4
position object 13,0,-0.4,1
lock object on 13
endif
menu = 0
printmag=0
endif
else
ink white,0
endif
if mousex() > 190 and mousex() < 220 and mousey() > 452 and mousey() < 462
ink blue,0:center text 200,452,"Item"
if mouseclick()=1
printitem=1
printmag=0
printspec=0
if object exist(13)=0
make object plain 13,0.3,0.4
position object 13,0,-0.4,1
lock object on 13
endif
menu = 0
endif
if mousex() > 281 and mousex() < 320 and mousey() > 353 and mousey() < 363
Ink blue,0:center text 300,350, items$(1)
if mouseclick()=1
endif
else
ink white,0
endif
endif
else
ink white,0
printitem=0
endif
if printitem=1
ink white,0
center text 300,350, items$(1)
center text 300,365, items$(2)
center text 300,380, items$(3)
center text 300,395, items$(4)
center text 300,410, items$(5)
center text 300,425, items$(6)
endif
if printmag=1
ink white,0
center text 300,350, magic$(1)
center text 300,365, magic$(2)
center text 300,380, magic$(3)
center text 300,395, magic$(4)
center text 300,410, magic$(5)
center text 300,425, magic$(6)
endif
`Battle menu end
`--------------------
`-In Battle Enemy AI-
`--------------------
if menu = 0
Etimer#=Etimer#+1
If Etimer# > 100
Damage = (Monstat(2)-Stats#(8,1))
if damage < 1 then damage = 1
stats#(1,1) = stats#(1,1) - Damage
set cursor 300,200:print Damage
if object exist(100) then loop object 100,50,75
Etimer#=0
endif
endif
If BTimer#>100
sec#=0
menu=1
If object exist(12)=0
make object plain 12,0.3,0.4
position object 12,-0.3,-0.4,1
lock object on 12
endif
else
menu=0
center text 320,2,"Wait!"
if object exist(12)=1 then delete object 12
if object exist(13)=1 then delete object 13
endif
if monstat(1) < 0
stats#(12,1)=stats#(12,1)+Exp
if object exist(100)=1 then delete object 100
if matrix exist(1)=1 then delete matrix 1
chase_cam(1)
goto loadloop
endif
Fog distance darken
if object exist(100)
loop object 100,0,50:set object speed 100,20
endif
`update the camera
battle_Cam(1)
ink rgb(36,35,24),0
box BTimer#+500,405,600,412
ink white,0
sync
loop
`---------
`chase cam
`---------
function chase_cam(id)
if matrix exist(1)
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+180)
`grab the objects current position
stats#(13,1)=object position x(id)
stats#(14,1)=object position y(id)
stats#(15,1)=object position z(id)
`other variables
camDist=20
camHeight=10
`work out new position
xCamPos#=newxvalue(stats#(13,1),yAng#,camDist)
zCamPos#=newzvalue(stats#(15,1),yAng#,camDist)
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos# < stats#(14,1)+camHeight then yCamPos#=stats#(14,1)+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCampos#
point camera stats#(13,1),stats#(14,1)+camHeight,stats#(15,1)
endif
endfunction
`------------
`-Battle Cam-
`------------
function battle_cam(id)
CamAng#=255
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+CamAng#)
`grab the objects current position
stats#(13,1)=object position x(id)
stats#(14,1)=object position y(id)
stats#(15,1)=object position z(id)
`other variables
camDist=20
camHeight=5
`work out new position
xCamPos#=newxvalue(stats#(13,1),yAng#,camDist)
zCamPos#=newzvalue(stats#(15,1),yAng#,camDist)
`work out camera height
if matrix exist(1) then yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos# < stats#(14,1)+camHeight then yCamPos#=stats#(14,1)+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCampos#
point camera stats#(13,1),stats#(14,1)+camHeight,stats#(15,1)+10
endfunction
This is the full code.
You don't have to use it, but it's just how I would do it.
Immunity and Annihalation makes Immunihalation...