# \[p5\] cycle of work order

**URL:** <https://discourse.processing.org/t/p5-cycle-of-work-order/38955>\
**Category:** Coding Questions\
**Created:** [September 24, 2022, 1:04am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955 "2022-09-24T01:04:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 24, 2022, 1:04am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/1 "2022-09-24T01:04:24Z")

</div>

[p5] cycle of work order

1. In ‘p5’, ‘preload()’ function is provided to prepare in advance.

2. However, there are cases where priority is needed even within the ‘preload()’ function.

3. So, the order was given through the while statement.

Is there any better way other than this one?

```auto
var whiles=0;
function preload() {
   while (whiles < 100) {
     whiles++;
            if(whiles== 1){ preload_key(); }
     else if(whiles==91){ preload_image(); }
     else if(whiles==92){ preload_font(); }
   }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 24, 2022, 1:41am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/2 "2022-09-24T01:41:38Z")

</div>

> [@GWAK](#):
>
> Is there any better way other than this one?

You can chain asset loading functions via their 2nd parameter callback:

- [how-to-preload-images-using-filenames-from-a-txt-file#Item\_3](https://Forum.Processing.org/two/discussion/18043/how-to-preload-images-using-filenames-from-a-txt-file#Item_3)
- [preload-images-from-csv](https://Glitch.com/edit/#!/preload-images-from-csv?path=sketch.js:1:0)

On the sketch above, after **loadTable()** finishes, it calls back **createPlayers()**; which in turn calls multiple **loadImage()**, based on the URLs within **preload()** CSV file.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 24, 2022, 6:48am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/3 "2022-09-24T06:48:29Z")

</div>

Dear GoToLoop / @GoToLoop

Thank you for answer.  
As you said, some functions have a ‘callback’ function.  
‘loadStrings(filename, [callback], [errorCallback])’

However, what I need is to create a ‘callback’ function. I want to put a ‘callback’ function in my function, is this possible?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 24, 2022, 6:55am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/4 "2022-09-24T06:55:48Z")

</div>

> [@GWAK](#):
>
> I want to put a ‘callback’ function in my function, is this possible?

Callback is a function which is automatically called back when some event triggers:

> **[Callback function - MDN Web Docs Glossary: Definitions of Web-related terms |...](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function)**
>
> A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 24, 2022, 7:20am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/5 "2022-09-24T07:20:56Z")

</div>

@GoToLoop

Thank you.

```auto
processUserInput(intput);
function intput() {  
  console.log(1);
  //------------------------------------//
  // STEP-1 FUCTION
  //------------------------------------//
}
function processUserInput(callback) {
  callback();
  console.log(2);
  //------------------------------------//
  // STEP-2 FUCTION
  //------------------------------------//
}

```

Is my understanding correct?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 24, 2022, 7:29am UTC](https://discourse.processing.org/t/p5-cycle-of-work-order/38955/6 "2022-09-24T07:29:01Z")

</div>

Have you taken a look at the links from my 1st post?  
It’s not about us calling back functions but p5js’ loading functions doing that.
