I’ve had a look at the perlin noise example:
and have been so far successful translating the LightningBolt.cs file to .js, however with the following error:
//C#:
Perlin noise;
Translation:
//JS:
private var noise : Perlin = new Perlin();
Doesn’t work, nor does
//JS
private var noise : Perlin;
resulting in error:
The name ‘Perlin’ does not denote a valid type (‘not found’). Did you mean ‘TreeEditor.Perlin’?
It doesn’t look as though I need to import anything for JS either.
What’s the issue?
Ah, thank you! I never realized there was a plugins folder for the perlin.cs file, in fact, never knew it existed…
Although the same error occurs, I moved the .cs and plugin file to my project and the original LightningBolt.cs works - but now I have to translate Perlin.cs to .js as the LightningBolt.js doesn’t work with it?
Edit:
Tried adding:
class Perlin{
function Perlin(){}//defines the Constructor
}
to the start of the file (before function start) and that removed the variable error, however I still get these errors:
Unknown identifier: ‘perlin’.
‘Noise’ is not a member of ‘Perlin’.
for
var offset : Vector3 = new Vector3(perlin.Noise(timex + position.x, timex + position.y, timex + position.z),
noise.Noise(timey + position.x, timey + position.y, timey + position.z),
noise.Noise(timez + position.x, timez + position.y, timez + position.z));
I’m unsure what you are doing here. Are you converting the entire Perlin.cs script over to JavaScript? If so you have to convert all of it. You are getting those errors because you just have an empty class with nothing in it. Therefore, when you are trying to call the Noise() function, it doesn’t exist.
I was trying to convert LightningBolt.cs to js, and have the js interact with the .cs perlin plugin but if I need to convert perlin.cs to .js, so be it. I’ll give it a shot.
You either need to convert the Perlin.cs to JavaScript or place it somewhere to ensure that it is compiled first (usually, this would be in Assets/Editor while your other script is in Assets/Scripts, for example), but it is generally a better idea not to mix languages (write your project in either JavaScript or C#).