Displaying a random picture from a CSV of URLs

Hello,

I have been having issues with creating a block of code that will display a random image based on a list of URLs.

For context, I am making a flag quiz, in which a country is randomly selected and the flag is displayed. To do this, i have set up two .csv files, one containing names, and one containing flag URLs. I have also created an "index" variable that is assigned a number to use as the index for the lists made from the .csv files.

How do I call these .csv files and present the contents as strings of text so they can be the source of an image or as the text on a button?

Your two files aren't really CSV files, because they lack commas.

They are just lists separated by line feeds (\n).

Normally, associated data like country names and flags are kept on the same line, separated by a comma (,).

Since you already have a (hopefully) matched pair of one dimensional lists of country names and flag URLs, it is easier to deal with their text as \n delimited text.

You already are reading the files in two separate File components, for which you need two separate .GotText event blocks, one per component.

You read nameslist.csv in File1, so its .GotText should:

  • split text at \n into global namelist

You read flaglist.csv in File2, so its .GotText should:

  • split text at \n into global flaglist

(I would have renamed the two File components to mention what they are reading, names or flags, to avoid confusion.)

(I advise renaming global variable to include mention that they are lists.)

Setting the index to a random number should be done in a Button Click event, followed by using it to get the associated names and flags for display.

P.S. If this doesn't work, export everything and post it all here.

See here:

You can simply use the json file provided in your app, and display flags in labels, you do not need an extension.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.