How do I save a value to the array?

0 favourites
  • 12 posts
From the Asset Store
Match the similar cards with each other and free all animals!
  • Summary: I can change the array value, but when I change the layout the array value returns to what it was before.

    In this code here in the photo, if I press Enter on the button option called Right : a variable called Record_keycode becomes True and the sprite font blinks for 5 seconds. At that time in another event, if I press any key on the keyboard it writes that keycode of the pressed key to a specific location in the array called Button_map at (2,54). The problem is that when I leave the menu layout and go to another layout, the array value returns to what it was before, it is not being recorded. I'm not talking about exiting the game (which I'm going to save to local storage), I'm talking about changing layouts. Then I created a test variable called Right_test and also recorded this value in it. The value was saved in the variable. I started messing with array and dictionay a little while ago and found this problem...

  • Do you have events that clear an array on start of layout?

  • No. I made another example to test in a new file that I created, and the same thing happens. It normally changes the matrix, but when I change the layout it returns to the value that was in the matrix. As I'm new to matrix maybe I'm missing something. I want to change the value in the array and it stays changed as long as I stay in the game. It's like a global variable, but I don't understand why it's not keeping it.

  • When you say matrix are you referring to the array? What you're describing is the default, they are global. When you change layout the value at 1,3 should be the same unless you pressed a key.

    Maybe you unticked global on the array object although that would be unusual. Or commonly people have events to reset the array on start of layout which can interfere with it.

  • Yes it is an array and it is marked as global. I really don't understand why it's not holding the value when I change layout. I don't have layout start events changing array. But thanks for answering, I'm definitely missing something, because I create other examples of changing the array and when I change the layout the value always changes in any new example that I do.

    But at the same time I always create a global variable and also write the value to it. In the global variable even when I change the layout it records the value as expected, but the array does not.

  • Check your array in debug mode, maybe your events are changing the width of the array.

  • Share the new file you mentioned that shows the issue and I can take a look.

  • Hello, thanks for the replies. I think I found the problem, but I don't know how to solve it. I forgot to mention that this array I included using json. So every time I change something in this array, when I enter another layout, it reloads the original json data into the array. So I believe that when I change something in the array, I need to save it in the json first, so that when I enter another layout it will download the already changed json to the array. To do this, I think you have to use local storage, right? I will send the file.https://drive.google.com/drive/folders/1Gf0PN-ucJylsJnP9VVvtTGQzVUTnwRCx?usp=share_link

  • That would be an example of clearing the array on start of layout that I mentioned. You can block this out with a global variable, use a condition variable=0 to load in the JSON then set the variable to 1. This means it won't do it again.

  • hmm, thanks, I'll try that. But anyway I'm going to have to save this array when I exit the game, so would it be more productive if I always save in jason and reload in the array, or just at the end of the level save all changes in jason and then in local storage? But anyway I thank you, I think you already solved the question, thanks.

  • You would still keep what you have now for a brand new game to load the initial array, the variable I mentioned acts as tracking whether it's a new game or not.

    Then you create the load game logic separately. Whenever a player is going through a different flow of loading an existing game you load the local storage data instead of request the array file via ajax.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks a lot, you saved me. I'm going to use Local Storage on data missing to check if there are any saves, if not, I load them from the original json. Thank you very much, you helped me a lot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)