Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to programmatically insert table data into a grid widget

A topic by eli-oat created Dec 09, 2023 Views: 223 Replies: 3
Viewing posts 1 to 2
(+1)

Hey there! I'm working on a deck where I'm hoping to display input from a few previous cards in a grid on another. 

I've sorted out how to access and display data across cards, but am hung up on how to programmatically insert table data into a grid widget. 

I noticed that the syntax for insert has recently changed, so *think* I'm doing it the right way, but it isn't having the effect I'm expecting. 

insert name age hobby with
  "Alice" 23 "running" 
  "Bob" 25 "cooking" 
  "Charlie" 17 "birdwatching"
into roundup.widgets.player.value

In this example I'm not yet trying to insert data from other cards, just insert some static sample data into a grid widget on the current card.

The card is named "roundup," and the grid widget is named "player" -- that widget currently has an empty table with columns named "name," "age" and "hobby." When I run my code snippet at the listener, I see a table in the listener, but no data appears in the widget. When I run it in the script pane, wrapped in an "on view" no error is thrown, but nothing happens. 

Any guidance for how to do this? Thanks!

Developer (2 edits) (+2)

All of Lil's query forms (select, extract, update, insert) are pure expressions; they do not modify tables in-place.

If you want to update the table in a grid, you need to write to its ".value" property. Since you simply wish to replace the contents of the grid rather than append to it, you don't require an "into":

roundup.widgets.player.value:insert name age hobby with
   "Alice" 23 "running"
    "Bob" 25 "cooking"
    "Charlie" 17 "birdwatching"
end

If you're doing this at the Listener on the same card as the widget you could be more concise:

player.value:insert name age hobby with
    "Alice" 23 "running"
     "Bob" 25 "cooking"
     "Charlie" 17 "birdwatching"
end

If you then wanted to programmatically append more rows to the table, you could use "into" like so:

g:roundup.widgets.player
g.value:insert name age hobby with
   "Dinah" 19 "bouldering"
   "Evan" 47 "chicken wrangling"
into g.value

Does that help clear things up?

(+1)

Brilliant! Perfect! 100% what I was looking for! Thank you so much. 

Very helpful and could definitely deserve some more doc in the main Decker doc. The Lil examples are nice, but linking that to the Decker widgets is is not straightforward..