Stencyl 3.4.0 is now out. Get it now!

External Data Extension [2.0.0]

ETHproductions

  • *
  • Posts: 415
Hi @giordano,

I think this might be possible, but it'd be very tricky to get this to work cross-platform, and there might be permission issues involved. On Android, it'd probably be possible to save to the user's Images folder, and on Windows it should be possible to save to the user's AppData folder. No clue about other platforms though.
Fontstruct - Stencyl - Website (in progress)

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

wsscinterns17

  • *
  • Posts: 3
I'm having issues with playing a flash file i keep getting an error. Is there a certain way that i need to implement it so that it will work correctly.

The error message is:

 ArgumentError: Error #2100: The ByteArray parameter in Loader.loadBytes() must have length greater than 0.
   at flash.display::Loader/_loadBytes()
   at flash.display::Loader/loadBytes()
   at PlaySWF$/playAVM1()[C:\Users\pmcnair\AppData\Roaming\Stencyl\stencylworks\engine-extensions/External Data/PlaySWF.hx:73]
   at scripts::SceneEvents_17/init()[Source/scripts/SceneEvents_17.hx:87]
   at com.stencyl.behavior::Behavior/initScript()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/behavior/Behavior.hx:97]
   at com.stencyl.behavior::BehaviorManager/initScripts()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/behavior/BehaviorManager.hx:105]
   at com.stencyl::Engine$/initBehaviors()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:1113]
   at com.stencyl::Engine/loadScene()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:984]
   at com.stencyl::Engine/begin()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:805]
   at com.stencyl::Engine()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:539]
   at Universal/init()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/Universal.hx:95]
   at Universal/onAdded()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/Universal.hx:74]
   at flash.display::DisplayObjectContainer/addChild()
   at Universal$/main()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/Universal.hx:553]
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at Function/<anonymous>()
   at ApplicationMain$/start()[Export/flash/haxe/ApplicationMain.hx:1561]
   at ApplicationMain$/init()[Export/flash/haxe/ApplicationMain.hx:1479]
   at lime.app::Event_Void_Void/dispatch()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/lime/lime/lime/app/Event.hx:145]
   at lime.app::Preloader/start()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/lime/lime/lime/app/Preloader.hx:242]
   at openfl.display::Preloader/display_onComplete()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/openfl/openfl/openfl/display/Preloader.hx:129]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at scripts::StencylPreloader/onLoaded()[Source/scripts/StencylPreloader.hx:314]
   at openfl.display::Preloader/start()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/openfl/openfl/openfl/display/Preloader.hx:93]
   at lime.app::Preloader/current_onEnter()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/lime/lime/lime/app/Preloader.hx:310]/

« Last Edit: September 28, 2017, 07:54:43 am by wsscinterns17 »

ETHproductions

  • *
  • Posts: 415
Hi @wsscinterns17,

I believe the problem is that the .swf file needs to be located in your game's "extras" folder. To do this:

1. With your game open, go to Debug > View > View Folder for this Game.
2. Open the highlighted folder.
3. If there is no "extras" subfolder within this folder, create a new folder named extras.
4. Open the extras folder and place preloader.swf there.

If you've already done this and it's still not working, please let me know and I can take a closer look.
Fontstruct - Stencyl - Website (in progress)

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

wsscinterns17

  • *
  • Posts: 3
Yeah I already had an extras folder from using the dialogue and data strcutures extension. The flash file is also present, so i am unsure of where the error is coming from.

Thanks for you're help it is really appreciated

Hi @wsscinterns17,

I believe the problem is that the .swf file needs to be located in your game's "extras" folder. To do this:

1. With your game open, go to Debug > View > View Folder for this Game.
2. Open the highlighted folder.
3. If there is no "extras" subfolder within this folder, create a new folder named extras.
4. Open the extras folder and place preloader.swf there.

If you've already done this and it's still not working, please let me know and I can take a closer look.

