Multiple-step Saving Process? (Or updating an existing entry?)

Hello world.

As mentioned elsewhere, one of my projects is an RPG. I’m trying to make a flow that allows users to create their own characters. I set up a page with multiple states to keep things tidy, overall. There’s a data slot to transition between those states, ds_CharacterCreationFlow. State 0 is the starting point, and each button increases its value to move the screen to the next state. That part’s working just fine.

The first screen asks the user to enter their character’s “First Name” and “Full Name.” The button then assigns the names to the “characters” data sheet, along with their email address, which we use to filter characters:

So far, this is working just fine. The user has created a new character, even if all we have down is their name(s).

The button on that screen also changes the DS value to 1, moving us to the next page, where the user selects an “Age” which also assigns some other game traits:

The problem here is that this ends up saving as a separate character entry, instead of saving inside the existing character entry:

I assume this has something to do with the way I’ve got the Component’s interactions set up. If I tell it to either “Add” or “Auto,” it creates the above, separate entry. If I set it to “Update,” it seems to demand access to a field it sees as undefined:

I’ve also tried to set this up to use a queried data sheet, too, but that didn’t get anywhere. Please advise. Thanks.

You have to write data to the “correct” row / document.

The quickest way I know of is to access “this.props.dataSheetRow.XYZ” in a script.

In this case, it would be “this.props.dataSheetRow.AgeName”

So something like attach a script to each “age” button. When Neonate is clicked, the script has:

this.props.dataSheetRow.AgeName = ‘Neonate’;

You can play around with this by attaching a script in various spots and console.log(this.props.dataSheetRow.XYZ); to see for yourself.

The only thing is I’m not sure if a button allows you to attach such a script. I find some idiosyncrasies around what kind of script can be associated with which components. Eg. some components has no DB access regardless of what’s in the script. I believe it has to do with which part of the js file the component goes under.

The other ways are:

  1. Actually locating a database row / document, then update a field. It’s much more involved, but you’re actually querying the database at that point and you can do whatever you want with it.
  1. Load a single FIrestore document into a datasheet. This was in an example project, but for the life of me I was not able to get it to work.

BTW, in the previous post, I mentioned use console.log to play with it. You would need to turn on the “developer tools” in web browser to see the console printout messages.

1 Like