External Data Extension [2.0.0]

ETHproductions

  • *
  • Posts: 430
External Data Extension

Recently I've been working on an extension that's able to get files from the 'extras' folder, such as described in this topic. It's gone quite well; I even managed to add in a saving feature.

Features:
  • Get text from a file
  • Modify that text
  • Get a sound from a file
  • Play an .swf file (on Flash)
  • Save text files and .png images (on Desktop or Mobile)

All except the saving blocks work correctly on Flash; should be the same with HTML5. All except the SWF blocks work on Windows and Android, and it should be the same on everything else. (If you can test it on Mac, Linux, or iOS, please tell me how it works!)

Designed to work with Stencyl v3.4+. Some blocks may not work in older versions.

Download for 3.4+

(How to Install and Update an Extension)
(Legacy downloads: 3.1, 3.2, 3.3. Please note that these are no longer being maintained.)
(View on GitHub)

If upgrading from the 3.3 version of the extension:
1. Install the extension as usual. Note that it will not overwrite the 3.3 version, resulting in two versions of the extension in your folder.
2. For each game you want to upgrade:
  a. Open the game.
  b. In the Extensions settings, disable the "External Data 3.3" extension and enable the "External Data" extension.
  c. Save and close the game. DO NOT open any resources before closing.
  d. Reopen the game. It should now have successfully upgraded.

Instructions

1. Download, install and enable the extension (link above).
2. Inside your game, press Debug > View > View Folder for this Game, then open up the highlighted folder.
3. Create a new folder and name it extras.
4. Place any necessary files inside this folder.
5. Use the blocks to get data from the files.

Using File Paths

File extensions work like this:
- For the text from file, save text, append line, and image from file blocks, you must use the correct file extension (e.g. .txt, .png, etc.)
- For the sound from file block, you must not use a file extension. (The extension chooses .mp3 or .ogg automatically, depending on the platform.)
- For the swf and save image blocks, it doesn't matter.
- Any subfolders in the path (after extras) must be included.

Examples:

.../extras/test.txt should be put into the text block as test.txt
.../extras/subfolder/test.txt should be put into into the text block as subfolder/test.txt
.../extras/preloader.swf can be put into into either swf block as preloader.swf, or just preloader
.../extras/image.png can be put into into the save image block as image.png, or just image
.../extras/sfx/jump1.mp3 and .../extras/sfx/jump1.ogg should both be put into the sound block as sfx/jump1

For future versions I plan to add the ability to manipulate files outside of the extras folder (perhaps outside of the game folder itself), but I have yet to determine how to implement this block-wise.

Blocks



Returns the text from the inputted file. If it has multiple lines in it, it may need to be processed with the following block.




Splits the text into a list by putting each line of the file into a new item.




The inputted text will have line breaks added wherever there is a \r in the text. For example, Hello\rWorld! will result in:
Hello
World!




Replaces each of the line breaks in the text with \r. Useful for debugging purposes.




Removes any line breaks from the text.




Adds a new line of text to the text attribute.




Adds a line of text to the end of the file. Useful for generating logs. Doesn't work on Flash or HTML5.




Returns the text with preserved Unicode characters. This is a workaround of Stencyl's automatic Unicode-to-code-point conversion, which results in glyphs outside the ASCII range encoding safely, but incorrectly.




Returns the line break character.




Draws a list onto the screen, item by item. The top left of the box it draws in is at the inputted x and y.




Prints a list out to the console, item by item.




Gets a sound from a .mp3 or .ogg file, depending on the platform. This block can be used just like any other sound block.





Plays an .swf file. Only works on Flash. If you notice that it isn't playing in the correct position, or for the correct length of time, try using the other block.

NOTE: The first of these two blocks has been tested to the fullest of my ability, but I cannot confirm that it works perfectly. If you can use it with a newer SWF, please tell me how it works!




Saves a text file to the extras folder.  Doesn't work on Flash or HTML5.




Saves an image (as a .png or a .jpg/.jpeg) to the extras folder. Doesn't work on Flash or HTML5.

Version History
Code: [Select]
2.0.0 (10/24/17)
- Updated for 3.4+
- Added "save as PNG/JPEG" block

1.6.1 (11/19/15)
Added beta HTML5 support

1.6 (08/27/15)
Added blocks:
- append line ___ to file: ___
- unicode text: ___

1.5.1 (07/14/15)
Bug fix: Missing subfolders are not taken into account when saving

1.5 (07/13/15)
Images that were saved after compilation can now be accessed
Added block: image from file (already existed in the palette, but had to be recoded to use a custom function)

1.4 (07/09/15)
Actually fixed the bug with saving and loading data on mobile
- Added in one missing slash

1.3.1 (06/06/15)
(Hopefully!) Fixed a bug with saving and loading data on mobile

1.3 (06/05/15)
Should now save data on mobile targets (NEEDS TESTING!)

1.2.2 (05/09/15)
Changed "text without line breaks" to "replace line break with \r in text"
Changed "text with added line breaks" to "replace \r with line break in text"
Added block: remove line breaks from text

1.2.1 (03/09/15)
Bug fix: Trying to retrieve non-existing file on Flash causes a null error

1.2 (03/08/15)
Added blocks:
- add line: _____ to ___
- save data ___ to file: ___
- save PNG ___ to file: ___

1.1 (03/05/15)
Added blocks:
- text with added line breaks
- text without line breaks
- print list

1.0.1 (03/03/15)
Added block:
- line break

1.0 - Initial public release (02/04/15)
Blocks:
- get text from file
- split text into lines
- draw list
- get sound from file
- play SWF/AVM1

