I'm back and have a slight problem.

Blitz3D Forums/Blitz3D Beginners Area/I'm back and have a slight problem.

Kenshin Yurihara(Posted 2009) [#1]
Okay its been awhile since I've posted here and probly should of been on more often to speak with people and learn new things.Anyway I have a slight problem with my Tile Mapping Engine.I've used a Input to input the name of the .map,but whenever it gets all the way down to CloseFile it says the file does not exist,but it does. So here let me give you the code to show you whats happening.

;Tile Map Editor

;Graphics
Graphics 800,600
NumTiles = 4

;Loading Tile Maps
Collision = LoadAnimImage("Collision.bmp",32,32,0,NumTiles)
Land = LoadAnimImage("Land.bmp",32,32,0,NumTiles)

;Setting up Loading
OpenNam = Input("Input the name of the .MAP to open:")
MapFile = OpenFile(OpenNam)


If MapFile <> 0 Then 
 MapX = ReadFile(MapFile)
 MapY = ReadFile(MapFile)
Else
 MapX = 800
 MapY = 600
EndIf 

Dim Map$(MapX,MapY)

If MapFile <> 0 Then
For y = 0 To MapY-1
For x = 0 To MapX-1
Map(x,y) = ReadFile(MapFile) 
   Next
Next
Else 
For  y = 0 To MapY-1
For x = 0 To MapX-1
Map(x,y) = 0
Next 
Next 
EndIf 


CloseFile MapFile 

-Oh and yes my code does look like the amcadam tutorials code because I was learning how to write this from his tutorials but I've added a little here and there and did not rip the entire code and no this is not the full code just till what you need to see.

Yes when it ask for the input I put Name.map but even then it does not work.Any suggestions?


Yasha(Posted 2009) [#2]
Well the most obvious thing is that ReadFile() doesn't work that way. ReadFile() opens a file to read data - it doesn't actually read anything from it, it's just an alternative to OpenFile for when you don't intend to write. To actually get data from the file, you need to use ReadByte/ReadShort/ReadInt/ReadFloat/ReadString/ReadBytes. I have no idea why the error might come up on CloseFile, but try changing this first, and see what happens.


Kenshin Yurihara(Posted 2009) [#3]
Thanks for the feed back but changing it did not seem to have any effect at all.I did however change ReadFile to ReadInt now that I realised that I used WriteInts to save it.However it still says the file does not exist.

-PS I'm starting to run out of ideas cause on the code I provided above I have 1 problem I have yet to solve and I tried rewriting the WHOLE thing with Types but those don't wanna work either so Idk.


PowerPC603(Posted 2009) [#4]
Change this:
OpenNam = Input("Input the name of the .MAP to open:")


into:
OpenNam$ = Input$("Input the name of the .MAP to open:")


You were inputting text into an integer variable.


Kenshin Yurihara(Posted 2009) [#5]
Wow PowerPC with the save.That seems to have fixed it I thought about doing that earlier but I didn't think it'd have a impact on it.
Thanks again!

One more problem and I should have this all sorted out I'm a keep messing wtih it myself and if I cannot find a solution I'll ask yall for some more insight.

Also I have a feeling my Blitz3D is Quite out of date
I was wondering where do we get updates for it from?
Ty


PowerPC603(Posted 2009) [#6]
If you have Blitz3D registered, you should have a tab at the top of this page: "Account".
From there you can download product updates.


Kenshin Yurihara(Posted 2009) [#7]
;Tile Map Editor

;Graphics
Graphics 800,600
NumTiles = 4


;Loading Tile Maps
Collision = LoadAnimImage("Collision.bmp",32,32,0,NumTiles)

;Setting up Loading
OpenNam$ = Input("Input the name of the .MAP to open:")
MapFile = OpenFile(OpenNam$)


If MapFile <> 0 Then 
 MapX = ReadInt(MapFile)
 MapY = ReadInt(MapFile)
Else
 MapX = 800
 MapY = 600
EndIf 

Dim Map$(MapX,MapY)

If MapFile <> 0 Then
For y = 0 To MapY-1
For x = 0 To MapX-1
Map(x,y) = ReadInt(MapFile)
   Next
Next
Else 
For  y = 0 To MapY-1
For x = 0 To MapX-1
Map(x,y) = 0
Next 
Next 
EndIf 


CloseFile MapFile 

SelectedTile = 0

SetBuffer BackBuffer()

While Not KeyHit(1)

Cls
For y = 0 To MapY
For x = 0 To MapX
Tiles  = Int(Map(x,y))-1 
If Tiles < -1 Then DrawImage Collision,x,y,Tiles
Flip  
Next
Next 


;Drawing Tiles
If SelectedTile >= 0 Then DrawImage Collision,MouseX(),MouseY(),SelectedTile 

If MouseHit(2)
SelectedTile = SelectedTile + 1
EndIf 
If MouseHit(3)
SelectedTile = SelectedTile - 1 
EndIf 
If SelectedTile > NumTiles Then SelectedTile = 0
If SelectedTile = -1 Then SelectedTile = NumTile 
Flip
;PROBLEM HERE
If MouseHit(1) Then
Map(MouseX(),MouseY())
Wend



;Clear Map When Right Shift is hit 
If KeyHit(54) Then 
For y = 0 To MapY
For x = 0 To MapX
Map(x,y) = 0
Next
Next
EndIf 

;Save when S is Pressed
If KeyHit(31) Then 
SaveNam = Input("Input a name to save it as:")
FileSave = WriteFile(SaveNam)

WriteInt FileSave,MapX
WriteInt FileSave,MapY

For y = 0 To MapY-1
For x = 0 To MapX-1
WriteInt FileSave,Map(x,y)
Next
Next
EndIf 

Thank you PowerPC the updates look great new 3D stuff -well not new to you
but it is to me.

Iight I've tired about 5 differnt things now but for some reason but under MouseHit(1)
It says expecting Variable Assignment.I know what this means but I read the other guys code and this worked fine except he had MouseX()-Scr_Something/TSize but I don't need those 2 additions because this is not for a sideScroller.
Any ideas of how to get around this without redoing the entire thing?


PowerPC603(Posted 2009) [#8]
If MouseHit(1) Then
Map(MouseX(),MouseY())


You must do something with that array-index, like:
If MouseHit(1) Then
Map(MouseX(),MouseY()) = 0


Also:
SaveNam = Input("Input a name to save it as:")

Make that:
SaveNam$ = Input$("Input a name to save it as:")


I also noticed that you're only using that array to hold integers.
Then you don't need to make it store strings.
; This is for strings
Dim Map$(MapX,MapY)

; This is for integers
Dim Map(MapX,MapY)



Kenshin Yurihara(Posted 2009) [#9]
Hey man thanks alot. I'm noticing 90% of my mistakes were in syntax.
If it wasn't for you I'd probly be stuck right here.


Kenshin Yurihara(Posted 2009) [#10]
Hey,Thanks again and also I think I'm gonna rewrite the entire thing except this time with Types because when I use the Array Index like you said no matter what I seem to do it says Array-Index Out Of Bounds..yes I know what that means but there seems no possible way to fix it so I'm just gonna rewrite the code to where I don't have to bug you guys.


_Skully(Posted 2009) [#11]
Types are definately the way to go for TileMaps, since you can store all information related to an individual tile in one place


Kenshin Yurihara(Posted 2009) [#12]
Okay thanks skully I think I got down how to do this cause I've used types quite alot since I started back using my Blitz3D a month ago.


andy_mc(Posted 2009) [#13]
Just thought I'd say hello, thanks for using my tutorials, it's good to see poeple are finding them useful.

I know I've been very quiet the last 6 six months or so, I think it's just me being lazy really. I'm sure you'll see some more updates soon.


Kenshin Yurihara(Posted 2009) [#14]
Its all good man I owe you alot since I just recently started Blitz programming again and needed a place to start.
So Thank you.


Kenshin Yurihara(Posted 2009) [#15]
;Tile Mapper 1.0
Graphics 600,400

;TileSets
TileSet = LoadAnimImage("Land.bmp",64,64,0,3)
;Setting Up Tile Type
Type Tile
Field X#,Y#
Field TNum#
Field TT#
End Type 

MapName$ = Input("Please Input the name of the map:")
MapOpen = OpenFile("" + MapName + ".map")

If MapFile <> 0 Then 
For Max = 0 To 14
T.Tile = New Tile 
T\X# = ReadInt(MapOpen)
T\Y# = ReadInt(MapOpen)
T\TNum# = ReadInt(MapOpen)
T\TT# = ReadInt(MapOpen)
Next 
Else 
T.Tile = New Tile 
T\X# = 0
T\Y# = 0
T\TNum# = 0
T\TT# = 1
EndIf 

SelTile = 0

While Not KeyHit(1) 
ClsColor 0,0,255
Cls 
DrawImage TileSet,MouseX(),MouseY(),SelTile
For Max = 0 To 14
T.Tile = New Tile
T\X# = T\X#
T\Y# = T\Y#
T\TNum# = SelTile
T\TT# = T\TT#
Next 

If MouseHit(2) Then
SelTile = SelTile + 1
EndIf 
If MouseHit(3) Then
SelTile = SelTile - 1
EndIf 
If SelTile > 3 Then SelTile = 0
If SelTile <= -1 Then SelTile = 0


If MouseHit(1) Then
T.Tile = New Tile 
T\X# = MouseX() / 64
T\Y# = MouseY() / 64
T\TNum# = SelTile
T\TT# = Input("Tile Type:")
EndIf 
Flip 
For Max = 0 To 14
DrawImage TileSet,T\X#,T\Y#,T\TNum#
Next 
Wend 


;Save when S is Hit 
If KeyHit(31) Then
SaveName$ = Input("Input the name to save the map as:")
FileWrite = WriteFile("" + SaveName$ + ".map")
For Max = 0 To 14
WriteInt FileWrite,T\X#
WriteInt FileWrite,T\Y#
WriteInt FileWrite,T\TNum#
WriteInt FileWrite,T\TT#
Next
EndIf 
EndGraphics 

Just thought I'd post it to let you guys see what I've got done so far.If you were to run this NO it won't work I'm still figuring out how to use Saving,Loading, and Drawing with Types but I'll get there eventually.


Kenshin Yurihara(Posted 2009) [#16]
okay so I've done a few changes and fixed the drawing problem now I just need to fix the saving and loading which shouldn't be to hard.
So I've yet to find out if I have to trash my whole code or not I don't think I will but I'm trying to figure out how to Save and Load Each Tile Type if anyone has any advice on this please do share.


Kenshin Yurihara(Posted 2009) [#17]
Well with some help from Skully I think I'm almost done with the Tile Mapper.


Kenshin Yurihara(Posted 2009) [#18]
Okay I just got 1 question:Do yall think it'd be best to use a differnt Type for Each TYPE of Tile?
Like Type CollideableTile
Type Land
Type Door(Like moves you to another map lol)