External Data Extension [2.0.0]

Jo3m

  • Posts: 13
Hello, I'm confused. I'm trying to use the "save data" block. I want to save the contents of a previously defined value to a "test.txt" file and it does not work. I work under Windows 10 as administrator with all file write permissions. Of course, I created the directory "extras", but nothing to do, it does not work.

The block is used not in the main loop, but in an "actor" object. For the moment, I do not have an answer to this problem.

I tell you what I'm trying to do because maybe I'm not using the right method. I created a parser able to read xml format and naturally, I would like to save the result in a file. Maybe there is another method than this extension to save xml data, for now I'm doing just that.

Thanks for reading me.


« Last Edit: February 01, 2018, 08:53:27 am by Jo3m »

yoplalala

  • *
  • Posts: 1467
- put a print in the save data.  Do you see it in the logs ?
(Met un print à l'intérieur du bloc save data et check si tu le vois qui s'imprime dans le log)
- create you text.txt in the files extras and check it has been modified
( Créé le fichier text.txt dans le dossier extras que tu as crée et vérifie s'il a été modifié)

Jo3m

  • Posts: 13
Yes, do it but don't work !
Merci de me répondre en français.
J'ai bien réalisé ce test et dans le log pas de souci, c'est "Sauvegarde réussie" qui apparait lorsque j'effectue cette action. Par contre, dans le répertoire "extras", rien... J'ai créé un fichier txt vierge pour voir au préalable, mais toujours rien. Bien sûr je me suis assuré que ma valeur contient bien quelque chose, c'est à dire du texte, et oui pas de soucis la valeur Page contient bien le texte voulu. Donc, pour le moment je sèche complet...

I realized this test and in the log no problem, it is "Backup successful" that appears when I perform this action. By cons, in the directory "extras", nothing ... I created a blank txt file to see beforehand, but still nothing. Of course I made sure that my value contains something, that is to say text, and yes no worries the value Page contains the correct text. So, for the moment I'm dry ...

Edit :

Nothing to do with Stencyl, it is a problem of authorization in writing under windows 10.

« Last Edit: February 01, 2018, 01:43:41 pm by Jo3m »

Jo3m

  • Posts: 13
Hello,
No. Don't work. Don't understand.
I go to the "extras" directory. I right click> property> attributes> I uncheck "drive only"> I do "apply" then "ok" ...

It still does not work.

The actions print well in the log that indicates the "success" of saving the data in the file, but in reality nothing happens. I am very fussed.


yoplalala

  • *
  • Posts: 1467
Did you check in the game generated folder ?

Dincicode

  • *
  • Posts: 214
Love love love the txtension its enabled me to do so much more with Stencyl. However there is some things that jsut wont work with Stencyl 3.5. I found solutions to some problems but the get audio file I can only disable that block. Any fixes for 3.5?

yoplalala

  • *
  • Posts: 1467
try to find " var stencylSound "  and modify like this

Code: [Select]
#if (openfl>="6.0.0")
var stencylSound = new com.stencyl.models.Sound(-1, filename, true, false, 0.0, 1.0, ext, 0);
#else
var stencylSound = new com.stencyl.models.Sound(-1, filename, true, false, 0.0, 1.0, ext);
#end

or you can try this

Code: [Select]
var stencylSound = new com.stencyl.models.Sound(-1, filename, true, false, 0.0, 1.0, ext #if (openfl>="6.0.0") , 0 #end);

Dincicode

  • *
  • Posts: 214
Second one works fine.

FMStudioGameDev

  • *
  • Posts: 163
Love love love the txtension its enabled me to do so much more with Stencyl. However there is some things that jsut wont work with Stencyl 3.5. I found solutions to some problems but the get audio file I can only disable that block. Any fixes for 3.5?
Hey, can you please share how did you fix this extension for 3.5?
I'm having these errors and don't know how to fix:
Code: [Select]
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/External Data/DataUtils.hx:55: characters 2-19 : Class<FileSave> has no field saveText
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/External Data/DataUtils.hx:27: characters 25-42 : Class<FileSave> has no field getImage
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/External Data/DataUtils.hx:6: lines 6-101 : Defined in this class
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/External Data/FileSave.hx:10: characters 7-27 : Type not found : nme.utils.SystemPath

Thank you!

« Last Edit: May 28, 2018, 10:06:58 am by FMStudioGameDev »

Dincicode

  • *
  • Posts: 214
Change the contents of "DataUtils.hx" to the text below. I think that was all. Can't remmemebr any more. I know there is 2 lines to change but I'm not sure if they were bot in the same file or not. Let me know if it doesnt work I'll look deeper.

import com.stencyl.graphics.G;
import com.stencyl.Engine;
import com.stencyl.models.Sound;
import nme.display.BitmapData;

class DataUtils {

   public static function getTextData(file:String):String {
      file = "assets/data/" + file;
      #if (flash || js)
      var text:String = nme.Assets.getText(file);
      #else
      var text:String = FileSave.getText(file);
      #end
      if (text == null) text = "";                  // if something goes wrong, return blank text
      text = StringTools.replace(text, "\r\n", "\n\r");   // swap double line breaks (Windows-style line breaks)
      text = StringTools.replace(text, "\n\r", "\r");      // replace all double breaks with single breaks
      text = StringTools.replace(text, "\n", "\r");      // make all line breaks the same type
      return text;
   }
   
   public static function getImageData(file:String):BitmapData {
      file = "assets/data/" + file;
      #if (flash || js)
      var image:BitmapData = nme.Assets.getBitmapData(file);
      #else
      var image:BitmapData = FileSave.getImage(file);
      #end
      if (image == null) image = new BitmapData(1,1);      // if something goes wrong, return blank image
      return image;
   }
   
   /* Takes a file path, gets rid of all illegal characters, and splits into a path and a filename. */
   public static function subfold(file:String):Array<String> {
      for (a in [':','*','?','"','<','>','|'])
         file = StringTools.replace(file, a, "");   // remove all illegal characters from path/filename
      file = StringTools.replace(file, "\\", "/");   // swap backslashes for forward slashes
      file = StringTools.replace(file, "//", "/");   // change double slashes to single ones
      while (file.charAt(0) == "/")
         file = file.substr(1);                  // remove leading slashes
      var n:Int = file.lastIndexOf("/");
      if (n == -1)
         return [".", file];
      else
         return [file.substr(0,n), file.substr(n+1)];
   }
   
   public static function appendLine(path:String, content:String):Void {
      #if flash
      trace("ERROR: File IO cannot be accessed on Flash.");
      #elseif js
      trace("ERROR: File IO cannot be accessed on HTML5.");
      #else
      var file = getTextData(path) + "\r" + content;
      FileSave.saveText(path, file, null);
      #end
   }

   public static function drawList(g:G, list:Array<Dynamic>, x:Float, y:Float):Void {
      for (i in 0...list.length) {
         g.drawString("" + list[Std.int(i)], x, (y + (i * g.font.getHeight()/Engine.SCALE)));
      }
   }
   
   public static function printList(list:Array<Dynamic>):Void {
      for (item in list) {
         trace(item);
      }
   }

   // EXPERIMENTAL
   public static function removeSpecial(text:String, char:Int):String {
      var special:String = "";
      if (char == 0) {
         special = "\n";
      } else if (char == 1) {
         special = "\t";
      }
      return "abc" + special + "def";
   }

   public static function getSoundData(filename:String):com.stencyl.models.Sound {
      var ext:String;
      #if(mobile || desktop || js)
      ext = ".ogg";
      #else
      ext = ".mp3";
      #end
      var file:String = "assets/data/" + filename + ext;
      var nmeSound:flash.media.Sound = nme.Assets.getSound(file);
      return soundToStencyl(nmeSound, filename, ext);
   }

   public static function soundToStencyl(sound:flash.media.Sound, filename:String, ext:String):com.stencyl.models.Sound {

      var stencylSound = new com.stencyl.models.Sound(-1, filename, true, false, 0.0, 1.0, ext #if (openfl>="6.0.0") , 0 #end);

      stencylSound.streaming = false;
      stencylSound.src = sound;
      return stencylSound;
   }
}

Dincicode

  • *
  • Posts: 214
I think also the top of "FileSave.hx" should look like this.

import com.stencyl.Engine;
import com.stencyl.behavior.Script;
import com.stencyl.behavior.TimedTask;
import com.stencyl.models.Font;
import com.stencyl.graphics.G;
import com.stencyl.utils.Utils;

import nme.display.BitmapData;
import nme.utils.ByteArray;
import haxe.io.Bytes;
import openfl.Assets;

#if (openfl >= "4.0.0")
import openfl.geom.Rectangle;
import openfl.display.*;
#end

#if !flash
import sys.*;
import sys.io.*;

#if (openfl >= "4.0.0")
import lime.system.System.*;
#else
import nme.utils.SystemPath.*;
#end

#end

FMStudioGameDev

  • *
  • Posts: 163
Thank you Dincicode for your help,
unfortunately it's still not working for me.  Now having the following error:
Code: [Select]
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/external-data/DataUtils.hx:55: characters 6-14 : Module FileSave does not define type FileSave
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/external-data/DataUtils.hx:27: characters 29-37 : Module FileSave does not define type FileSave
[haxelib.exe] C:/Users/Setroyr/AppData/Roaming/Stencyl/stencylworks/engine-extensions/external-data/DataUtils.hx:13: characters 24-32 : Module FileSave does not define type FileSave

Are you sure you pasted the whole "FileSave.hx" code?  The original one is 305 lines while you pasted only 28 (exactly the same as the original with the whole FileSave class missing).


Edit: Fixed by keeping the whole FileSave.hx file.
I am afraid I was still using an older version of the extension since I am testing Stencyl 3.5 on a Windows PC I haven't used for a while (didn't want to update my Mac until I am sure everything works).
Sorry and thanks for your help.

« Last Edit: May 30, 2018, 06:48:03 am by FMStudioGameDev »

Dincicode

  • *
  • Posts: 214
Well I did say change the top part not the whole file.