Can a custom state store a table or array? is a custom state better than a database thing?

I’m used to being able to create multi-dimensional variables. Two questions:

  1. can a custom state store anything more complicated than a list?
  2. is there an advantage to storing multi-dimensional information in a set of custom variables vs in a database thing?

So a custom state can obviously store a single value, as in custom_state = X

It can also store a list, as in custom_state =
X
Y
Z

Can it store a set of related lists? as in custom_state =
1 / A / B / C
2 / X / Y / Z

A use case example is that I want to let the user build something out of a list of pieces I provide. I figured I could store the piece and its position relative to the canvas in a list in a custom state as the user works. something like custom_state =
ID 123456 / X 15 / Y 38
ID 789102 / X 3 / Y 90
ID 749374 / X 45 / Y 27

It doesn’t seem like custom states have any tools for parsing data like that back out anyway.

1 Like

The data structure that matches what you are after is “list of things”, but does reference database storage.

One workaround is to have parallel lists, i.e. a separate custom state for each “column” in your “array”:
ID: 123456, 789102, 749374
X: 15, 3, 45
Y: 38, 90, 27

Then refer to the same item number in each list for each value. Creating an entry would require three workflow actions, redefining each custom state by the previous list :plus a new value.

1 Like

Right, that’s why I asked question (2).

The only way to add that structure to custom states is to define them as your own data type.

But to do that you need to store it somewhere, so you way as well store it on the database anyway.

I would suggest having multiple lists and trying to do operations based on index numbers is going to quickly get very tedious. Far better to store temporary data on the User, that way you have all the structure you need.

1 Like

@NigelG It’s to slow for me to update a Thing (aka the database). So thinking of States, but as you say updating multiple list is not good. You say, use the User. But doesn’t that as any Thing update update the database, leading to the same slowness?

@philledille have you figured this out?

Check this:

OMG what a clever workaround, now I just need to figure out how to use regex hehe. Basically I need to create a 7 day calendar with half hour slots, thats 48 columns and 7 rows for the upcoming week(336 cells). Each cell can be one of 3 states, free, booked or available. So I guess I could use just a string of 336 characters with a numeric value: 1,2,3 depending on the state.

K so now to find out how regex works hehe.

Thanks so much, mind if i hassle you later when i run into probs?

You’re Regex string seems smartly simple!

Feel free to post any questions - though I’m not a Regex expert, just someone who likes finding work arounds :slight_smile:

Hi @philledille so im not really sure how to set about this. I understood that you have 3 letters representing the 3 different states, so a, b or c depending on if its available, booked or unavailable.

Basically I want to create this 7 day calendar which allows you to edit your availability. How would you set about this. Onpageload i set up a custom state of the page with a string which is 336 characters long and starts out as aaaaaaaaaaaaaaa, etc. Then I´ve created a RG with 7 rows and 48 columns with a shape in each one which i will use to conditionally change colour based on the cell´s value. I extract the initial data Using REGEX with a . to extract individual characters. But where do i store this data and how do i change the string when a user clicks on the shape in any cell in the RG?

And then once set up, how do I cycle through the string character by character to save the state back to the database?

You don’t need to store the data in the RG/cell. You can use a Regex expression in the conditional tab of an element.

You change the string using “find & replace” and use Regex expression in there.

No. Store the string in the database(!), not as separate things. Much faster and no moving of data from thing to string and back. To be able to do this you need 336 dummy things to build up the RG.

By 336 dummy things you mean 336 data fields?

No, things. They don’t even have to have data fields since it’s a dummy thing used only to populate the RG.

:frowning: Im so lost, any chance you could make an example @philledille? Would really appreciate it

1 Like

OKKK finally managed to get something.

So Im using REGEX and strings to define availability. I want to show 7 days in half hour slots.

How Im trying to do it is create only 48 slots (per day) in a RG which is repeated 7 times vertically in a RG (days) . I cant seem to implement it because the Child Repeatinggroup cant have a state (it seems). So I setup the 7 strings for the 7 days in separate states and conditionally set the datasource for the child repeating group to the correct datasource depending on the cellindex of the parent (1,2,3,4,5,6,7). However when it comes to editing i now have a problem because when i click on a cell in the child RG, it cannot determine the cellindex of the parent :confused:

I need to know this to be able to know which string i need to replace. Any ideas?

Thanks so much.

@copilot, I have a session booked with you Salar on Tuesday so it´d be great if you could give this prob a look, if you have any tips or a fix so we can discuss other stuff in our session. Much appreciated.

1 Like

We’d be glad to help any way we can. :wink:

How would you set about this example? Is the entire process I´m using flawed or is there a way to make this work? @copilot

Can you share a link to editor?

The best solution for this is to add a group in the parent cell, set its data source as the cell’s data. Then you can refer to the group’s thing in the child RG. The new group doesn’t have to include anything in it.