RequestFile() clone but without GUI?
BlitzMax Forums/BlitzMax Beginners Area/RequestFile() clone but without GUI?| 
 | ||
| Is there any sample code for loading files from a directory? I can code it to load one file but only if i know the filename. I have a factory where people can make maps for my game and save them with a custom filename. How would I go about coding a loader for maps so that I don't have to rely on RequestFile(). I've noticed that ReQuestFile doesn't show up during my game when in fullscreen. | 
| 
 | ||
|  Is there any sample code for loading files from a directory? LoadDir()? | 
| 
 | ||
| Ok. Now when I use loadDir(), how could I display the contents on a graphical screen? | 
| 
 | ||
| Tried this but I doesn't work. 
Type LoadFD
	
	Global Files:String[]
	Global Xloc:Int = 100
	Global YLoc:Int = 100
	
	Function LoadMapDir()
		LoadFD.Files = LoadDir("data/userlvl/")
	End Function
	
	Function DrawMapFilesInArray()
		For Local x:Int = 0 To Len(loadfd.files)
			DrawText "MapName : "LoadFD.Files, XLoc, Yloc
			Yloc:+25
		Next
	End Function
End Type
This one works Better. 
Type LoadFD
	
	Global Files:String[]
	Global Xloc:Int = 100
	Global YLoc:Int = 100
	
	Function LoadMapDir()
		LoadFD.Files = LoadDir("data/userlvl/")
	End Function
	
	Function DrawMapFilesInArray()
		For Local t$ = EachIn LoadFD.Files
			DrawText "MapName : "+t, XLoc, Yloc
			
			Yloc:+25
		Next
	End Function
End TypeIt still prints them all on the same line. :/ I'm working on it. :) | 
| 
 | ||
| Got this But I'm getting wierd results. 
Graphics 800,600,0
Global MapList:TList = CreateList()
Type LoadFD
	
	Global Files:String[]
	Global Xloc:Int = 100
	Global YLoc:Int = 100
	Field MapName:String
	Global count:Int
	Global t:String
	Function LoadMapDir()
		LoadFD.Files = LoadDir("data/userlvl/")
	End Function
	Function GetMapName()
		For t = EachIn files
			Local file:LoadFD = New LoadFD
			file.MapName = t
			count:+1
			maplist.AddLast(file)
		Next
	End Function
	
	Method DrawMapFiles()
		For Local xiter:Int = 0 To count - 1
			DrawText "MapName " +t,100,100
		Next
		
	End Method
End Type
LoadFD.LoadMapDir
LoadFD.GetMapName
While not KeyHit(KEY_ESCAPE)
	Cls
	
		For Local file:LoadFD = EachIn MapList
			file.DrawMapFiles
		Next
	
	
	Flip
	
WEnd
 | 
| 
 | ||
| This one works. :) 
Graphics 800,600,0
Global MapList:TList = CreateList()
Type LoadFD
	
	Global Files:String[]
	Field Xloc:Int = 100
	Field YLoc:Int = 100
	Field MapName:String
	Global count:Int
	Global t:String
	
	Global tempx:Int = 100
	Global tempy:Int = 100
	
	Function LoadMapDir()
		LoadFD.Files = LoadDir("data/userlvl/")
	End Function
	Function GetMapName()
		For t = EachIn files
			Local file:LoadFD = New LoadFD
			file.MapName = t
			file.Yloc = tempy
			maplist.AddLast(file)
			tempy:+25
		Next
	End Function
	
	Method DrawMapFiles()
		
			DrawText MapName,Xloc,Yloc
		
		
	End Method
End Type
LoadFD.LoadMapDir
LoadFD.GetMapName
While not KeyHit(KEY_ESCAPE)
	Cls
	
		For Local file:LoadFD = EachIn MapList
			file.DrawMapFiles
		Next
	
	
	Flip
	
