Skip to main content

How to replace random blocks with a different type of block

Comments

3 comments

  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Hi, Ashley. I'm excited to hear about all of this creative thinking! There are always many ways to accomplish something, so please allow me to ask a few questions. What kind of code have you been using so far? (MakeCode Python? Block code? Python Azure Notebooks? Chat commands?)

    I agree that one way to choose blocks is to select them from actual blocks in the world. Another way is to have a list (or array) of block references (like their names or ids.) All of this will depend on what kind of code you are using.

    Then the only thing will be how to write the code to choose where to randomly change blocks, and for which random block results.

    FWIW my class is currently placing blocks using arrays of blocks. We are selecting the blocks based on a random number when we place them. It's just like building a regular wall, except that when you place the block, you choose which block to place. Your code will kind of go over the wall afterwards and "edit" the wall. Will I change this block? If so, how? At least, that is what seems most sensible from my view.

    Let me know how I can help. 

     

    0
  • Ashley Gumtow

    Thanks for the reply! We've been using Makecode. I wasn't sure if it was possible with the blocks, or only possible with written code instead. 

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    It's possible either way, but you need to have a strategy. Does the agent have access to the whole wall? The have the agent move across the whole wall (use the same code that built the wall, but replace the line of code that places the block with a random number generation, and a conditional statement. If the random number is the desired value, break and replace with the new block, otherwise continue.)

    0

Please sign in to leave a comment.