Remember state for a parcel while on the "Grid"

I am trying to save my parcel’s state while on the “Grid”.

I have a variable “down” that stores the state of an elevator (true for down, false for up). I want the “Grid” to remember it, so when other players spawn in, the elevator is configured correctly (if it was up, it loads in the up position).

Since the Grid is only a temporary instance, I can’t store a variable there. Fine. So I attempted to read the position of the elevator each time a new player spawns in.

Unfortunately, testing has revealed the Grid loads everything in its default position, then syncs as players explore together, so even if several players have positioned the elevator UP together, a new player will load it in the default down position.

I then decided to double down and make an express app on my own server (node js) and set the state there. When the elevator goes up, it uses fetch() to make a POST to my server to say it’s up. When the elevator goes down, it uses fetch() to make a POST to my server and says it’s down.

When the parcel loads, it it uses fetch() to make a GET request to my server and finds the position of the elevator and sets it. Perfect!

However, if the “Grid” is on, fetch stops working.

I then noticed on line 374 of https://github.com/cryptovoxels/scripting-bundle/blob/master/index.js that “fetch doesn’t work nicely on the grid. So we use ‘fetchJson’ when on scripthost, and fetch() when local”, so I pasted all of fetchJSON into my script and used that.

Still doesn’t work.

Am I trying to accomplish the impossible here?

I’ll admit after two days of experiments, it sure feels like it.

How to remember state on your parcel when combined with the Grid?

I think your approach is the best way to store the data. It’s the one I use.
And yeah. It looks as though this is a bug when using ‘fetchJson’ and also ‘fetch’.
Wrapping an api request in a try catch block will yield “Error thrown on message: join”

So I suppose for now I’ll just have to wait until Grid matures and I can either make requests to my server from it, or persist data on theirs. In the meantime, I’ll have to rope in my visions. :wink:

Heya,
Yeah at the moment the grid is extremely childish;

Thanks @karpatic.eth for the help;

Hopefully we can get a programmer to be fulltime on the scripting engine.
@nth-commit is also interested in changing the scripting-bundle to typescript so we can have auto-completion in the scripting editor.

Anyway, lots to work on

2 Likes