SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: wadmixfm on June 07, 2021, 23:13:40

Title: a little help please
Post by: wadmixfm on June 07, 2021, 23:13:40
i am trying to save a file with the inbuilt file requester, is it possible ??

loading (or requesting) works great

i cant seem to make it work

lee
Title: Re: a little help please
Post by: Midimaster on June 07, 2021, 23:52:21
The file request is not the part where you save a file. FileRequest is only responsible for defining the file name and the path.

So first question is: What do you want to save? Binary datas? Plain text? A Stream? Often we want to save the content of a variable or the RAM content of a bank. But there are different ways, depending on what you want to save.

The FileRequest only shows a windows to the user, where he can select a folder and define a file name. When the user clicks "SAVE" it looks like the saving is done, but in reality this is the moment where the saving starts.

 Example for saving the content of a string:
Code: BlitzMax
  1. local Text$="hello world"
  2. SaveText Text, "test.txt"
  3.  
As you can see: There is no need for using the FileRequest for saving anything.

The FileRequest would only define the name of the file and is fininshes before the saving start. Here is the same example with FileRequest:

Code: BlitzMax
  1. Local text$="HelloWorld"
  2.  
  3. Local FileName$ = RequestFile("select a name", "Textfiles:txt", True)
  4. Print "User wants this Filename: " + Filename
  5. If FileName<>"" Then
  6.         SaveText Text, FileName
  7. Else
  8.         Print "file note saved"
  9. EndIf
  10.  
Now the user is forced to select a existing file or defining a new name with the extension ".txt".
there are several possible scenarios:

 - If the user clicks at "CANCEL" the variable FilenName$ will be empty. This means that not should not save the file.

 - If the user defines a name or selects a existing file, the FileName$ will contain a whole path and not only the name.

 - If the user only enters the name without using an extension, the FileName$ will automatically get the extension ".TXT"

 - If the user enters a filename like "image.png" also the filename will have the extension ".PNG". So you have to check it this!

Code: BlitzMax
  1. Local text$="HelloWorld"
  2.  
  3. Local FileName$ = RequestFile("select a name", "Textfiles:txt", True)
  4. Print "User wants this Filename: " + Filename
  5. If FileName<>"" And ExtractExt(FileName)="txt" Then
  6.         SaveText Text, FileName
  7. Else
  8.         Print "file note saved"
  9. EndIf
  10.  
Title: Re: a little help please
Post by: wadmixfm on June 08, 2021, 00:20:47
Top man Midimaster :)

also whilst your here i cant get your miniaudio wrapper to compile on ng 64bit

i downloaded the mod folder did everything i was supposed to and it fails

can you enlighten me :)

Lee
Title: Re: a little help please
Post by: wadmixfm on June 08, 2021, 00:27:26
on the file requester issue

i want the requester to default to a folder say

/Applications/bla/bla/

where do i type that everything i try it defaults to the last folder i opened

lee
Title: Re: a little help please
Post by: Midimaster on June 08, 2021, 00:46:09
this needs to use the 4th parameter of the function:

Code: BlitzMax
  1. Local UserDir$=""
  2. Local FileName$ = RequestFile("select a name", "Textfiles:txt", True, UserDir )
  3. Print "User wants this Filename: " + Filename
  4.  
  5. 'now set user dir for the next call:
  6. UserDir= ExtractDir(FileName) + "/"
  7.  
  8. Print "new user dir =" + UserDir
  9. ....
  10. ' later:
  11. FileName$ = RequestFile("SECOND TIME CALL !!!!", "Textfiles:txt", True, UserDir )
  12.  

this is also often used together with Brucey new functions of the "Volumes"-Mod. Now part of "Others":
Code: [Select]
GetUserHomeDir()       Returns the user home directory.
GetUserDesktopDir()    Returns the user Desktop directory.
GetUserAppDir()        Returns the user directory for application data.
GetUserDocumentsDir()  Returns the user Documents directory.
GetCustomDir()         Returns the custom directory path.


Code: BlitzMax
  1. Local UserDir$=GetUserAppDir()
  2. Local FileName$ = RequestFile("select a name", "Textfiles:txt", True, UserDir )
Title: Re: a little help please
Post by: wadmixfm on June 08, 2021, 09:23:33
Thank you so much for the help

Lee
SimplePortal 2.3.6 © 2008-2014, SimplePortal