import text file
-
How can I import a prepared text file (e.g. json format or simple comma separated values) into an array?
-
A dictionary seems like it would be a more suitable behavior to use instead of an array. What are you trying to accomplish? You can use the HTTP Request behavior if your JSON file is stored somewhere on the internet.
-
Since apple makes the ios file system difficult to access (until recently with the addition of the files app) you can't exactly import a text file.
However as suggested, you can have a file stored online somewhere and have you game import it with http requests.
@RobinsonX has done this quite a bit and may have an example on it.
-
@Lupo You can import any text into hyperPad into a behavior.
The Value behavior is a perfect way to store values, which you can plug it into any other behavior you wish to manipulate this value with. (You can copy and paste values in there)
If you want to use JSON, you can simply plug the JSON string into Modify Array / Modify Dictionary. In both of these behaviors, there's an option to set the array / dictionary so you can manipulate these data structures to its fullest. :)
-
If you have something other than JSON, say like a comma-seperated list, then you can use something like Text Operation to split a string and form an array.
-
@RobinsonX I have a few MB comma separated text file I would like to import into array or dictionary. I can put it into Dropbox and with a direct download link I could donwload it with HttpRequest.
Do you have an example of a GET HttpRequest and reading response and put into array/dictionary? -
@Lupo Currently, there's no way to import text as a file. The only ways are copying and pasting it (yes, it works for larger texts too that is in MB) or using something outside of hyperPad to store your text file and accessing that.
If you want to store your text file online, I recommend using something like Firebase by Google. You can store your text file there and then access it via URL without dealing with authentication or advanced API stuff.
-
@Lupo Here is an example using HTTP Request
-
@RobinsonX Thanks for the sample. But how are the values separated and stored in the array? By magic 😉 or do I need to parse the txt file (comma separated strings)?
-
@Lupo Oh yeah I forgot but you would use Text Operation if you're importing a comma-seperated string.
If you use the
split
feature in that behavior, then it will output an array that can be plugged into Modify Array to set the array.