Skip to main content

Variables' value gets erased

Comments

7 comments

  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    May I ask if base 1 is calling a procedure in the same coding window?

    I ask this because if you have called another program, your code has been reset, and the values would be expected to be zero again, because you did not call the initialization code again.

    0
  • Rodrigo González

    yes, "base" is another chat command in the same coding window. 

    What I've noticed is that the variables get reset every now and then, specially if you open and close the coding window several times. But sometimes, the variables keep their values for a long time if you just call all the programmed chat commands from the chat console, without opening the coding window  

    0
  • Rodrigo González

    I can post the URL of my code in case you want to import it:

    https://minecraft.makecode.com/20584-09596-35966-85559

    Basically, my program receives the initial coordinates through the chat command (e.g: "inicio 25  4 -12"). The "base" command buidls a 10x10 square built with the material passed as a paremeter in the chat command line. For example: "base 41" builds a square with blocks of gold (id=41)

    With the chat command "borrar" you can erase the base (simply by replacing the blocks in the 10x10 square with air. After that, you should be able to build the same structure with "base 41" again, but many times it fails (if it doesn't work, just type "coordenadas" in the chat command line to print the value of the inicial coordinates. You will see that very often (0, 0, 0) is printed, meaning that the variables have reset to 0 spontaneously

    0
  • Rodrigo González

    Does the program (my code) initialize every time I press "C" to open the code builder? As far as I understood, it shouldn't 

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    My understanding is that when you use "c" you stop the execution of the code in Makecode.

    If your code is working, you should just use the chat commands and continue to use them.

    Sometimes, when I have set up multiple on_chat commands in my code, I have to make notes to keep things straight, because the temptation is to open up the code. You can't reopen the same code or open other code, as far as I know.

    Give it a try and let me know. And pleased to meet you. I am always happy to meet another coder!

    0
  • Rodrigo González

    Thanks! that would explain the behavior.

    Do you know if there is any way to share a variable across different  code windows? That would be great in a multiplayer environment. 

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    I would *love* access to global variables in MakeCode and Python AZNb, as you mentioned. It would help in many situations, like the one you have described. Even a small number with predefined names would be incredibly useful, as you are experiencing. Laylah Bulman

    1

Please sign in to leave a comment.