Help with particle script error


#1

Can someone advise me RE. line 7 - although it says “expected :” i know there is more to this than simply a missing colon

L1 // myParticleTest_v3
L2 var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
L3 var properties = {
L4  type: “Box”,
L5  position: position,
L6  color: { red: 0, green: 255, blue: 0 },
L7  particles,
  // [SyntaxError] Expected `:’ in c:/xxx/HighFidelity/Particles myParticleTest_v3.js:7(12)
};
Ent = Entities.addEntity(properties);
print(“Entity added”);

Entities.editEntity(particles, {
            additiveBlending: 0,
            alpha: 1,
            alphaSpread: 0,
            alphaStart: 1,
            alphaFinish: 1,
            
            emitRadiusStart: 0 , //can be zero
            particleRadius: 0.04,
            radiusStart: 0.04,
            radiusFinish: 0.04,
            radiusSpread: 0,      
               
            emitRate: 50,
            
            emitSpeed: 0.2, //minimum is 0.1
            speedSpread: 0.0,

azimuthStart: 0,
            azimuthFinish: 0,
            
            polarStart: 0,   //set as 1 for cone shape
            polarFinish: 0,  //set as 1 for cone shape
            
            emitAcceleration: { x: 0.0, y: -0.3, z: 0.0 }, //gravity
            accelerationSpread: { x: 0.0, y: 0.0, z: 0.0 },
            emitDimensions: { x: 0.0, y: 0.0, z: 0.0 },
            //emitOrientation: { x: 0.0, y: 0.0, z: 0.0 w: 0.0},
            
            textures: “https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png”,
            
            color: { red: 255, green: 255, blue: 255 },
            colorStart: { red: 255, green: 255, blue: 255 },
            colorFinish: { red: 255, green: 255, blue: 255 },
            colorSpread: { red: 255, green: 255, blue: 255 },
            
            lifespan: 30.0,
            maxParticles: 1000,
             lifetime: 3600,  // 1 hour; just in case
                    animationIsPlaying: true
                }());


#2
var properties = {
    type: "Box",
    position: position,
    color: { red: 0, green: 255, blue: 0 }, 
    particles, 
};

This is not legal JavaScript. properties needs to be in the form of…

var properties = {
    name: value,
    name: value,
    name: value
};

Where name is something like “type”, “position”, “color”, etc…

You can have property names that are unknown, misspelled, etc. and they will just be ignored… In this case “particles” is not a valid property name and so it would be ignored if it was included with a value. But since you’ve written a name without a value, it’s not syntactically correct and that’s why you’re getting the error you’re getting.


#3

@ritzo Have a look at \examples\example\entities\particleTest.js.

For particles you need to an entity of type “ParticleEffect” (not “Box”).
For editEntity() you need to pass in the ID of the entity return by addEntity().


#4

thanks guys, i know you mean well …
I’ve learned a lot over the past weeks from particleTest.js and the corresponding generated JSON files, its a  great visualisation tool, but i gave up trying to edit it, there are just too many variables in the script plus deprecated syntax that it was difficult to tell what actually worked/didn’t work or when values where in/ or out of acceptable range.

For example i can make nice ‘falling snow’ but after a a minute or so the value for
 emitAcceleration: { x: 0.0, y: -0.3, z: 0.0 }, //gravity
would revert to a positive value (snow rising), why i don’t know, when no other value was changed.
So it seemed a simple proposition - rezzz a box which emits particles based on a very simple list of current values which i can save in an easily  readable form.
I am not a coder, copy and paste is my idea of coding :slight_smile: the particle effects are what interest me, but what is so hard is that there are millions of pages on using .js for web page stuff, but if you google “.js + particle” there is very little, in fact looking for any .js scripts, which may be applicable to  HiFi,  and you are in the wilderensss. For those of you from a  computer science background this might not be a problem but for the rest of us (?) i suspect its a nightmare.

I realise from both your comments that if have made some fundamental errors - illegal even hehe
"For particles you need to an entity of type “ParticleEffect” (not “Box”). Ok i can do that and i didn’t really need the box anyway

var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
var properties = {
  type: "ParticleEffect",
  position: position,
};

but of this
"For editEntity() you need to pass in the ID of the entity return by addEntity()."

and i have no idea how to proceed


#5

@Ritzo In \examples\example\entities\particlesTest.js, notice the following …

particles = Entities.addEntity({
    type: "ParticleEffect",
    ...
}

… the ID of the particle emitter is contained in the variable “particles”.

Then if you want to change any of the properties …

    Entities.editEntity(particles, {
        alpha: 0.5,
        ...
    }

… i.e., you include the variable “particles” so that Entities.editEntity() knows which particle emitter to edit.

P.S. particlesTest.js doesn’t generate JSON files; another of the particles scripts does. particlesTest.js is a simpler demonstration of each of the particle properties.


#6

@ctrlaltdavid - success, thanks.
Ah yes my confusion RE. http://public.highfidelity.io/scripts/example/entities/particlesTest.js.
i had run that script many times too, the polar examples in particular are quite amazing