Some Noob questions

Hi!

I have a number of questions, that I hope you can answer :slight_smile:

• I need to load text from the README.md, or any file in the MakeCode Arcade’s Explorer, but I can’t seem to find the right feature.(And I don’t know how to use settings.readString(key: string))

• I am producing a sort of RPG game, kind of like Pokemon, and I need sprite collision. -Meaning, when the player overlaps another sprite, it will just keep the player in the same position until the player walks away, or into another direction.

• I need to send data to another player when a connection is successfully established; e.g. if the players decide to trade $5 and x1 Water Bottle, then it should send over the items, and remove the correct items / cash from the players’ inventory.

Any help is highly, highly appreciated :smile:

1 Like
  • settings.readString stores the string in the devices flash memory; this will let you save the data to the device. here’s a quick example of using it to store a message for future players (like you would save data, so that you could save the data as the player progresses, and try to read it whenever they reset the device): https://makecode.com/_3uF6WxXu9VX7

2019-12-24 00.09.39

  • You could handle it with overlaps, it might be a bit tricky though - you would probably end up wanting to figure out which direction the player is coming from (based off their velocities), and reset the position to be opposite that direction when they hit one of the sprites - e.g. if the player is moving right and they overlap an enemy, set the player’s .right position to the enemies .left position: https://makecode.com/_15bRj9cL5crA

other potential approaches:

  • make the other ‘sprites’ walls if they aren’t moving, and let the physics take of them / handle the collections with wall collision handlers.
  • the tileworld extension handles things like this nicely by aligning sprites to the grid, but I’m not sure if the current state is fully stable / if there is any documentation (@tballmsft). Also, the extension linked in that post is a bit older; now located here

(re: hardware multiplayer, I haven’t personally interacted used it / made any multiplayer games on hardware yet, and there will likely be more iterations before that part of the codebase is fully stable)

1 Like

Joey, this is extremely helpful. But I have a question… Can I save multiple strings, without them overlapping each other?

I want to save name and score, not only one string.(Would be pointless :sweat_smile:) Any ideas on this? Thanks :grin:

1 Like

Yes - the ‘key’ is like a file name in this case, so if you need to store a name and a score you could use two keys - “mySavedName” and “mySavedScore” - and then it will store the two values separately, and you can read them using those keys. (Going of the example above, just make unique names for each thing you need to save / read, and use each of them like I did myKey)

Just a note, if you store too much at once and it runs out of memory, the current behavior is that you will get a crash with a 920 error, and the data will be wiped on the next load.

1 Like

:slight_smile: Joey, you are AMAZING! Thanks! :grin:

1 Like

wait, you can save info on the arcade, like turn it off and back on and have the same game, like a save, or am i miss reading this?

1 Like

Yes, use the “settings” extension. Click Advanced -> Extensions -> settings.

1 Like

its not there

1 Like

@peli, do we have a blocks extension for the settings? I don’t see it either. The APIs are available in JavaScript without any additional packages

1 Like

Oh snap we probably don’t. We also don’t have blocks to store data into the sprite data object which is very annoying. We need an create an extension for this.

1 Like

Oh! Yes! My son was working on his own “Galga” and was making different kinds of enemies. He wanted the bigger ones to take two hits, but I didn’t have any good suggestions for how to track their health.

He decided to just spawn a maximum of one per screen, which worked… but it’d be excellent to have support for sprite-scoped data.

1 Like

I’ll spin an extension for the sprite data.

4 Likes

Here is an extension with blocks to store data in sprites: https://github.com/pelikhan/sprite-data

2 Likes

Thanks! Looks really useful. Looks like there’s one small problem with the comment above readDataAsString. I created an issue: https://github.com/pelikhan/sprite-data/issues/1

1 Like

@Blobiy I just created a settings extension for saving game data. Check it out here

1 Like