Reading/writing files

Blitz3D Forums/Blitz3D Beginners Area/Reading/writing files

Aussie(Posted 2012) [#1]
Hey there everyone I am trying to create a simple world editor to use for my next project.
I have created a small program that creates cubes at random positions, scale, rotations & colour then exports the info out to a .txt file. I have had no problems with this part; it’s trying to load the scene back up again that is doing my head in.
I have tried using a loading system that I have used in the past but it just does not want to play the game this time. Been going over & over the code for the past 4 hours, not having much luck.
My head hurts.
What would be the best way to read a .txt file for use in loading scene data?
Cheers :)
Here is what I have.


Creates the cubes & exports to .txt file



Supposed to load the scene



Midimaster(Posted 2012) [#2]
at first you can shorten the code by creating a function to divide the text line automatic:

....
      	If Left$(param$, 2) = "x="
         	W\L_X# = ExtractValue( param)
     	 EndIf

Function ExtractValue$(TextLine$)
   Local Value$, There%
   There=Instr(TextLine,"=")
   Value=Mid( TextLine, There+1, -1)
   Return Value$
End Function


a shorter code is always better, ecause it reduced the risk of bugs.

If you search for a bug you should use the DEBUGGER and DEBUGLOG to check, whether everything happened as you exepected. At first I would add some DEBUGLOG lines here:

		If Left$(param$, 6) = "finish"
DEBUGLOG "Finished Values:"
DEBUGLOG "W\L_X:" + W\L_X
....
			PositionEntity W\Mesh, W\L_X, L_Y, L_Z
....
		End If



and exactly here i see this line:

PositionEntity W\Mesh, W\L_X, L_Y, L_Z


shouldn't it be:
PositionEntity W\Mesh, W\L_X, W\L_Y, W\L_Z
???


Aussie(Posted 2012) [#3]
Thanks Midimaster.

I haven't used any DEBUGLOG commands before i guess i should learn to use them.

I have changed the code so i can see all the values are being passed from the .txt file & changed the POSITIONENTITY line yet still none of the cubes are being created.


Midimaster(Posted 2012) [#4]
so your next step will be to check, whether the cubes properties have been set really correct after the creation!

DEBUGLOG "is it created? Handle=" + w\Mesh
DEBUGLOG "X=" + EntityX(W\mesh)
.....



And I would add a second cube created in the code to have a reference, that camera and rendering are really working and camera is not to far away from the cubes!

Last edited 2012


Aussie(Posted 2012) [#5]
The log shows:
is ist created? Handle=11949296
X=0.0

I am tipping that its not being created & i'm not to sure what the number following Handel is.

I will have to have a look at this again tomorrow i really need to go to bed now.

Thanks heaps for the help, no doubt i will be asking a few more questions.


Midimaster(Posted 2012) [#6]
if there is any "handle" it is created! And the x=0 shows, that it is positioned in the center of the scene.

You have to know, whether this position could be correct. I think this exact zero points to a bug, because you created the values by random and "0.0" is quite implausible.

Of course you have to add also more DEBUGLOG lines for the other parameters until you find the bug.

Can you post the TXT file?

At me it is 11:00 in the morning...


Aussie(Posted 2012) [#7]
I found out why the x position was returning 0, i was trying to find it's position before i placed it.

Added some DEBUGLOG lines to return pitch,yaw & roll. All entity positions & rotations are there showing in the DEBUGLOG that they are correct but nothing appears on the screen.

Here is the .TXT file

It was 9:00pm last night here when i posted my last post, had to be up at 4:00am for work.


Aussie(Posted 2012) [#8]
Fixed it.

Going over the code with a fresh set of eyes & saw this straight away.

[bbcode]
EntityColor WMesh, R, G, B
[/bbcode]

Should have been
[bbcode]
EntityColor WMesh,WC_ R, WC_G,WC_ B
[/bbcode]

Thanks for the help Midimaster. :)

Last edited 2012