Skip to main content

Text functions in block coding don't appear to be working

Comments

15 comments

  • Tim Longman

    Any comment on whether this is a bug? Some of the text functions don't appear to work and have zero documentation. How do I submit a bug report?

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    I think the split command takes string elements and converts them to elements in an array.

    (works with commas, too!)

     

     

     

    1
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Hi, Tony Wang welcome to the community!

    The Minecraft community is a great place for people to share their experiences using Minecraft for Education, get help when needed, and help others when they can. It makes everyone's Minecraft world a better place. It's one of the wonderful things about the internet, right? - helping and befriending people you have never even seen!

    So if you have a question or a helpful comment, chime right in! There's always room to get to know someone new!  I'm sure you can see that it is hard to do any of those great internet things with your small comment there. Find somewhere to contribute, and jump on in! =]

    0
  • Moderator Beacon of Knowledge Super Star

    That's a good question!  You want to go to here:

    https://educommunity.minecraft.net/hc/en-us/community/topics/360001798152-Coding-with-Minecraft

     

    and click the NEW POST button (or my screen shows one at the bottom of this very page!

    Then put your question on a new pot and see what happens! Good luck with your first post! and Welcome to the community. =]

    1
  • Tim Longman

    That is great! Works better than I assumed. Thank you. 

    Whoever is in charge of the documentation should put this in since there is no documentation for this function.

    1
  • Tim Longman

    Hi, unfortunately - your code works - but when I try and use it for an array of player names - it doesn't....... can you see where I am going wrong? As you can see I can get a list of the 2 players in the game with a comma, but the split function doesn't seem to find that comma. Is it a special comma?

     

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Aside from the comma question, you may have a different issue. I think players may be a special object in Minecraft, not just a string name.

    I'm not sure. try running this to see what I mean:

    them = world._all_players
    say (them)

     

     

    0
  • Tim Longman

    Not sure what you mean. I tried converting to Python and the code switches back and forth. But the Python version doesn't seem to work in same way.

    I used the "to string" function to turn the list into a proper string - and that seemed to work.

    Am I going about this the wrong way though. Is there an easy way to create an array of current player names I haven't thought of?

    0
  • Tim Longman

    Just all a bit strange. I think the text functions may be a bit buggy. They aren't fully documented and I guess they are not used that much - hence it has slipped under the radar. I did some more experiments and the join function is happy with that string - but the other functions just don't like it.

    https://makecode.com/_2g6M9hUhaUCc

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    I think references to players and entities are not usual array elements:

    It creates a string of the entities, but splitting a list of string form "Target Selectors" seems to be the problem.

    Micah-M

    0
  • Micah M
    Beacon of Knowledge

    Hi Tim Longman,

    Thanks for reporting the issue with split not working correctly after converting from Blocks to Python. Our team has been able to verify the problem and I'm passing the feedback on to the MakeCode team.

    Deborah got it exactly right - what you are seeing in your examples is that the purple block returns a "TargetSelector" type and not a simple array. Array and string manipulation functions may not work as you'd expect on the TargetSelector objects as they are designed to be used with other purple blocks. That said, many of the blocks do let you use them with other types of blocks, so trial and error and experimentation are the best ways to learn.

    What is the final result you are trying to achieve? If we knew your goal we may be able to offer a few suggestions to help you get there.

    Thanks!
    Micah 

    1
  • Moderator Beacon of Knowledge Super Star

    Thanks, Micah! I think Tim Longman sounds like he has something interesting up his sleeve, so I hope we can determine that workaround out.

    Tim, you have intrigued me. What were you going to do with that array of players?

    0
  • Tim Longman

    Thanks guys,

    In your example you didn't use the "to string" function to turn the selector into a string. The substring, split, and find text functions don't work - but "join" does quite happily. 

    What I am trying to do is find a way to keep scores for players in a 2d array and also be able to give specific players items, or xp or whatever. 

    The selector only allows for random players or for yourself.

    First task is to simply get all the active player names!

    0
  • Moderator Beacon of Knowledge Super Star

    I like where you are going. I think the 2-d array with string versions of player names and an integer for XP amounts will be attainable. What I think will be trickier will be getting a usable player target selector to allow you to address a player when you want to give them something.

    In the world._all_players (post above) you see the results of the target version. I wish you great success with parsing these selectors out. I was able to do some things with the target selectors, but not get a *working target selector variable *into an array.

    I'd love it if you would share your code (above) with me, if you are willing. It is a great idea. I would enjoy also trying to make it work somehow. But in any event, let me know how it goes. I have wanted to do things like this with NPCs and such, myself. =]

    0
  • Tim Longman

    I haven't got very far! Fell at this hurdle! How do you test the world._all_players method? I haven't strayed far off block programming so far.

    My makecode ref is _2g6M9hUhaUCc but there isn't much code there.

     

    0

Please sign in to leave a comment.