Draimond's Forum Posts

  • How do you use AJAX POST to change the contents of a file on your web server?

    I've been looking through various topics trying to find out how to word a POST request correctly but I'm still unsure. There's some great examples out there but I'm not sure how to translate the examples into something I can use for my project.

    I want to write to a text file hosted on a web server.

    My project is hosted on the same web server.

    The data I want to overwrite the text file with is an array.

    The text file has write permissions enabled.

    I am able to "GET" the data from the text file and update my array.

    I am unable to update / upload data to the text file

    Sorry for not including a capx, probably not relevant seeing as none of this works in preview anyway. <-[solved]

    My code looks this this:

    Button_Download On clicked = AJAX request "http://www.mysite.com/data.txt" (tag "getdata")

    AJAX on "getdata" completed = Array Load from JSON string AJAX.LastData

    Button_Upload On clicked = AJAX Send Array.AsJSON to URL "http://www.mysite.com/data.txt" (method "POST", tag "savedata")

    I think the Data field needs to be written in query string form. I don't know how to do that or what that means.

    So for "data to post" it should be some php stuff around the Array.AsJSON ?

    Am i ment to have a php file somewhere?

    Just to be clear, I'm not trying to send pieces of data, I want the whole array being uploaded and downloaded.

    EDIT

    I'm continuing to research this while I wait for a reply.

    I've found some great info that will help others trying to figure this stuff out.

    What I've learned - May or may not be correct

    • If your setting up a project that uses AJAX to work with your website, your probably going to need to learn a little about PHP and setup a PHP file in your web hosting directory (eg. where your website is hosted). I don't think the AJAX Page in the manual makes this very clear.
    • To get AJAX stuff to work in preview you need to use "header('Access-Control-Allow-Origin: *');" Which is great... but how do you use it that line of code? Does it go in the C2 project somewhere? Once again, not abundantly clear to beginners like myself.

    Turns out, you put a PHP file on your website, eg anyfilename.PHP and you put this code in that file:

    <?php
        header('Access-Control-Allow-Origin: *');
    ?>[/code:2v957n1b]
    [b]UPDATE[/b]
    [b]I think I got it working![/b]
    I've ended up with a text file called "mydata.txt" and a PHP file called "myphp.PHP".
    [ul][li] The text file holds the data that I upload and download.[/li]
    [li]The PHP file acts as an intermediary controller facilitating my C2 projects interaction with the text file![/li][/ul]
    [code:2v957n1b]<?php
    header('Access-Control-Allow-Origin: *');
    
    /* GET */
    $data = $_GET['data'];
    file_get_contents("data.txt", $data);
    echo ( file_get_contents("data.txt", $data) );
    
    /* POST */
    $data = $_POST['data'];
    file_put_contents("data.txt", $data);
    echo ( file_get_contents("data.txt", $data) );
    ?>
    [/code:2v957n1b]
    [b]AJAX Request URL ( The GET function )[/b]
    Tag = anything
    URL = the url to your PHP file - "[i]http://www.mysite.com/data.php[/i]"
    [b]AJAX Post to URL ( The POST function )[/b]
    Tag = anything
    URL = the url to your PHP file - "[i]http://www.mysite.com/data.php[/i]"
    Data = "data="&TextBox.Text - [b]This is one of the main issues I had[/b]
    [ul] [li] "data="  < this is the Query String Form mentioned in C2 [/li]
    [li] data just refers to where data is written in the php file, 
    so it can be anything but [b]must [/b]correlate to whats in the php file![/li]
    [li] &TextBox.Text is the object I used to collect data to test with,
    It can be anything you like though, e.g. Array.AsJSON or a global variable etc[/li][/ul]Method = "POST"
    
    Keep in mind that I googled my way to finding this method without really understanding the technical aspect of what I'm doing. I've seen some really awesome technical stuff along the way that I have no idea how to achieve. The way I've done this is likely not the best way of doing it. But it worked, which is a big milestone for me as a beginner. 
    
    I'm keen to hear any extra explanation as to the correct process and any features or improvements that can be implemented.
    
      
    For some reason when I GET the data, i receive it fine, but it wipes the data from the text file!
    Can anyone see what went wrong with the PHP code?
    
    [img="https://photos-4.dropbox.com/t/2/AAAFqGWpWvvDQgOoQnYlswdu8GAjg30e5IqIq0O0izfU8w/12/213776830/jpeg/32x32/1/_/1/2/ajax%20code.jpg/ENOiiqEBGF0gBygH/OMzzwMjRVNN3fEIcawnxXDhcj2zj-2L5_pEqS0Vqh3c?size_mode=5"]
  • black screen is because of plugin its does not support ...conconjs plugin also give black screen

    Would be nice if it told you which plugin was breaking the app.

    furthermore, it would be nice if the cordova plugin (made by some random) was free or native to construct...

    Can't even add a "close app" feature from within C2 without third party addons! Microsoft / Intel won't ever make a cordova plugin.

    The simplicity of Construct is ruined by the arduous and perplexing process of publishing to Android.

    I have been using C2 for years now and have a paid licence... To be honest, it looks like Construct is simply not viable for use in publishing to android. PLEASE prove me wrong, I would worship anyone who could show a clear cut procedure.

  • Awesome, ty, donated

  • well I suppose that's the trade off isn't it... If you want "real time" in C2 games that can run offline then your subject to cheating. Otherwise the game must be 100% online, as you said.

    could always have some anti cheat e.g. "current time is more then a month greater then previous time = reset game". But no I don't actually think that would help.

    As for unix plugins or just plugins in general, I'm having a hard time getting past the Intel XDK's create app button. Keeps telling me my plugins are wrong and I can't for the life of me figure out why... all I did was update the xdk, app hasn't changed. So based on those issues.. I feel even less confident to proceed with the "real time" app.

  • I was trying to keep it broad because the main question was:

    What process are people using to get from A to B, Construct 2 to Google Play.

    I got a top scrolling race game which is in beta on google play (but it's not working) and a plethora of other projects I haven't taken further because my flagship app hasn't successfully been completed.

    All the compiling services have been getting updates faster then people can make guides for them. In turn the guides are becoming less relevant.

    There are now so many ways of compiling, signing and zip aligning and thus there are tones of possible combinations of apk finalizing methods.

    Is there a sweet spot? Is there a combination that yeilds predictable results that's user friendly?

    I'm not a pro developer, I just figured out how to use construct over the course of about a year or so. The compiling services however, seem to be tailored to a more dev savvy user base, which I don't think is your average licenced construct user.

    I'll try and answer some of my own questions for the benefit of the public.

    Intel XDK

    I really like this program. I feel like it has more potential then the other services provided you put some solid time into learning it. When I first used Intel XDK it was very daunting and hand to pick up and understand. The tutorials were mostly for different versions then the one I downloaded on that day. The UI has changed a fair bit, important buttons and functionality aren't where they used to be, as seen in the tutorials.

    Once you do manage to become simi-familiar though, things start to get better. The preview on your phone feature is awesome and the game looks like it's meant to when viewed on a android device.

    HOWEVER, I havn't been able to compile anything with XDK for the last few versions. It just sits at "uploading project" with no indication of progress. I've left it for a whole day with no result, however the CPU usage shows that it is doing something?!

    Even if you don't have this issue or can get around it, you still get no real progress indicator, whether your downloading an update or uploading your project.

    Cocoon.JS

    The old Cocoon system worked. You had to push the right buttons and select the right options for it to spit out a working app, but when you did, it really did "just work". RIP

    Cocoon.IO

    The new system for cocoon that is currently replacing .JS.

    Recently tried to get it to compile my app. 9 out of 10 attempts I got the "Black Screen" known bug. There's a few fixes that require you to change physics engine and a couple lines of code manually, but despite doing that, I still got a black screen 9 out of 10 attempts.

    The one attempt that did work was ugly. Fonts looked odd and had scaled weird and were out of position.

    Looked extremely unprofessional. I don't know if a fix exists, I imagine I'd get told it's inherit to the process.

    Either way, conclusion is that you cannot expect your app to look the same on android as it does in C2 preview...

    Signs and ZipAligns your APK for you!!! you have to provide your own keystore.

    Adobe PhoneGap

    I put about an hour into this and either didn't get a working result after compiling or got a weird result. Can't comment to much here because of limited experience.

    KeyStore - Signing - ZipAligning

    This was a painful experience for a noob to be undertaking... -_-

    I hate this part so much. Download an old version of java (which u need an oracle business account to get!) because the new ones don't work. I can't remeber what else I had to download at this point, think I ended up with 3 versions of Java XDK, Android XDK, Intel XDK and something else... ALL JUST TO SIGN THE BLOODY THING!

    When doing it manually, save a notepad doc of EVERYTHING you do.

    I used notepad ++, (shift, ctrl,right click to get cmd in the location required)

    There's a tiny program floating around somewhere that can do all this rubbish for you. It's less then a few MB!

    Advanced+ApkTool+v4.1.0+By+BDFreak

    First dozen times I tried to do this I went through the entire process (with a miserably slow net speed) just to keep getting told by google that my apk wasn't zip aligned correctly or something. Days... not just hours..

    So yeh I'm not having fun

  • Hey guys, I'm looking for user feedback as to the best method of getting a game out of Construct 2 and onto the Google Play Store.

    I've tried using the Intel XDK, Cocoon.js and the new Cocoon.io. By far the Cocoon.js was the best experience I've had with publishing, having said that I still don't have a finished, bug free game on the Play Store. Having issues no matter what way I go.

    It would be amazing if i could just press a button and C2 popped out an apk that looked and played the same as what I get in the C2 preview!!!

    Alas, all the methods I've tried have given me multiple headaches.

    I bought C2 personal with hopes of getting a foot in the door to amateur android development and publishing.

    I have limited knowledge but i google everything I don't understand until I understand it.. or my head hurts too much to absorb new information.

    I feel like I'm so close to publishing my app but I just can't get a decent working apk for the life of me.

    I really need some guidance, I've put a good 6 months into this one app and I'd hate for it to all be for nothing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just tried using Browser Close in my Android Game, compiled using the new Cocoo webview+ and it doesn't work.

  • changed to wallclocktime insted over add to count ever x seconds, works well.

    int(Scores.At(Scores.CurX)/60000) & "." & int(((Scores.At(Scores.CurX)/10) - ((int((Scores.At(Scores.CurX)/10)/6000))*6000))/100) & "." & (Scores.At(Scores.CurX)/10) - ((int(Scores.At(Scores.CurX)/1000))*100)

    Set | Scores to | (int(Text_Timer_Min.Text)*60000) + (int(Text_Timer_Sec.Text)*1000) + (int(Text_Timer_Mil.Text)*10)

    Set | Play_Time to | wallclocktime - Menu_Time

    Still need a reliable unix addon that works in android for progress over time games

  • Every X Seconds | Spawn Enemy & set next X to int(random(1,6))

    so for Every X Seconds you use a global variable, I'll call it xRandomSeconds

    Every "xRandomSeconds" do

    1) Spawn your enemies

    2) System | set "xRandomSeconds" to int(random(1,6)) - now you have a new interval for the next spawn

  • I do add 1, problem is a add 1 every 0.1 seconds..

    I do expect fairly exact results, In fact after looking at the google play leader boards guide for developers, I've found that i need 0.00 seconds , ie, hundredths of seconds

    [quote:sdkokj4i]Time leaderboards present scores in hours / minutes / seconds / hundredths of a second format. You must submit scores as milliseconds, so 66032 would be interpreted as 1:06.03.

    1 minute 06 seconds 03 milliseconds

    They need times submitted as milliseconds. I don't think construct can handle milliseconds can it?

  • I'm not sure that I understood what your after, but:

    System | For each Square

    Square | InstanceVariableX = Girl.InstanceVariableX

    Square | InstanceVariabley = Girl.InstanceVariabley

    do -> Girl | Set position to Square (image point 0)

    Tried to make it look like it does in Construct2

    Arrays are awesome, but if your having trouble now... I wouldn't send you off to learn arrays even though they are ultimately better and easier to use

  • Posting here because I do need a solution.

    I got a racing type game that needs to run off milliseconds.

    Floating point stuff is giving me a headache (0.1 = 0.099etc).

    Can't use the, every x seconds because every 0.01 seconds doesn't play nice.

    [quote:4brktgh9]Time leaderboards present scores in hours / minutes / seconds / hundredths of a second format. You must submit scores as milliseconds, so 66032 would be interpreted as 1:06.03.

    Quote from Google Play Games Services for Publishing Android Games.

    If anyone has any experience with c2 to google play, handling hundredths of seconds, I'd love to hear about it.

    Also working on another game where I want to accumulate revenue over time regardless of whether or not the app is running.

    Correct me if I'm wrong but Construct 2 doesn't have native support for 'system time' ?

    I was just going to search for a unix time addon but got cold feet wondering if it would work on the million different types of android phone. I want to be able to work with hundredths of seconds and days all in the same equation. Elapsed time.

    e.g. this thingo will give revenue 3 times per second, and this thingo will give revenue about once every 3 hours and if the app is closed, it will check on startup, using last stored times, how much has been earned since last revenue gained and calculate/display the progress towards next revenue for each thingo.

  • For example the number 0.1 is exact in base 10, but is a recurring decimal in base 2. This means rounding can happen in unexpected places, even if you think you're dealing with exact numbers.

    ok... fair enough.

    was very scared, ty

    So how do you do it then?

  • Problem Description

    Having an issue with a play time timer. I'm adding 0.1 to a variable "Play_Time" ever 0.1 seconds.

    This way I can exclude menu time from game time by checking to see if the menu is open before it adds time to the play time variable. I need milliseconds because It's a time based racing survival game where seconds aren't going to be enough to separate players on a leader board. However I'm getting weird numbers.

    What I get

    Code

    The disabled code just caused the Play_Time to stay at 0.7.. not what I expected either.

    What I expected would happen

    well... you know.. 0.1 second would be a nice round 0.1... how could it possibly equate to anything else <img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked">

    Recreating this issue

    I had another interesting issue when recreating the capx for public viewing.

    I did the add 0.1 per 0.1 seconds thing with the play_time variable, then set a value in an array (used to record multiple scores) to Play_Time, which always gives a raw, uninterpreted value such as 1.99999999865 when viewed through a text object (set text1.text to array(1) ).

    Mean while I let construct interpret Play_Time directly without the array by viewing its value through a text object, the same way i did with the array, (set text2.text to Play_Time).

    I used a button object to take a snapshot of the values.

    • The array received the value Play_Time and displayed it as 14.999999999999963
    • The text object, however, displayed the value for Play_Time as 15
    • My value for time display which I got from the array and converted into time showed 0:1410 (this is in minutes)

    I get the sense that the .99999999963 is something theoretical. It knows it should be absolute e.g. 1.0 but it can be seen behaving as a decimal when viewed through an array... however the moment you reinterpret the value from the array it switches back into a whole value..... <img src="{SMILIES_PATH}/icon_e_surprised.gif" alt=":o" title="Surprised"> like my time display, the .999etc became a 1 again when called on to be a 'used value' as opposed to a 'stored value'... i'm freaking out, it's the matrix man!

    " Time " & int(Scores.At(Scores.CurX)/60) & ":" & int(Scores.At(Scores.CurX)) - (int(Scores.At(Scores.CurX)/60))*60 & (Scores.At(Scores.CurX) - int(Scores.At(Scores.CurX)) )*10

    Demo capx

    https://www.dropbox.com/s/dziksi3to3781 ... .capx?dl=0

    Affected Browsers

    Chrome

    Operating System and Service Pack

    Windows 7 64 SP1

    Construct 2 Version ID

    r216 64bit

  • I know this is an old post but it was the second result in my google search for automatic game saves for android.

    So i know that there is a static was to save games ( https://www.scirra.com/tutorials/526/ho ... -savegames )

    I've played around with saves and honestly I just haven't gotten the hang of them.