Thursday, 4 January 2018

15) Using Loops and Conditional blocks

Using Loops and Conditional blocks

Control blocks are used to manage the flow of script. Using control blocks scripts can be looped, paused, or their flow can be changed under certain conditions. It can also be used to send signals to other sprites.

Conditional Control Blocks
  1. If Block:



    If the condition specified is true then the script inside is executed. All conditions are in the form    
    hexagon. These blocks are present in Sensing and Operators options in blocks palette. Some     examples sensing options are “Key “space” pressed” , “Touching Color ?”. By inserting these     conditions in if block, the script is executed only if the condition is satisfied. For Example, in      the sample code below the script is executed if sprite is touching pointer, the sprite will cry     “meow”.




  1. If Else Block:
   

    If the condition is true then script under the if block runs else the condition under else block     runs. For Example, in the following script the sprite says “Hello!” if mouse is on sprite, else it     says “Where are you my friend?”.


  

Loop Control Blocks

  1. Forever block:

Forever block can be used to run the script inside again and again. You can drag other blocks in between the forever block. A sample script is shown below:



  1. Repeat Block:



    Repeat block loops the script specified number of times. For example, in the above block the     code inside will get repeated 10 times.

  1. Forever If:



    It continuously checks if the condition is true, and executes the script inside the forever block.


Other Control Blocks

  1. Wait : Pause the script for specified amount of time.

   
  1. When key pressed: When specified key is pressed then script starts running. List of key options can be seen by click on down arrow in the block.



  1. Broadcast:  Send Message to all sprites and then continues to the next block without waiting.


  1. Broadcast and Wait: Send message to all sprites and waits until they finish, before continuing to the next block.


  1. Stop script: Stops the current script.


  1. Stops All Scripts: Stops all the scripts in all sprites.


No comments:

Post a Comment

1) Introduction to Email

Introduction to Email Introduction Communication, the transfer of information, has been the key element needed ...