Skip to main content

How to Execute code from Agent's position?

Comments

14 comments

  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    What language are you using? (block based code, Makecode Python, Notebooks Python)

    There are commands to save locations. You could use the location of the agent as a reference point.

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    I was using block based code for java script.

    I've seen in the builder blocks where you can teleport builder to a location and set mark but then fill would fill according to my location from the mark when I tried it. 

    Any tips on how to save locations using the agent as a reference point?

    I've written the program using the fill blocks and relative positions.

    I really want to figure out how to make the positions relative to the agent's location instead of mine.

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Okay, this could stand more thorough testing, but it gives you the general idea. (The agent is stuck inside the build.)

     

    https://makecode.com/_CWb5FH11z024

    0
  • Hi Aleece Landis- maybe something like this? 

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Thank you for the suggestion.  However, I don't really want to have to run that many more commands.  Is there any way I can use the builder to Fill without it using ME as one of the reference points?

    I would really prefer if I could have the builder use fill commands since I'm filling large spaces at a time and to change the single fill command for running 5 commands for each block placed seems way less efficient.

    I don't really understand the point of the

    Say Join "builder position is" builder position command?

    Also what is the point of placing the mark, it doesn't seem to get used in this example since you are then moving the builder before placing the next block?

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Is there some way I could tell the program to execute at a particular position?  I know I see some blocks that have position but I'm having trouble figuring out how to use them.  And so far the Help examples don't seem to be very informative.

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Did you click on the makecode link I gave you? Did it seem to be the direction you wanted to go?

    The "agent position" is a value that gives you the coordinates of the agent's position. Using that, you can calculate another relative position from the little agent. Try running the example in a flat world and play around. I think you will see what I mean.

    I'm glad to see your enthusiasm for Minecraft and coding. It's a blast, isn't it?

    ***** perhaps if you are still having trouble, you could post a link to or a copy of your code, so we could follow along a bit more closely? *****

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Sorry, @deborah alexander  I'm not seeing the links?  I don't know what it is about this forum but I have some challenges with it I think.

    I have been playing around with it in a flat world trying to figure out what works and doesn't.

    hum, I think maybe I just figured out how to use the execute as,  I'm going to test a little more.

     

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    here's a snip:

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Ok not quite sure how to go about posting a copy of the code.  I think maybe I'm dealing with a little instability with the code builder because it keeps locking up every so often and I have to get out of minecraft and back in.

    Anyway, I've been trying to figure out how to call functions and have them run as if from a location other than myself.  I created the functions using the Blocks for fill from ~x ~-y ~z to ~-x ~-y ~-z.  But I don't seem to be able to get those to run from any location other than my own.

    However, I have found that I can use the Execute as to run commands as if they were typed into chat.  So now it looks like I will need to re-write all the functions in this form.

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Ok finally I was able to take a snapshot.  (last few tries code builder froze and I had to restart.)

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Now I just have to figure out how to get the different colors of wool using commands? 

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Benefit of the execute command is that I can put the entire build into the code editor to save it for use in other worlds.  Before when I was trying to use the Blocks fill code blocks, I was NOT able to place the border_blocks, allow blocks or deny blocks.

    It will just take a little while to input them all.

    0
  • Aleece Landis
    Bug Zapper Beacon of Knowledge Super Star

    Well I guess I just learned how to create a function file in make code.  Actually much easier to do it this way since it is such a pain to actually try to do it with an actual function file in education edition.

    AND it is nice to be able to Place the function reference position using the agent.

    Anyway, to solve my problem, I had to rewrite all of the function code using execute blocks instead of the Block Fill blocks.  I would post another snapshot here but code builder keeps freezing whenever I try to do that.

    Nice things about the execute blocks is you are choosing who/what is executing the code and the position or relative position where it executes from and then simply pasting the command without the / into the text area.

    Hum, now I wonder if I can use this to actually place command blocks with the settings and commands installed?

    *************************Update August 16, 2021*****************************

    So I've managed to re-write the whole thing using execute as blocks so that I can place my agent in a set location and run the commands as my agent using the agent's relative position.  So I can build and take down the walls repeatedly without them accidentally being in the wrong place (and possibly messing up some ones build.)

    If you can build it using the fill commands, you can build this way and then save the file and use it in another world to build the same structures in different worlds.  AND by using the agent as a set position, it may be a little easier to make sure you locate the build exactly how you want it.  Always best to export a world save just in case you mess up since there still is no easy undo option without mods.

    Unfortunately, this file must be too big for me to take a snapshot to share here since every time I try to do snapshot to show, the code builder screen goes white and locks up and I have to shut it down.

    0

Please sign in to leave a comment.