Skip to main content

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

struggling to decode base64 with image[] constructor

A topic by bublet created 36 days ago Views: 266 Replies: 2
Viewing posts 1 to 3
(1 edit) (+1)

I have a grid of data with three columns: tname; tdesc; and tmini. tmini contains encoded image strings. Despite my ability to display the image in the listener, I have trouble creating the image in the grid widget script. The decoded image appears blank. (The reason I'm encoding these images in the first place is to keep all the data organized in, and local to, the card.) Is there anything I'm missing that would prevent my script from decoding images, or is there something I can do better?

code:

on click row do
 piece_data: extract 
  tname:tname 
  tdesc:tdesc
  tmini:tmini
 from ((list(row)) take me.value)
 name_field.text: piece_data.tname
 desc_field.text: piece_data.tdesc
 minipic: image[piece_data.tmini]
 print["this is what i want:"]
 print[piece_data.tmini]
 print["re-encoded image"]
 print[minipic.encoded]
 big_minimap.clear[]
 big_minimap.paste[minipic]
 print["this is what i get:"]
 print[big_minimap.copy[].encoded]
end

output:

this is what i want:
%%IMG2ADAAMAD/AP8A/wBHAQEALgEDAC0BAQAvAQEAAQEBAC0BAQACAQEAKwEBAAYBAgAmAQMAAgEBAAIBAgAmAQEAAQEBAAMBAgABAQEAJgEBAAEBAQADAQIAAgEBACcBAQAEAQEAAgEBACcBAQAIAQEALwEBAC8BAQAwAQEA/wD/AP8ARQ== 
re-encoded image 
%%IMG2AAAAAA== 
this is what i get: 
%%IMG2ADAAMAD/AP8A/wD/AP8A/wD/AP8A/wAJ
(1 edit) (+2)

If I put show[piece_data.tmini] directly after the extract expression, it prints:

("%%IMG2ADAAMAD/AP8A/wBHAQEALgEDAC0BAQAvAQEAAQEBAC0BAQACAQEAKwEBAAYBAgAmAQMAAgEBAAIBAgAmAQEAAQEBAAMBAgABAQEAJgEBAAEBAQADAQIAAgEBACcBAQAEAQEAAgEBACcBAQAIAQEALwEBAC8BAQAwAQEA/wD/AP8ARQ==")

…which represents a list containing a single string (even though that’s not the syntax for creating a list containing a single string). Let’s call it imglist:

imglist:list "%%IMG2ADAAMAD/AP8A/wBHAQEALgEDAC0BAQAvAQEAAQEBAC0BAQACAQEAKwEBAAYBAgAmAQMAAgEBAAIBAgAmAQEAAQEBAAMBAgABAQEAJgEBAAEBAQADAQIAAgEBACcBAQAEAQEAAgEBACcBAQAIAQEALwEBAC8BAQAwAQEA/wD/AP8ARQ=="

Now print[imglist] will try to convert the list to a string, which works and produces the intended result (as you saw with your “this is what I want” message). However, image[imglist] wants its argument to be an x,y size, and only falls back to trying to interpret a string if it can’t do that. The argument it gets is a list, just not a list of two integers, so you wind up with an 0x0 image.

In general, you probably want to change the way you extract the row from the table:

 piece_data: first rows select
  tname:tname 
  tdesc:tdesc
  tmini:tmini
 where index=row
 from me.value

Now piece_data is a dictionary, as you expected, rather than a table.

In this specific instance, since this is the click handler of a grid, we can assume that the relevant row of the grid is already selected, and we can just say:

piece_data:me.rowvalue

And now the rest of your code should work as you expect.

Developer (1 edit) (+2)

Great explanation, Screwtapello!

In the general case, if you want a specific row of a table at a known index as a dictionary, I'd recommend skipping the query and instead using simple indexing. The following lines are both equivalent to your third example (assuming you just want every column with its original name and order):

piece_data: (rows me.value)[row]
piece_data: me.value[row]