giordano

  • Posts: 76
Hi @giordano,

I think this might be possible, but it'd be very tricky to get this to work cross-platform, and there might be permission issues involved. On Android, it'd probably be possible to save to the user's Images folder, and on Windows it should be possible to save to the user's AppData folder. No clue about other platforms though.
I would like to do this in android, if possible

hodragon

  • *
  • Posts: 61
I get the following error when compiling.
This seems to be a problem when upgrading the OpenFl version from Stencyl 3.5 Beta.


[haxelib] /Users/hodragon/stencylworks/engine-extensions/External Data/FileSave.hx:83: characters 11-39 : Class<openfl.display.BitmapData> has no field loadFromHaxeBytes (Suggestion: loadFromBytes)

[haxelib] /Users/hodragon/stencylworks/engine-extensions/External Data/FileSave.hx:163: characters 33-38 : String should be openfl.geom.Rectangle

[haxelib] /Users/hodragon/stencylworks/engine-extensions/External Data/FileSave.hx:163: characters 33-38 : For function argument 'rect'
Indie Game Developer.

ETHproductions,

First of all, I love your extension, it's amazing. I was just wondering if you could tell me what some things I'm messing around with would do.

If I were to comment out all the file = "assets/data/" + file; and path = "/assets/data/" + path; lines in the DataUtils.hx and FileSave.hx files, would that let me save/load things anywhere in the project folder? For example, loading an image from "Saved Images/Face.png" instead of "assets/data/Saved Images/Face.png" or savinga text document to "Exported Player Data/Ali.txt" instead of "assets/data/Exported Player Data/Ali.txt".

Also, line 147 of FileSave.hx is if (path.substr(path.length - 4).toLowerCase() != ".png") { path += ".png"; }. If I commented that out, would I be able to save images in other formats such as .jpg? And if I could, what would be the limitations of this?

If you would be able to answer these questions, I would most appreciate it.


Thank you,
Annulus

yoplalala

  • *
  • Posts: 1430
I'm not ETH production.
But yes and no.
For the text laoding and saving.
If you see openfl.Assets.getText(). The files have to be compiled and already included in the assets
If you see File.getContent. It looks directly in the path

In flash && html5 you (usually) cannot access the files on the drive, you can only use openfl.Assets

Conclusion : FileSave.getText can read data in other folders.  DataUtils.getTextData  cannot.


Which format do you want  ?

As you can see the code  var b:ByteArray = image.encode("png", 1);
you can replace by "jpg". Which other formats you are interested in ? I think other formats are not included by default.

« Last Edit: October 15, 2017, 01:30:28 am by yoplalala »

I can see now that my programming experience is severely lacking: I have a lot to learn!  :P

Basically, I'm compiling to Windows, and... OK nevermind, I don't know the terminology. If I compile to Windows and I choose where I want to game saved, then Stencyl opens up file explorer where I chose? That's the folder I'm trying to be able to access with the external data stuff.  Say I made a 2D Minecraft game and saved it to my desktop, now my desktop has the folder "Paper-Minecraft" or something.

If the player (me in this case) took a screen-shot, it would be saved somewhere under C:\Users\com-user0\Desktop\Paper-Minecraft\assets\data\{whatever else}. What I'm instead trying to do is have the starting point for where saves go to be in that initial folder where Paper-Minecraft.exe, so I can instead save screenshots to C:\Users\com-user0\Desktop\Paper-Minecraft\Screenshots\{image}. I wasn't really planning on trying to save anywhere outside of the games folder.

The other thing I'm trying to do is allow the user of my program to switch between saving screenshots as .png or .jpg. Those are the only two formats I think would be useful. I thought that by commenting out the if (path.substr(path.length - 4).toLowerCase() != ".png") { path += ".png"; } bit I could instead make the extension either .png or .jpg when using the block. So I can write Screenshots\Image.png or Screenshots\Image.jpg into the text field based on what the user wants to save the image as.

