# Save command in void?

**URL:** <https://discourse.processing.org/t/save-command-in-void/16863>\
**Category:** Coding Questions\
**Created:** [January 4, 2020, 5:23pm UTC](https://discourse.processing.org/t/save-command-in-void/16863 "2020-01-04T17:23:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Optyfen\_met\_Eenden](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@Optyfen\_met\_Eenden](https://discourse.processing.org/u/Optyfen_met_Eenden)\
**Post date:** [January 4, 2020, 5:23pm UTC](https://discourse.processing.org/t/save-command-in-void/16863/1 "2020-01-04T17:23:29Z")

</div>

Hi! I’m new to Processing and also to this forum.  
I got some trouble with the void command; I couldn’t use a save(""); in a void. See an example below, when I execute it, it will say “ArrayIndexOutOfBoundsException: Coordinate out of bounds!”. How can I fix this, I want a file that Processing creates.  
Thanks in advance 🙂!

```auto

String Folder_Name="Test";
color[]Color=new color[10];
void setup(){
  Color[0]=color(0,0,0);
  File Folder1=new File(Folder_Name);
  Folder1.mkdir();
  CreateTexture(0);
}
void draw(){
}
void CreateTexture(int Number2){
  surface.setSize(500,500);
  background(Color[Number2]);
  save(Folder_Name+"\\A.PNG");
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 4, 2020, 5:57pm UTC](https://discourse.processing.org/t/save-command-in-void/16863/2 "2020-01-04T17:57:03Z")

</div>

to give you a start:

```auto
String outfile = "data/a.png";
color[]mycolor=new color[10];
boolean saveit = true;

void setup(){
  size(500,500);
  mycolor[0]=color(200,200,0);
}

void draw(){
  background(mycolor[0]);
  if ( saveit ) save(outfile); // the subdirectory is created automatically
  saveit = false; // do not save 60 files per sec.
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 4, 2020, 6:23pm UTC](https://discourse.processing.org/t/save-command-in-void/16863/3 "2020-01-04T18:23:44Z")

</div>

You can refer to the reference to learn about [save()](https://processing.org/reference/save_.html) function. To find the sketch folder in the PDE click the menu _Sketch \>\> Show Sketch Folder_ and it shall display your sketch folder.

To get the location of your current created folder in your OP, you can add the following line right after you create the folder: `println(Folder1.getAbsolutePath());`

Finally, Folder1 should be replace with **folder1** aka notice the lower case letter. Capital letter is reserved for naming classes and variables should begin with lower case. This is not an issue of your code but more of best practices to ensure your code is readable by others.

Kf

---

<div class="post-metadata">

**Author:** ![Optyfen\_met\_Eenden](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@Optyfen\_met\_Eenden](https://discourse.processing.org/u/Optyfen_met_Eenden)\
**Post date:** [January 4, 2020, 6:35pm UTC](https://discourse.processing.org/t/save-command-in-void/16863/4 "2020-01-04T18:35:23Z")

</div>

Wow, thank you all! t worked for me, I think I understand it.

---

<div class="post-metadata">

**Author:** ![Optyfen\_met\_Eenden](https://avatars.discourse-cdn.com/v4/letter/o/ea5d25/32.png) [@Optyfen\_met\_Eenden](https://discourse.processing.org/u/Optyfen_met_Eenden)\
**Post date:** [January 4, 2020, 7:03pm UTC](https://discourse.processing.org/t/save-command-in-void/16863/5 "2020-01-04T19:03:50Z")

</div>

I figured out that surface.setSize created the problem of its failure. I removed that, and everything functioned perfectly. Thank you anyway!
