HTML5 file_copy causes crash

THE_T_V1RUS

Member
IDE: v2.2.3.436
Runtime: v2.2.3.344
Target: HTML5

I create a very small ini file in my game using ini functions. It contains a single section with one key in that section. I then want to simply copy that ini file so I have two with the exact same data but different names. I'm using the file_copy() function to do this.
Code:
show_debug_message("Key Press Enter event triggered");
if !file_exists("data2.ini")
    {
    show_debug_message("start copy")
    file_copy("data1.ini","data2.ini");
    show_debug_message("copy finished");
    }
When I run this code, the console shows the following:
Code:
start copy
HEAD http://127.0.0.1:51264/html5game/data2.ini 404 (Not Found)
At this point, the game and page become completely unresponsive. Trying to close the tab doesn't work. Trying to close the browser doesn't work. I have to close the browser with the task manager.

Is there a bug with the file_copy() function in HTML5? The description of the function seems like it should work in HTML5, and I don't see anything I'm doing wrong. It works in other targets.
 
Last edited:
The file_copy() function works by copying the first file to the second file.

e.g. file_copy(existing_file, new_file_to_be_created)

Your code here:

Code:
if !file_exists("data1.ini")
is checking if the file "data1.ini" DOESNT exist, then try to copy the file.

So the code after the if() statement is running, when "data1.ini" does not exist, giving you the error.

So depending on what you are trying to achieve, you either need to remove the exclamation mark from your if statement, or reverse the order of your file_copy() parameters.
 

FrostyCat

Redemption Seeker
The concept of local files doesn't exist in the HTML5 export, every "file" is based on an existing template given by an Included File of the same name. You have to include a data2.ini file in your project for this to work, even if it's blank.
 

THE_T_V1RUS

Member
The file_copy() function works by copying the first file to the second file.

e.g. file_copy(existing_file, new_file_to_be_created)

Your code here:

Code:
if !file_exists("data1.ini")
is checking if the file "data1.ini" DOESNT exist, then try to copy the file.

So the code after the if() statement is running, when "data1.ini" does not exist, giving you the error.

So depending on what you are trying to achieve, you either need to remove the exclamation mark from your if statement, or reverse the order of your file_copy() parameters.
That was a typo when making the post. That should have been if !file_exists("data2.ini"). I have corrected it above. Thanks for pointing that out!


The concept of local files doesn't exist in the HTML5 export, every "file" is based on an existing template given by an Included File of the same name. You have to include a data2.ini file in your project for this to work, even if it's blank.
Okay so "data2.ini" must exist before "data1.ini" can be copied to it? What I tried is the following

Code:
        var c1_name = "data"+string(copy1);
        var c2_name = "data"+string(copy2);
     
        //do not copy files if files selected are the same
        if c1_name != c2_name
            {
            //copy files
            if !file_exists(c2_name+".ini")
                {
                //if the file you are copying to does not exists, make the file
                show_debug_message("create ini file");
                ini_open(c2_name+".ini")
                ini_write_string("copy","copy","copy");
                ini_close();
                show_debug_message("ini file created");
                }
            if file_exists(c1_name+".ini")
                {
                show_debug_message("start copy ini file");
                file_copy(c1_name+".ini",c2_name+".ini");
                show_debug_message("copy ini file completed");
                }
          }
Creating an ini file works so I thought I could just make the data2.ini before trying to copy data to it. However, I get the exact same failed results with this. This just feels like a bug in the file_copy function to me. Do I really have to have all my ini files in the 'Included Files' folder in the IDE for any kind of copying to work?
 

Attachments

FrostyCat

Redemption Seeker
Do I really have to have all my ini files in the 'Included Files' folder in the IDE for any kind of copying to work?
I mean exactly that. There is no such thing as actual "local files" in the HTML5 export.

Besides, if you are working with the HTML5 export and you save with the assumption of a full-fledged file system, your save system is done wrong.
 
Top