Editing a Table Using Blocks
CreatiCode last edited by info-creaticode
You can easily edit a table using blocks, such as adding new rows, removing some rows, or changing the value of some items.
The “add to table” block appends a new row at the bottom of a table, then set the values of some or all of the items. It can take up to 12 values, so you can at most set the values of the first 12 items in the new row using this block.
Note that the order of the values has to match the column order in the table. Blank input boxes will be ignored.
You can also insert a new row at a particular row number. The existing rows will be pushed down to make room for this new row. You can specify at most the first 12 items in this new row:
You can replace all items in a row using the block below if you know its row number. Other rows will not be affected.
Sometimes you only need to change one item, and keep the other items in the row unchanged. If you know that item’s row number and column name, then you can change its value using this block:
Note that for the second input, you have to specify the column name (e.g. “age”), not the column index (e.g. 2). This is a very common mistake.
For some use cases, you only want to change an item relatively based on its current value. For example, if someone’s birthday has just passed, you might want to increase his age by 1. Similarly, if someone has lost a game, you can reduce his points by some number. The following 2 blocks can be used to change or reduce an item’s value:
If you know the row number of any row you would like to delete, you can use the following block to delete that row. The rows below will move up by one row to fill in the gap.
You can also clear the table and delete all rows. The column structure will not change:
Sometimes we only want to delete all rows in the table with a specific value in a specific column. You can use the following block to specify the column and the value to look for in that column.
You can also insert a new empty column into a table. You need to specify the name and position of this new column. The existing columns at that position and after will all be pushed to the right by one column.
Note that this is an uncommon operation, since normally a table’s structure is fixed, and we just change its rows or items.
You can also remove an entire column from a table by specifying the column name, and the letter case of the name does not matter.
If you need to redefine a table, you can delete all its columns, then add new columns to it from scratch.
You can use the following 2 blocks to show or hide the table on the stage: