Skip to main content

Placing blocks by ID using more than one array

Comments

5 comments

  • Laurence Boulter

    Hi Debbie. Sorry to not have got back to you sooner. I have to fit this in with my other adventures... so need to to take of the ones that pay me first! I spend time n this last Friday, but deviced to start over. I don't think the "place block by ID" block will accept a text based variable to represent the ID of a block. So I restructured and replaced the 19 column arrates for each level with much longer arrays and wrote a routine to work through te three arrays for the three levels of blocks. Works a treat!

    I'm spending a day on the project tomorrow, and was going to get back to you then. Don't know if you are on LinkedIn but...

    https://www.linkedin.com/posts/laurenceboulter_edtech-minecraftedu-activity-6994454249912815616-tRIu?utm_source=share&utm_medium=member_desktop

    (hopefully that works?)

    ... but I'll share the code with you.

    Thanks for sticking with it!

     

     

    1
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    It would be nice to know more about the column arrays (colarrays) and col, since you initialize from 0-18 and the access from 0-29 and I'm not quite following without seeing all the code.

    But if I am understanding you correctly, your line of code which currently has a compatibility error (that triangle) works fine when you substitute the "name of the column array" So the command is just the purple "place" and then "col" - right? and that works?

    So I think the problem is that you need a new variable. In run2 you set col to an element of colarrays, and it has that datatype now.

    So either you want colarray get value at index in run3, or something else like a new variable. But I need more code (and commented code =] please ) to say more.

    Hope it helps.

     

    0
  • Laurence Boulter

    Brilliant! Thank you! I have 19 column arrays each with 30 elements, and another array to list the 19 column variables so pretty difficult to take a meaningful screenshot. Completely understand the need to create another variable, and I did try, but just could not shake off the compatibility error, but probably more to do with my inability to manage or control data types than anything else.

    But if I am understanding you correctly, your line of code which currently has a compatibility error (that triangle) works fine when you substitute the "name of the column array" So the command is just the purple "place" and then "col" - right? and that works?

    Exactly right!

    When I run the code the "col" and "index1" variables increment correctly but the "place" command can't accept that "index1" refers to a position in the array "col", - but does if I specifically name the array and don't use the "col" variable which correctly contains name of the appropriate array. 

    Block by ID here is always text, whether as the col variable or as a direct reference to the array. "Index1" is always an integer incremented by the "for" loop. But it works for the direct reference but not with the variable."Place" is looking for a number and I don't understand why it can't pick up the number in the array "col" at position "index1". I worried that my arrays were not defined properly (as integers), but then the routine would not work when I substitute "col" with a direct reference to the array - at which point I got lost!

    I'll happily annotate some screenshots if you have the time to take a look. I do appreciate the support.  Thank you.

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    So how about adding a line, (prior to the place command,) accessing the value you want using the index1, (saving the amount in a variable) and then using THAT variable in the place command, so you get the movement through the array properly?

    Am I tracking along? Worth a shot?

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Laurence Boulter So how is it going? If you are working in MakeCode, you can share the code with the share link also.

    0

Please sign in to leave a comment.