GWAK
September 24, 2022, 1:04am
1
[p5] cycle of work order
In ‘p5’, ‘preload()’ function is provided to prepare in advance.
However, there are cases where priority is needed even within the ‘preload()’ function.
So, the order was given through the while statement.
Is there any better way other than this one?
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(); }
}
}
You can chain asset loading functions via their 2nd parameter callback:
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.
1 Like
GWAK
September 24, 2022, 6:48am
3
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?
Callback is a function which is automatically called back when some event triggers:
1 Like
GWAK
September 24, 2022, 7:20am
5
@GoToLoop
Thank you.
processUserInput(intput);
function intput() {
console.log(1);
//------------------------------------//
// STEP-1 FUCTION
//------------------------------------//
}
function processUserInput(callback) {
callback();
console.log(2);
//------------------------------------//
// STEP-2 FUCTION
//------------------------------------//
}
Is my understanding correct?
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.
1 Like