Getting a filename to use in error loading
BlitzMax Forums/BlitzMax Beginners Area/Getting a filename to use in error loading
| ||
I have the following code:'--------------------------------------------------------------------------------------------------- ' Fuction CreateObject ' Creates the Game Object '--------------------------------------------------------------------------------------------------- Function CreateObject(Obj:TGameObject, Image:TImage, New_X_Start_Position:Int,New_Y_Start_Position:Int, New_Scale:Float=1.0) Obj.X_Start_Position = New_X_Start_Position Obj.y_start_position = New_Y_Start_Position Obj.X_Scale = New_Scale Obj.Y_Scale = New_Scale Obj.Image = Image If Obj.Image=Null Print "Not able to load image file. Program aborting" End EndIf Obj.Reset() ListAddLast GameObjects, Obj End Function I would like to change it so instead of the static message "Not able to load image file. Program aborting" printing out when the image doesn't excist, i would like it to print "Not able to load image file filename_here. Program aborting". I have tried the following code to no avail '--------------------------------------------------------------------------------------------------- ' Fuction CreateObject ' Creates the Game Object '--------------------------------------------------------------------------------------------------- Function CreateObject(Obj:TGameObject, Image:TImage, New_X_Start_Position:Int,New_Y_Start_Position:Int, New_Scale:Float=1.0) Obj.X_Start_Position = New_X_Start_Position Obj.y_start_position = New_Y_Start_Position Obj.X_Scale = New_Scale Obj.Y_Scale = New_Scale Obj.Image = Image If Obj.Image=Null Print "Not able to load image file " + String(Obj.Image) + ".Program aborting" End EndIf Obj.Reset() ListAddLast GameObjects, Obj End Function Any ideas? |
| ||
Well, why not post the error were you load the image? Cos then you would have its name. |
| ||
because you need to use object.create(loadimage("filename"), x_start_position, y_start_position, scale) as you can see i call loadimage outside of the create function as a parameter. I don't see how i can do that. GameEngine uses TGameEngine.Create(loadimage("background.png")) to load the background image. |
| ||
In fact how silly do you think it is to check that an image is NULL THEN try to use it "String(Obj.Image)" object.create(loadimage("filename"), x_start_position, y_start_position, scale) see that "FileName", you could print that |
| ||
Well, then i truely am stumped. Since Image will be null, there is nothing to gather from what i see. filename is a string and not a variable, so i can't use that. |
| ||
I must be missing something. Don't pass the function a loadimage command. Instead load the image, test the result, display any messages and then call CreateObject with the resulting TImage. |
| ||
@ tony you can see He calls loadimage outside of the create function as a parameter. He doesnt see how he can check the file then I mean he couldnt possibly just pass the image name could he, and then load it in. And because filename is a string and not a variable, he cannot print it (Ive given up) |
| ||
So my guess is it can't be done. |
| ||
Space, yes thats right it is imposible to get the name of a file, from an image that is NULL Pass the filename to create and load the file inside the function, then check to see is its null, whilst you still have the file name (And yes I am shouting) |
| ||
Space Xscape, does this not do what you want?Graphics 640 , 480 filename:String="max.png" Local image:TImage = LoadImage(filename) If image Notify "File " + filename + " found" Else Notify "File " + filename + " NOT found" |
| ||
nevermind i fixed it. |
| ||
Because your TGameEngine.Create is asking for a TImage and you're passing it a string. Changes: Function Create:TGameEngine(filename:string) Local GameEngine:TGameEngine = New TGameEngine CreateObject(GameEngine, filename, 0, 0, 1.0) Return GameEngine End Function |
| ||
the Ide highlights a line, just post that line |