Z
zendraw
Guest
How do you fill a list with the names of files? like you have multiple saves, then you do a loop and store theyr names in an array. i done this before but cant remember how was it done.
find first file
while found file is not empty string
do something with filename
find next file
find file close
save[0]=file_find_first(string(working_directory)+string("*.stk"), 0);
if (file_exists(save[0]))
{
var i=0;
while (file_exists(save[i]))
{
save=file_find_next();
i++;
}
}
file_find_close();
save[0]=file_find_first(string(working_directory)+string("*.stk"), 0);
if (file_exists(save[0]))
{
var i=0;
while (file_exists(save[i]))
{
save[i]=file_find_next();
i++;
}
}
file_find_close();
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object oarmies:
Push :: Execution Error - Variable Index [0,1] out of range [1,1] - -1.save(100022,1)
at gml_Script_scrstackgetlist (line 9) - while (file_exists(save[i]))
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scrstackgetlist (line 9)
called from - gml_Object_oarmies_Create_0 (line 7) - scrstackgetlist();
called from - gml_Object_ocontroll_Other_10 (line 58) - else {instance_create_depth(0, 0, 0, oarmies)};
called from - gml_Object_ocontroll_Step_0 (line 41) - event_user(0);
You're getting an error because you're testing ifok,
this
gives me this errorCode:save[0]=file_find_first(string(working_directory)+string("*.stk"), 0); if (file_exists(save[0])) { var i=0; while (file_exists(save[i])) { save[i]=file_find_next(); i++; } } file_find_close();
GML:___________________________________________ ############################################################################################ FATAL ERROR in action number 1 of Create Event for object oarmies: Push :: Execution Error - Variable Index [0,1] out of range [1,1] - -1.save(100022,1) at gml_Script_scrstackgetlist (line 9) - while (file_exists(save[i])) ############################################################################################ -------------------------------------------------------------------------------------------- stack frame is gml_Script_scrstackgetlist (line 9) called from - gml_Object_oarmies_Create_0 (line 7) - scrstackgetlist(); called from - gml_Object_ocontroll_Other_10 (line 58) - else {instance_create_depth(0, 0, 0, oarmies)}; called from - gml_Object_ocontroll_Step_0 (line 41) - event_user(0);
save[i]
exist before assigning it inside the loop.index = 0;
save[0] = "";
var _file = file_find_first(working_directory + "*.stk", 0);
while ( _file != "" ) // file_find_first() / file_find_next() return "" (empty string) if no files found.
{
save[index++] = _file;
_file = file_find_next();
}
show_debug_message("Found " + string(index) + " files.");
file_find_close();