Skip to main content

block ids with multiple data values

Comments

10 comments

  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Here is a bit of info in that general direction:

    https://educommunity.minecraft.net/hc/en-us/community/posts/4417751617172/comments/4417907942676

    So, if I am understanding, you want to use a command like agent.inspect, and determine which color of wool the agent sees?

    0
  • Keith Lavigne

    Hi Debbie,

    Yes, that is correct.  Another example are the wood planks block that all have the same id but the different data values determine which version the block is.  Inspecting any wood plank returns the same name.  The data value is obviously there as the agent can place different wool/stone/planks.

    Thank you!

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Here is the solution, based on the great info in our shiny, new reference guide!

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Micah-M  My computer science class is finishing up their first unit. We are finishing variables, intro to binary, intro to functions and parameters, and data types (int, float, bool, string and MC:location - we will elaborate on tuples in unit 2.) 

    The new update and Python AZNB Resources have been a blessing and a bit tricky. In the code above, we see a command which used to return a string, but no longer. There are, in fact, not any functions I can find which return a string (world.weather being more of an updated data point, but it's all we have.) We have to return as you see above, and then take variable.name to get a string to use simple data types. Similarly for a few other functions.

    All of my long-winded whining here (haha!) is to ask, is that output from these commands with the colon always a certain data type I can count on? (dictionary, I take it?) Because I don't want to tell them wrong (and I really wish I had simple data types to deal with, but if I have to introduce others, I'd like to just do the ones I have to bit by bit.) 

    The reference guide is a bit behind the latest update for this stuff.

    With regards to teaching the commands, lol, I tell them it used to just give you the cheese, and now you get the whole sandwich! So it's more robust, which is good, even though it broke all our old code (sad face), we can just add one more line. But now we have access to lots more info.

    And while I'm bugging you, the player.add_effect() function returns the value ~none~ and my student was asking if that was a string value. I though it was most likely a game state, but do I look for this in the MC:Python namespace rules? When would it ~not~ be none? (we checked before and after applying the effect)

    And always, thanks for your heroic help!

    0
  • Andrew Mulholland

    Debbie Alexander I can speak about a few of your above points to provide some context.

    Objects - The use of objects I would argue is a big step forward. This allows much more data to be made available, along with the data being made available individually (vs previously having to mush together fields into a single string output, then having to split those after). I agree some work could be done on the __str__ dunder method to allow the object to be treated as a string in some cases and we've put forward this feedback. There are some issues that would need to be worked around to make that work, but I have my fingers crossed!

    Additionally, do take a look at the "Blocks and locations" page in the reference guide. It contains an overview of the objects and their attributes/methods.

     

    Dictionaries - Dictionaries are generally discouraged if at all possible vs an object, as objects are a lot cleaner in Python and work better for error detection systems. If we ever get code completion as well in Notebooks (also got my fingers crossed for this someday) then objects are the only option in this case. So it future proofs the system.

     

    Return types - add_effect() doesn't have a return, hence if treated as though it would, it would return None (note this is not the string "None", it is of type NoneType, aka null, a special datatype in Python). This return type is used for all functions that don't specify a return. In this case, add_effect() doesn't specify a return in its definition. This is why in the reference guide, there is no return mentioned. The only method in the player class that has a return specified is the .position() method. All others will return None automatically.

     

    Outdated reference guide - The reference guide should be fully up to date for the changes in 1.18? It's always possible we missed the odd change here or there, so do let me know if we have so we can get it fixed!

    0
  • Sacha van Straten

    Where can I find the AZNB reference guide please? I’ve downloaded the Intro to Python AZNB guide and Programming with Python PDF, but if there is a reference guide to sit alongside them that would be great to use. 

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Sacha van Straten - there is a wonderful Reference Guide for Python Azure Notebooks right in the game! If you select C to code, and the blue Notebook for Python, you will see the Reference guide right there, with tabbed information available in important subjects and suggested code to try.

    Andrew Mulholland Thanks for all the deets! So, forgive my ignorance, but I never see objects displayed in print... is the {"id":"planks: "namespace":"minecraft"... output an example of an object being printed out, then? I was thinking it had to be a block object, but didn't know how to identify the data I was seeing in the context of what we were learning (does that make sense?) I have no idea where to look for all of the attributes of a block object, but I'm willing to dig! =]

    I *love* love* love* the reference guide. My students were using it today for our CS1 class.  Thanks for the "none" 'splain. Somehow I thought functions returned "True" as a default value, but this is good to know.

     

     

    0
  • Sacha van Straten

    I’m with you. I know where that is. Thank you. I thought for some reason there was a separate downloadable guide. Much appreciated!

    1
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    I'm glad to know you were able to benefit from the Python AZNB Guide!  Sacha van Straten Get in touch with me on Twitter! We are developing a coding crew!

    0
  • Micah M
    Beacon of Knowledge

    Debbie Alexander python is a little sneaky in how it prints objects. The default print statement for a generic object is just the object id (something like "minecraft.world.World object at 0x00000000" which isn't helpful). For native objects and data structures in Python and most of the objects we've created in Minecraft and there are defined print formats. As Andrew said, the {propName1: "value", propName2: "value", ...} isn't actually a dictionary, it's just the format our team chose to use to print the properties we thought were useful in the object. For example: world - player.print(world) and block - player.print(agent.inspect("down")) are both objects, but world has the default print value and block has a custom print value containing the useful properties that our team chose to print for the block object (although it's not a complete list of all of the properties in the block object).

    If you are creating your own objects and want to define their print values, this stack overflow is a good explainer of the __repl__ and __str__ functions which are used to specify what should print when someone tries to print your object: https://stackoverflow.com/questions/33730341/how-to-print-an-object-in-python

    0

Please sign in to leave a comment.