Hopefully that clears things up a bit. I haven't actually made a Paper Minecraft game, this was just an example, but I have attached some images to try and get my point across a bit better.


Thank you,
Annulus

yoplalala

  • *
  • Posts: 1430
Quote
If the player (me in this case) took a screen-shot, it would be saved somewhere under C:\Users\com-user0\Desktop\Paper-Minecraft\assets\data\{whatever else}. What I'm instead trying to do is have the starting point for where saves go to be in that initial folder where Paper-Minecraft.exe, so I can instead save screenshots to C:\Users\com-user0\Desktop\Paper-Minecraft\Screenshots\{image}. I wasn't really planning on trying to save anywhere outside of the games folder.
No problem you can remove "assets\data\". I think "assets\data\" was put by default in the extension because  everythings you put in the folder "extras" in your game folder will find it there.

You can even create your own folders in Window  http://api.openfl.org/sys/FileSystem.html. You do sys.FileSystem.createDirectory("Screenshots"); which create your folder in your game folder

Quote
The other thing I'm trying to do is allow the user of my program to switch between saving screenshots as .png or .jpg. Those are the only two formats I think would be useful. I thought that by commenting out the if (path.substr(path.length - 4).toLowerCase() != ".png") { path += ".png"; } bit I could instead make the extension either .png or .jpg when using the block. So I can write Screenshots\Image.png or Screenshots\Image.jpg into the text field based on what the user wants to save the image as.

The extension would have changed but the file format would be the same.
Like when you rename test.txt into text.exe, it doesn't it make it a program.

You can modify the code fo avePNG. You can replace the "png",  by type.
Then you modify a  block and add a dropdown where you can choose between "png" or "jpg"  :)
Code: [Select]
public static function saveImage(path:String, type:String, image:BitmapData, ?whenDone:Bool->Void):Void {
if (path.substr(path.length - 4).toLowerCase() != "."+type) { path += "."+ type; }

// Flash: Not possible to save; error out
#if flash
trace("ERROR: File IO cannot be accessed on Flash.");
if (whenDone != null)
whenDone(false);
#elseif js
trace("ERROR: File IO cannot be accessed on Html5");
if (whenDone != null)
whenDone(false);

// Windows, Mac, Linux, iOS, and Android: Use the "saveText" function with the converted file
#else
var b:ByteArray = image.encode(type, 1);
saveText(path, b.toString(), whenDone);
#end
}

Thank you so much, I'll give this all a go.

gplar

  • *
  • Posts: 1117
@ETHproductions.
Could you take a look at this?
http://community.stencyl.com/index.php/topic,54864.msg292508.html#msg292508
It worked like a charm up to 3.5.  :-)

ETHproductions

  • *
  • Posts: 415
The extension has been fully upgraded for Stencyl 3.4 and 3.5. You can download the latest version here. Please let me know if you experience any problems!

So for the next steps:

- Loading and saving files outside of the extras folder
- Loading and saving files outside of the project folder altogether (maybe add blocks to reference various directories)
- Loading and saving various types of data (e.g. lists, maps, maybe even more complicated ones like Actors) in safe formats
- Perhaps a "save as" dialog window? (see lime.ui.FileDialog)
- I'm not sure why I'm using userDirectory instead of applicationStorageDirectory for mobile... double-check to make sure it's working properly

Any other suggestions? (Perhaps I missed a few that have already been posted?)
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: 2488
This is one of the most useful extensions I have seen, and the next steps sound very promising.
As always, excellent work and excellent ideas.

Thank you very much, @ETHproductions
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

wsscinterns17

  • *
  • Posts: 3
I have a few questions about the new extension.

1.) Will this only work if i publish the game as a flash and not to IOS?
2.) can someone give a walk thru on how to set up the video player for flash, when i do i get an error message or nothing plays. I've been messing around with it for awhile now with no luck.

All help is appreciated thanks!