Skip to content

Commit d2996cd

Browse files
authored
Merge pull request #1037 from sidwellr/2.0
Fix 2.x Table and JSON examples
2 parents 8e1ad51 + 839cdf2 commit d2996cd

File tree

2 files changed

+4
-7
lines changed
  • src/content/examples/en/14_Loading_And_Saving_Data

2 files changed

+4
-7
lines changed

src/content/examples/en/14_Loading_And_Saving_Data/01_JSON/code.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ let mousePressY = 0;
88
// Remember whether bubble is currently being created
99
let creatingBubble = false;
1010

11-
// Put any asynchronous data loading in preload to complete before "setup" is run
12-
function preload() {
13-
// Load the JSON file and then call the loadData() function below
14-
loadJSON('/assets/bubbles.json', loadData);
15-
}
16-
1711
// Convert saved bubble data into Bubble Objects
1812
function loadData(bubblesData) {
1913
bubbles = [];
@@ -31,9 +25,11 @@ function loadData(bubblesData) {
3125
}
3226
}
3327

34-
function setup() {
28+
async function setup() {
3529
let p5Canvas = createCanvas(640, 360);
3630

31+
await loadJSON('/assets/bubbles.json', loadData);
32+
3733
// When canvas is clicked, call saveMousePress()
3834
p5Canvas.mousePressed(saveMousePress);
3935

src/content/examples/en/14_Loading_And_Saving_Data/02_Table/code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function loadData(table) {
2525
// Put object in array
2626
bubbles.push(new Bubble(x, y, radius, name));
2727
}
28+
return table;
2829
}
2930

3031
async function setup() {

0 commit comments

Comments
 (0)