/    Sign up×
Community /Pin to ProfileBookmark

Library doesn’t seem to be initilized for me to declare global variables

I am using the p5.js and the matter.js libraries. The following code produces a [B]ReferenceError[/B] saying that [B]Matter[/B] wasn’t defined on [B]line 4[/B]

[CODE]let width = 900;
let height = 600;

var Engine = Matter.Engine,
World = Matter.World,
Bodies = Matter.Bodies;
var engine = Engine.create();
var world = engine.world;

function setup(){
createCanvas(width,height);
car = new Car(100,height/2);
}[/CODE]

When the variables are declared within the setup function, everything worls fine, except I am not able to access the variables in my [B]car [/B]object

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERNov 10.2017 — Where is the code located that defines the Matter function?

Cannot call what it cannot see where to look.


BTW, welcome to the forums.

?
Copy linkTweet thisAlerts:
@xtfishburnxauthorNov 10.2017 — Thank you! The code that contains the Matter function is located in the same directory as the sketch. I dont even get an error that it cant find the library specified in my html.
Copy linkTweet thisAlerts:
@JMRKERNov 10.2017 — So you are using something like the following to access the external files?
<i>
</i>&lt;script src="p5.js"&gt;&lt;/script&gt;
&lt;script src="Matter.js"&gt;&lt;/script&gt;

Somewhere before you call the functions?

Sorry for the questions. Just not specified in what you have posted so far.

Do you have the entire HTML, JS and/or CSS available to see or link to?
×

Success!

Help @xtfishburnx spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...