WEnd
Version 2 displays 2 colums of text if the list reaches the bottom. Gonna try and add pages so that it can display 100's of files. :) 
Graphics 800,600,0
Global MapList:TList = CreateList()
Type LoadFD
	
	Global Files:String[]
	Field Xloc:Int = 100
	Field YLoc:Int = 100
	Field MapName:String
	Global count:Int
	Global t:String
	
	Global tempx:Int = 100
	Global tempy:Int = 100
	
	Function LoadMapDir()
		LoadFD.Files = LoadDir("data/temdir/")
	End Function
	Function GetMapName()
		For t = EachIn files
			Local file:LoadFD = New LoadFD
			file.MapName = t
			file.Yloc = tempy
			file.Xloc = tempx
			maplist.AddLast(file)
			tempy:+25
			count:+1
			
			If tempy > 500
				tempy = 100
				tempX:+300
			EndIf
			
		Next
	End Function
	
	Method DrawMapFiles()
		DrawText MapName,Xloc,Yloc
	End Method
End Type
LoadFD.LoadMapDir
LoadFD.GetMapName
While not KeyHit(KEY_ESCAPE)
	Cls
	
		For Local file:LoadFD = EachIn MapList
			file.DrawMapFiles
		Next
	
	
	Flip
	
WEnd
 | 
| 
 | ||
| I get a duplicate identifier 'file' found in this code. Why? 
Graphics 800,600,0
Global MapList:TList = CreateList()
Type MapFile
	
	Global Files:String[]
	Field Xloc:Int = 100
	Field YLoc:Int = 100
	Field MapName:String
	Global count:Int = 0
	Global t:String
	
	Global tempx:Int = 100
	Global tempy:Int = 100
	
	Function LoadMapDir()
		MapFile.Files = LoadDir("data/temdir/")
	End Function
	Function GetMapName()
		For t = EachIn files
			Local file:MapFile = New MapFile
			file.MapName = t
			file.Yloc = tempy
			file.Xloc = tempx
			maplist.AddLast(file)
			tempy:+25
			count:+1
			
			If tempy > 500
				tempy = 100
				tempX:+400
			EndIf
			
		Next
	End Function
	
	Method DrawMapFiles()
		DrawText count+MapName,Xloc,Yloc
	End Method
	
	Function ShiftText()
		If KeyDown(KEY_LEFT)
			For Local file:MapFile = EachIn MapList
				file.Xloc:- 1
			Next
		ElseIf KeyDown(KEY_RIGHT)
			For Local file:MapFile = EachIn MapList
				file.Xloc:+1
			Next
		End If
	End Function
End Type
MapFile.LoadMapDir
MapFile.GetMapName
While not KeyHit(KEY_ESCAPE)
	Cls
	
		For Local file:MapFile = EachIn MapList
			file.DrawMapFiles
		Next
		DrawText "TempX = " + MapFile.tempx,0,0
		MapFile.ShiftText
	Flip
	
WEnd
It points to this below. Function ShiftText() If KeyDown(KEY_LEFT) For Local file:MapFile = EachIn MapList file.Xloc:- 1 Next ElseIf KeyDown(KEY_RIGHT) For Local file:MapFile = EachIn MapList file.Xloc:+1 Next End If When I take out one of the conditions, example keydown(right) it works perfectly. | 
| 
 | ||
| Because you're not using Strict / SuperStrict, so your variables aren't lexically scoped. | 
| 
 | ||
| Ahh! I get what you mean but don't get the lexically scoped thingamy jig. Now, lexical is a greek word. so I'mm assuming you mean that the scope of blah is ...... Don't get it. :/ | 
| 
 | ||
| Lexical scope: Function ShiftText() 'Function scope starts here. If KeyDown(KEY_LEFT)'New If scope For Local file:MapFile = EachIn MapList 'New For Scope file.Xloc:- 1 Next 'End of For scope ElseIf KeyDown(KEY_RIGHT) 'End of if scope, New If scope For Local file:MapFile = EachIn MapList ' New For Scope file.Xloc:+1 Next 'End of For Scope End If 'End of If scope End Function'End of Function scopeNon-lexical scope: Function ShiftText() 'Function scope starts here. If KeyDown(KEY_LEFT) For Local file:MapFile = EachIn MapList file.Xloc:- 1 Next ElseIf KeyDown(KEY_RIGHT) For Local file:MapFile = EachIn MapList file.Xloc:+1 Next End If End Function'End of Function scopeThus since you're in non-strict mode your second for loop, is using a variable with the same name, and in the scope as the first one - which is an undefined operation, and thus an error. | 
| 
 | ||
| Can I clone you and have your clone as a pet? |