If you have any questions, comments, or suggestions, feel free to post them below! :)
ETH

« Last Edit: August 05, 2022, 09:06:32 am by Luyren »
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

captaincomic

  • *
  • Posts: 6108
It looks like "src" is set in play/loop only for "streaming" sounds. Sounds with "streaming == false" load the source in loadGraphics()  called by new(). So you can try it like this (pseude-code):

Code: [Select]
var s:Sound = new Sound(..., ..., true, ..., ..., ..., ...); //third paramter streaming == true, to prevent src being set here
s.streaming = false; //set streaming to false, to prevent src being set in play/loop
s.src = <your nme.media.Sound object>

ETHproductions

  • *
  • Posts: 430
That works perfectly! Thanks for your help. :)
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Jon

  • *
  • Posts: 17524
This contains some references to nme that will need to be updated to openfl for this extension to function in 3.3 and above. Please update. Thanks!

ETHproductions

  • *
  • Posts: 430
Yessir, I'll get on it right away!

EDIT: Done! I've also upgraded the top post to a real extension post.

« Last Edit: February 04, 2015, 02:21:45 pm by ETHproductions »
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Mineat

  • Posts: 376
[Mod edit: This post was originally in reference to the Attribute Saving extension.]

Hey, I like your extension, but can you make it so that you can do the same thing with text files? I'm working on a learning category maker program using this and the External Data extension. The result would help everyone, including me.

« Last Edit: March 07, 2015, 08:24:08 pm by Justin »

ETHproductions

  • *
  • Posts: 430
Hey, I like your extension, but can you make it so that you can do the same thing with text files? I'm working on a learning category maker program using this and the External Data extension. The result would help everyone, including me.

I've recently been experimenting with some Haxe code that allows reading, writing, saving and renaming any file inside the game's folder. I'm planning to add it into the External Data extension after I simplify it some. However, it only works on Desktop and Mobile (I believe).

If you need to do this for a Flash game, there is a workaround: you can use the extensions together to achieve the same basic concept. You could retrieve a full, pre-created text file (using External Data), then save it as a text attribute (with Attribute Saving). You can also edit the text and save it again as needed.

P.S. Have you had any difficulties in using the External Data extension? I'd love some feedback.... :)
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

LIBERADO

  • *
  • Posts: 2720
I've recently been experimenting with some Haxe code that allows reading, writing, saving and renaming any file inside the game's folder. I'm planning to add it into the External Data extension after I simplify it some. However, it only works on Desktop and Mobile (I believe).
Even save images? That would be super interesting!
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

Mineat

  • Posts: 376
Hey, I like your extension, but can you make it so that you can do the same thing with text files? I'm working on a learning category maker program using this and the External Data extension. The result would help everyone, including me.

I've recently been experimenting with some Haxe code that allows reading, writing, saving and renaming any file inside the game's folder. I'm planning to add it into the External Data extension after I simplify it some. However, it only works on Desktop and Mobile (I believe).

If you need to do this for a Flash game, there is a workaround: you can use the extensions together to achieve the same basic concept. You could retrieve a full, pre-created text file (using External Data), then save it as a text attribute (with Attribute Saving). You can also edit the text and save it again as needed.

P.S. Have you had any difficulties in using the External Data extension? I'd love some feedback.... :)

@ETH(Off-topic a little): I can't get a hold of accessing the line breaks in the text files I'm using. In 3.2, I want to split text with the blocks you provided, but I can't get the palette combination right for making the Lists when making a new attribute.

I've recently been experimenting with some Haxe code that allows reading, writing, saving and renaming any file inside the game's folder. I'm planning to add it into the External Data extension after I simplify it some. However, it only works on Desktop and Mobile (I believe).
Even save images? That would be super interesting!

@LIBERADO: I think it would require a lot of time, but okay!  :)

ETHproductions

  • *
  • Posts: 430
@Mineat: I've changed the 'get text from file' block quite a bit, and it should be way easier to use the returned text now. Could you please try the latest version, and post the result on the External Data thread?

@LIBERADO: That would be awesome! I believe it's possible, at least with .bmp bitmap files. I'll post the results once I have more time to mess around with it.
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Mineat

  • Posts: 376
Almost done. Once the file name is retrieved by typing it it in, testing will be a snap.

ETHproductions

  • *
  • Posts: 430
@LIBERADO: I figured out how to save a .png in the extras folder! Unfortunately, if there isn't an image with the same name inside the folder to begin with, the 'get image from file' block won't recognize the saved image. I'll post with the rest of the extension once the rest of the saving blocks are ready.

Once the file name is retrieved by typing it it in...

@Mineat: Could I inquire what you mean by this? I don't quite understand....
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Mineat

  • Posts: 376
I coded the main part of the program but, the program exited with, "Line 153: #AttributeSaving has no saveData." Here it is.

LIBERADO

  • *
  • Posts: 2720
@LIBERADO: I figured out how to save a .png in the extras folder! Unfortunately, if there isn't an image with the same name inside the folder to begin with, the 'get image from file' block won't recognize the saved image.
Even with this minor inconvenience, I think it worth adding this interesting feature, it is still very useful in many cases. For example, I am making a Desktop game in which I need to save .png images (screenshots) in the extras folder but I don't need to use the "get image from file" to load the images after saving them. I just want to store multiple images and screenshots within the "extras" folder for use them later outside the game.

Could you include this feature without the option of recognize the saved images?

« Last Edit: March 06, 2015, 10:47:45 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

Justin

  • *
  • Posts: 4716
If you don't need to use them later in the game, it would probably be better to save them in a different place. Perhaps a set of blocks should be put together for file IO.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)