So my level editor is nearly complete (in terms of all of the functions I need for file saving/loading and object deleting/creating), and I've encountered a very strange bug.
In my level loading routine, I have the program read-in the file and load the proper 3D model with a variable named
ObjPath$. Normally, this would logically work, yet it's not working at all for me. I have to type in the full file path, which completely defeats the purpose of using a variable that can be changed to load in different models.
Here's the code block:
LoadLevel: `This loads a level file into the editor
Input " ", Name$
FileName$=LevelLoadPath$+Name$+".mtml"
`Open the file for readin
If File Exist(FileName$)
Open to Read 1, FileName$
Read String 1, ST$ : BlockCount=Val(ST$)
For Obj=1 to BlockCount
`Read in all the information
Read String 1, ObjPath$
Read String 1, ST$ : ObjPosX#=Val(ST$)
Read String 1, ST$ : ObjPosY#=Val(ST$)
Read String 1, ST$ : ObjPosZ#=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).Ghost=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).Visible=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).CollOn=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).CollType=Val(ST$)
Read String 1, ST$ : CollSizeX#=Val(ST$)
Read String 1, ST$ : CollSizeY#=Val(ST$)
Read String 1, ST$ : CollSizeZ#=Val(ST$)
Read String 1, ST$ : CollSizeX2#=Val(ST$)
Read String 1, ST$ : CollSizeY2#=Val(ST$)
Read String 1, ST$ : CollSizeZ2#=Val(ST$)
`Position the objects
Load Object ObjPath$,Obj
Scale Object Obj, 250,250,250
Position Object Obj, ObjPosX#, ObjPosY#, ObjPosZ#
If ObjAttributes(Obj).Ghost=1
Color Object Obj, RGB(0,0,255)
Else
EndIf
If ObjAttributes(Obj).Visible=1
Color Object Obj, RGB(255,0,0)
Else
EndIf
Next Obj
Close File 1
Else
ErrorMessage("Can't find the file!")
EndIf
Return
Whenever I try to load a level file, it stops, crashes and says "Error on line ###, file doesn't exist". (This line:
`Position the objects
Load Object ObjPath$,Obj
Scale Object Obj, 250,250,250
Position Object Obj, ObjPosX#, ObjPosY#, ObjPosZ#) It's talking about the ObjPath$ variable, which after going in and inspecting the level file itself I KNOW contains the proper information. The only way I can get this to work is if I type in the full file path in "" marks, which as I've said completely defeats the purpose of using the string variable. What's wrong with it? Is this a normal bug?
Does anybody know how I can fix/get around this?
Thanks to any and all who respond!
P.S. Full source code, if it helps...
REMSTART =============================================================
= The Adventures of Martin the Marble | Level Editor ==
= ==
= ==
= ==
================================================================REMEND
`Program start
Gosub StartUp:
`----------------------------
`Main Loop
`----------------------------
Do
Text 0,0,"FPS: "+Str$(Screen Fps())
Text 0,12,"Object Position: X:"+Str$(NewPosX#)+" Y:"+Str$(NewPosY#)+" Z:"+Str$(NewPosZ#)
`Save the Level (test)
If ShiftKey()=1 Then GoSub SaveLevel:
`Load a previously saved level (test)
If KeyState(3)=1 Then GoSub LoadLevel:
`Control the camera
Control Camera Using ArrowKeys 1, 1,5
`Create a cube
If SpaceKey()=1 Then CreateObject()
`Select and control the level's objects
ClickObj=Pick Object(MouseX(), MouseY(),1,8000)
If MouseClick()=1 And ClickObj <> 0 Then SelObj=ClickObj : Sleep 50
If SelObj <> 0
`Get the object's position and angle of rotation
ObjPosX#=Object Position X(SelObj)
ObjPosY#=Object Position Y(SelObj)
ObjPosZ#=Object Position Z(SelObj)
ObjAngX#=Object Angle X(SelObj)
ObjAngY#=Object Angle Y(SelObj)
ObjAngZ#=Object Angle Z(SelObj)
EndIf
If Operation=1
If Object Exist(8000) Then Delete Object 8000
If SelObj <> 0
If SelObj >0 And SelObj <49
`Highlight the currently selected object
Make Object Box 8000,5.5,5.5,5.5
Color Object 8000,RGB(255,255,255)
Set Object 8000,0,1,0
ObjAngY#=Object Angle Y(8000)
EndIf
`Store the object's new position
NewPosX#=Object Position X(SelObj)
NewPosY#=Object Position Y(SelObj)
NewPosZ#=Object Position Z(SelObj)
`Now move the object
If KeyState(77)=1
While KeyState(77)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosX#=NewPosX#+5
EndIf
If KeyState(75)=1
While KeyState(75)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosX#=NewPosX#-5
EndIf
If KeyState(78)=1
While KeyState(78)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosY#=NewPosY#+5
EndIf
If KeyState(74)=1
While KeyState(74)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosY#=NewPosY#-5
EndIf
If KeyState(72)=1
While KeyState(72)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosZ#=NewPosZ#+5
EndIf
If KeyState(80)=1
While KeyState(80)=1
EndWhile
Move Object SelObj,0.5 : Move Object 8000,0.5 : NewPosZ#=NewPosZ#-5
EndIf
If KeyState(52)=1
While KeyState(52)=1
EndWhile
YRotate Object SelObj,90 : YRotate Object 8000,90 : ObjAngY#=ObjAngY#+90
EndIf
If KeyState(51)=1
While KeyState(51)=1
EndWhile
YRotate Object SelObj,180 : YRotate Object 8000,180 : ObjAngY#=ObjAngY#-90
EndIf
`Position the object
Position Object SelObj,NewPosX#,NewPosY#,NewPosZ#
Position Object 8000,NewPosX#,NewPosY#,NewPosZ#
`If the mouse is clicked de-select the object
If MouseClick()=1 Then Delete Object 8000 : SelObj=0
EndIf
`Delete Currently Selected Object
If KeyState(211)=1 And SelObj > 0 And SelObj < 49
Delete Object SelObj : Delete Object 8000
`Reset the ghosting variable
If ObjAttributes(SelObj).Ghost=1
ObjAttributes(SelObj).Ghost=0
EndIf
`Reset the object visible variable
If ObjAttributes(SelObj).Visible=1
ObjAttributes(SelObj).Visible=0
EndIf
SelObj=0
BlockCount=BlockCount-1
If BlockCount=<1 Then BlockCount=1
EndIf
EndIf
Sync
Loop
`+++++++++++++++++++++++++++++++++
`S U B R O U T I N E S
`+++++++++++++++++++++++++++++++++
StartUp: `This runs on program launch
FileName$="Editor Data\Setup.txt"
If File Exist(FileName$)
Open to Read 1, FileName$
Read String 1, ST$ : Width=Val(ST$)
Read String 1, ST$ : Height=Val(ST$)
Read String 1, ST$ : Depth=Val(ST$)
Read String 1, ST$ : WindowMode=Val(ST$)
Read String 1, ST$ : WinWidth=Val(ST$)
Read String 1, ST$ : WinHeight=Val(ST$)
Read String 1, ST$ : SyncValue=Val(ST$)
Read String 1, LevelSavePath$
Read String 1, LevelLoadPath$
Read String 1, SaveProjectPath$
Read String 1, LoadProjectPath$
Read String 1, LoadModelPath$
Read String 1, LoadTexturePath$
Read String 1, LoadMusicPath$
`Apply data to program
Set Display Mode Width, Height, Depth
Sync On : Sync Rate SyncValue
If WindowMode=1
Set Window On
Set Window Size WinWidth, WinHeight
Set Window Title "The Adventures of Martin the Marble : The Level Editor [v0.1]"
Else
Set Window Off
EndIf
Close File 1
`Set up variables
Global BlockCount=1
Global MaxBlocks=49
Global CoinCount=100
Global MaxCoins=199
Operation=1
Type ObjAttributes
`Object attributes for the platforms
Ghost
Visible
CollOn
CollType
`Elevator and enemy attributes
StartPoint#
EndPoint#
EndType
Dim ObjAttributes(300) as ObjAttributes
`Create the camera, color the backdrop and create some light
Color Ambient Light RGB(255,255,255)
Set Ambient Light 55
Make Camera 1 : Position Camera 1,0,5,-10
Color Backdrop 1, RGB(0,0,0)
`Make the grid
grid=1 : Load Image "Resources\Textures\gridImg.jpg", grid
Make Object Plain 10001,1450,1450
Position Object 10001,0,-2.5,0
XRotate Object 10001,90
Texture Object 10001,grid
Scale Object Texture 10001,300,300
Set Object 10001,1,0,1
EndIf
Return
`---------------------------------
LoadLevel: `This loads a level file into the editor
Input " ", Name$
FileName$=LevelLoadPath$+Name$+".mtml"
`Open the file for readin
If File Exist(FileName$)
Open to Read 1, FileName$
Read String 1, ST$ : BlockCount=Val(ST$)
For Obj=1 to BlockCount
`Read in all the information
Read String 1, ObjPath$
Read String 1, ST$ : ObjPosX#=Val(ST$)
Read String 1, ST$ : ObjPosY#=Val(ST$)
Read String 1, ST$ : ObjPosZ#=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).Ghost=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).Visible=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).CollOn=Val(ST$)
Read String 1, ST$ : ObjAttributes(Obj).CollType=Val(ST$)
Read String 1, ST$ : CollSizeX#=Val(ST$)
Read String 1, ST$ : CollSizeY#=Val(ST$)
Read String 1, ST$ : CollSizeZ#=Val(ST$)
Read String 1, ST$ : CollSizeX2#=Val(ST$)
Read String 1, ST$ : CollSizeY2#=Val(ST$)
Read String 1, ST$ : CollSizeZ2#=Val(ST$)
`Position the objects
Load Object ObjPath$,Obj
Scale Object Obj, 250,250,250
Position Object Obj, ObjPosX#, ObjPosY#, ObjPosZ#
If ObjAttributes(Obj).Ghost=1
Color Object Obj, RGB(0,0,255)
Else
EndIf
If ObjAttributes(Obj).Visible=1
Color Object Obj, RGB(255,0,0)
Else
EndIf
Next Obj
Close File 1
Else
ErrorMessage("Can't find the file!")
EndIf
Return
`---------------------------------
SaveLevel: `This saves a final level file
Input "Enter a name for your level: ",Name$
FileName$=LevelSavePath$+Name$+".mtml"
`If that file already eixsts, create a copy
FileNum=1
If File Exist(FileName$)
FileNum=FileNum+1
FileName$=LevelSavePath$+Name$+Str$(FileNum)+".mtml"
If FileNum>50 Then ErrorMessage("Too many copies of that file exist. Please enter a new name. Press Enter to continue.")
EndIf
`Save the information
Open to Write 1, FileName$
`Save the blocks' positions, locations and game-specific attributes
Write String 1, Str$(BlockCount)
For Obj=1 To 49
If Object Exist(Obj)
ObjPath$ = LoadModelPath$+"OneBlockGrass.x"
ObjPosX# = Object Position X(Obj)
ObjPosY# = Object Position Y(Obj)
ObjPosZ# = Object Position Z(Obj)
`If the object is transparent
If ObjAttributes(Obj).Ghost=1
ObjGhost=1
Else
ObjGhost=0
EndIf
`If the object is a hidden platform (to be revealed by a switch later in-game)
If ObjAttributes(Obj).Visible=1
ObjVisible=1
Else
ObjVisible=0
EndIf
`Collision detection information
If ObjAttributes(Obj).CollOn=1 And ObjAttributes(Obj).CollType=1
CollOn=1 : CollType=1
CollSizeX#=2.5 : CollSizeY#=2.5 : CollSizeZ#=2.5
CollSizeX2#=-2.5 : CollSizeY2#=-2.5 : CollSizeZ2#=-2.5
Else
CollOn=0
CollSizeX#=-2.5 : CollSizeY#=-2.5 : CollSizeZ#=-2.5
CollSizeX2#=2.5 : CollSizeY2#=2.5 : CollSizeZ2#=2.5
EndIf
`Write the information to the file
Write String 1,ObjPath$
Write String 1,Str$(ObjPosX#)
Write String 1,Str$(ObjPosY#)
Write String 1,Str$(ObjPosZ#)
Write String 1,Str$(ObjGhost)
Write String 1,Str$(ObjVisible)
Write String 1,Str$(CollOn)
Write String 1,Str$(CollType)
Write String 1,Str$(CollSizeX#)
Write String 1,Str$(CollSizeY#)
Write String 1,Str$(CollSizeZ#)
Write String 1,Str$(CollSizeX2#)
Write String 1,Str$(CollSizeY2#)
Write String 1,Str$(CollSizeZ2#)
EndIf
Next Obj
`Save the coins' positions, locations and game-specific attributes
`Close the file and return to the main program
Close File 1
Return
`==================================
`Program Functions
`==================================
`Create Object Function
Function CreateObject()
`Make sure the object number is available
BlockCount=1
While Object Exist(BlockCount)
BlockCount=BlockCount+1
EndWhile
`Create a dialog to offer options to the user
While ReturnKey()=0
Set Cursor 0,12 : Input " ", Ghost$
Set Cursor 0,24 : Input " ", Hide$
EndWhile
`Create the cube
Load Object "Resources\Models\OneBlockGrass.x", BlockCount
Scale Object BlockCount, 250,250,250
Position Object BlockCount, 0,0,0
If Ghost$="1"
Color Object BlockCount, RGB(0,0,255)
ObjAttributes(BlockCount).Ghost=1
Else
ObjAttributes(BlockCount).Ghost=0
EndIf
If Hide$="1"
Color Object BlockCount, RGB(255,0,0)
ObjAttributes(BlockCount).Visible=1
Else
ObjAttributes(BlockCount).Visible=0
EndIf
BlockCount=BlockCount+1
If BlockCount=>MaxBlocks
ErrorMessage("You can't create anymore blocks. Press Enter to continue.")
BlockCount=BlockCount-1
EndIf
EndFunction
`Error Messages function
Function ErrorMessage(Msg$)
Ink RGB(255,255,255),RGB(255,255,255)
While ReturnKey()=0
Center Text 512,425,Msg$+" "
EndWhile
EndFunction
