How do I save data into a text file - Android build?

0 favourites
  • 7 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • My bowls app uses arrays to store the positions of objects to create replays.

    I am trying to find a way to download this data so that if needed a user can submit it so I can review any bugs.

    On a HTML5 build, the invoke download from the browser plugin works fine and I can save and load array data as JSON information. The problem is that this is blocked when compiling into an android apk.

    If there a way to unblock it - or a suitable alernative method to achieve what I am trying to do?

    I have tried to use the cranberry save file plugin but that didnt seem to do anything. I also tried to upload the data (google sheets / zapier webhook) but there are too many values in the array and both these methods time out without completing

    Thanks,

  • Maybe optimize the data, or send it in portions?

    I haven't seen a working solution to allow saving files on Android. Although, I believe "cordova-plugin-file" (or a fork plugin) is added automatically to all builds. So maybe you can use some javascript to write to a file:

    cordova.apache.org/docs/en/latest/reference/cordova-plugin-file

  • Hi dop2000

    Thanks for the reply. I'll check out the link now to see what I can do. I have the cranberry plugins which I paid for back in 2015. I know the file-plugin was part of this, but at the moment I've not managed to sucessfully use it.

    I've been trying for a few hours to optimise the data but its still too much. I eneded up being able to send a small portial of the array over to google sheets. But this is about 1s of in game data. Once you get over this it must fail as google stays empty.

    I guess i could make the array save less info and make the replay not as smooth to cut dwon on the data. The array stores 5 bits of data for 10 objects :( (8 player bowls, 1 jack and 1 wood - for each one it stores the x, y, size, rotation and animation info)

    It's a shame as the JSON file when you download through PC web is only like 800kb for a whole match being saved (Short match). I was thinking of trying to save the angle / force for each shot instead as this would be alot less data - but i believe the phsics wouldnt work 100% the same everytime so it might give in correct replays

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Did you set fixed stepping mode for Physics?

    If you need to send lots of numbers, don't send each number in a separate URL parameter. Put them into an array and send the whole thing as urlencode(Array.AsJSON). Or even pack it into a compact comma-separated list, maybe then it will not timeout.

  • Hi dop2000

    At the moment I used the replay template that was on here (it's very old).It is putting all the data into an array already.

    Each physics item has its own array. Then at a set internal (I have a variable to change / experiment, currently set at 0.1s) - it will push the X, Y position, rotation and animation frame to an array. As it does this is add's one to a variable so that you can loop from 0 to this variable to replay the match.

    It works well and was very easy to setup - trouble is it also records the position when statioary and as you can image when you combine all 10 arrays into one its alot of text. (Each player has 4 bowls, there is the jack and wood on the mat that also need recording)

    On the PC because I can use invoke download, I've made it so I can download asJSON all arrays compiled together. I can also load in one of these files and load up a replay fine. Trouble is this is blocked on android. The shortest match posible is around 800kb JSON file with around 600,000 characters.

    I might try and modify the code so that it only pushes to the array when the object moves - storing a value to represent what 'frame' this occurs at. Then if the frame number matches the loopindex it will set the position - otherwise leave where it was. This would cut out alot of the text as most of the time the objects are stationary except for one object on the mat (or a couple if there is a collision). I am guessing this would be better leaving as an array for each object as if I tried to create on big 3D array, I am guessing it would store alot of "0" when most objects are still.

    I did manage to get it posting the array data to a google sheets - Without an optimization though I am hitting the fact that google has a 50,000 character limit per cell. (I have tested splitting the POST request into 50,000 at a time but this is just bound to give me problems if I don't make efficient.

    I started splitting out a way of storing just the last shot yersterday so a happy meduim might be to allow users to save / submit just one shot. (I'd like to allow submitting your best shots / any bugs encountered)

  • Yes, before adding a new record, check if the object has actually moved at least 1 pixel since the last time. But then you'll also need to save a timestamp or tickcount.

  • dop2000

    Yep - that's what I've been updating in it this morning. I added a timestamp value to the array and it only updates at the start of each shot (1 row) and then when that particular object is moving.

    It has actually halved the data in the array for a short match (400kb and 400,000 characters). I've also renamed my animation frames to "D" and "T" rather than "Default" and "Toucher" to save characters!

    I think I can strip out two of the values in each row two and call that at the start of the replay (The bowl size and colour don't change once the match has loaded) - This should cut down too

    I do need to work out a more efficient way of checking if the timestamp is in the array as the method I've put in at the moment works ok for a small array. it's too slow at the end of the match when the array is larger.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)