Skip to content

zParticlesModule Validation Documentation

Dan edited this page Nov 8, 2022 · 1 revision

zParticlesModule Helper Library Documentation

Make sure you add the zParticlesModule library to your level. Use Ctrl+Click to add the library to your level!

Prerequisite: You also need the zCriterionValidationLibrary library in your level too. Use Ctrl+Click to add the library to your level!

Copy-and-paste this into each level you want to validate using this library

if(World.frameCount == 1) {
  setFailTime(150);
  setDelayTime(90);
  setupPrevious();
  setupParticlesValidation(); // <-----------

  // addCriteria functions here

}
getHelperVars(); 
check();
updatePrevious();
updateParticlesValidation();

Functions

setupParticlesValidation()

Adds special variables to track specific behaviors with special particles blocks created in the ParticlesBlocks pool. This function is designed to be called just once, inside the if-statment when writing validation code.

updateParticlesValidation()

Keeps track of previous state of specific variables for the special particles blocks. This function is designed to be called every frame, outside the if-statement when writing validation code.

checkValidation()boolean

Checks if we're in a level that involves validation. This function is designed to be called within the helper code for a custom block, not in validation code itself.

addParticlesBlock(blockObj)

Adds a new custom block to the special variable keeping track of things for the special particles blocks. The block should be an object with properties, but the specific format can be whatever makes the most sense as long as it's consistent. This function is designed to be called within the helper code for a custom block, not in validation code itself.

setupParticlesValidation()

Adds special variables to track specific behaviors with special particles blocks created in the ParticlesBlocks pool. This function is designed to be called just once, inside the if-statment when writing validation code.

Kind: global function
Example

if(World.frameCount == 1) {
  setFailTime(150);
  setDelayTime(90);
  setupPrevious();
  setupParticlesValidation(); // <-----------

  // addCriteria functions here

}
getHelperVars(); 
check();
updatePrevious();
updateParticlesValidation();

updateParticlesValidation()

Keeps track of previous state of specific variables for the special particles blocks. This function is designed to be called every frame, outside the if-statement when writing validation code.

Kind: global function
Example

if(World.frameCount == 1) {
  setFailTime(150);
  setDelayTime(90);
  setupPrevious();
  setupParticlesValidation(); 

  // addCriteria functions here

}
getHelperVars(); 
check();
updatePrevious();
updateParticlesValidation(); // <-----------

checkValidation() ⇒ boolean

Checks if we're in a level that involves validation. This function is designed to be called within the helper code for a custom block, not in validation code itself.

Kind: global function
Returns: boolean - true if we're in a level we want to validate and false otherwise. Does not check if the zParticlesModule helper library has been added to the level.
See: statesOfMatter Custom Block
Example

function statesOfMatter2(costume, behaviorStr) {
    //For Validation
    if(typeof checkValidation === 'function' && checkValidation()) { // <---------
      var newBlockObj = {
        blockName: 'statesOfMatter',
        costume: costume,
        matter: behaviorStr
      };
      addParticlesBlock(newBlockObj);
    }
	//Function
	// Code omitted for brevity 
}

addParticlesBlock(blockObj)

Adds a new custom block to the special variable keeping track of things for the special particles blocks. The block should be an object with properties, but the specific format can be whatever makes the most sense as long as it's consistent. This function is designed to be called within the helper code for a custom block, not in validation code itself.

Kind: global function
See: statesOfMatter Custom Block

Param Type Description
blockObj object an object representing a custom block in this level.

Example

function statesOfMatter2(costume, behaviorStr) {
    //For Validation
    if(typeof checkValidation === 'function' && checkValidation()) {
      var newBlockObj = { // <----- new block object
        blockName: 'statesOfMatter',
        costume: costume,
        matter: behaviorStr
      };
      addParticlesBlock(newBlockObj); <------
    }
	//Function
	// Code omitted for brevity 
}

Functions

getParticlesBlocks()array

Gets the current block log for the custom particles blocks.

checkNewParticlesBlockThisFrame()boolean

Checks if a new particles block was used with an event.

getMostRecentParticlesBlock()Object

Gets the most recent particles block object that occurred

checkThisParticlesBlockThisFrame(blockName)boolean

Checks if a specific particles block was used with an event.

getParticlesBlocks() ⇒ array

Gets the current block log for the custom particles blocks.

Kind: global function
Returns: array - An array of the blocks that have occurred so far in the level. Each element of the array is an object in a specific format.
See: Click here for an example level that uses this function
Example

addCriteria(function() {
  var particlesBlocks = getParticlesBlocks();
  return particlesBlocks.length >= 1;
}, "noParticlesBlocks");

checkNewParticlesBlockThisFrame() ⇒ boolean

Checks if a new particles block was used with an event.

Kind: global function
Returns: boolean - True if the particles block was used with an event, false otherwise
See: Click here for an example level that uses this function
Example

addCriteria(function() {
  //Check if the first sprite had an event that caused a particles block to run
  return checkThisSpriteClickedThisFrame(spriteIds[0]) && checkNewParticlesBlockThisFrame();
}, "noParticlesBlocks");

getMostRecentParticlesBlock() ⇒ Object

Gets the most recent particles block object that occurred

Kind: global function
Returns: Object - The particles block object, which always has a blockName property but the other properties may vary based on the block.
See: Click here for an example level that uses this function
Example

addCriteria(function() {
  //Check if a statesOfMatter block was set to a gas behavior
  var block = getMostRecentParticlesBlock();
  return block.blockName == "statesOfMatter" && block.matter == "gas";
}, "wrongStateOfMatter");

Example

addCriteria(function() {
  //Check if a statesOfMatter block was set to a gas behavior when a sprite was clicked
  var block = getMostRecentParticlesBlock();
  return checkNewParticlesBlockThisFrame() && block.blockName == "statesOfMatter" && block.matter == "gas";
}, "noParticlesBlockWithClick");

checkThisParticlesBlockThisFrame(blockName) ⇒ boolean

Checks if a specific particles block was used with an event.

Kind: global function
Returns: boolean - True if the particles block was used with an event, false otherwise

Param Type Description
blockName String the name of the block. Must be the same as the hard-coded name used when creating block objects within the block helper function (see addParticlesBlock() for an example)

Example

addCriteria(function() {
  //Check if the first sprite caused a represent block to trigger
  return checkThisSpriteClickedThisFrame(spriteIds[0]) && checkThisParticlesBlockThisFrame("statesOfMatter");
}, "noParticlesBlocks");
Clone this wiki locally