Any limits on AJAX post-data?

0 favourites
From the Asset Store
Easy SiteLock
$11.99 USD
Protect your game from being stolen and posted on another site with Easy SiteLock!
  • It seems to be the examples only. If I just load up a new project and add my own tables, they seem to work fine (actually they do in the examples too, but just give an error when loading). Here's the bug it reported.

    ---------------------------

    Construct 2 Check failure

    ---------------------------

    Check failure! This is probably a bug:

    Encountered second <i> before first was closed with </i>

    Condition: italic_flag == false

    File: Controls\EventString.cpp

    Line: 213

    Function: void __cdecl EventString::FragmentString(void)

    Build: release 174 (64-bit) checked

    Component: Construct 2 IDE

    (Last Win32 error: 0)

    You are using a 'checked' release of Construct 2, intended for testing, which causes certain errors to be reported this way. Hit Ctrl+C to copy this messagebox - it's useful information for the developers, so please include it with any bug reports! Click 'Abort' to quit (unsaved data will be lost!),'Retry' to turn off messages for this session and continue, or 'Ignore' to continue normally.

    ---------------------------

    Abort Retry Ignore

    ---------------------------

  • Ahh.. looks like beta releases check for correct closure syntax... yah the error is trivial.. its a tag that makes the text italic when displaying an action in the editor. I found the error thanks to your print out and updated the file in the post above. You can re down load it and it should work.

    Thank you!

  • Yay, cool

  • troublesum

    Following on from what you've taught me already, just wondering, is there a similar system to the Constuct 2 'Pick' system, in PHP? For example, I can download all of my players from my database into objects, but I'm not sure how to work with the objects. Let's say for example, I only want to operate on the players belonging to team 1. In Construct, I do a simple 'Pick Players where Team = 1' sorta thing. In PHP, how do I do something similar? Is it more of an old-fashioned sort of approach where I start my loop, run through all the player objects, and do something along the lines of If Player->Team == 1 .... ?

    It's strange going back to this kind of programming. I hated OOP when it first arrived, now I can't live without it. But PHP does have OOP right, I just need to use a different syntax?

    I'm actually considering doing the entire 'guts' of my game in PHP. Originally I was planning to load everything into C2, process it in C2, then load it back to the database via PHP. But it seems like an unnecessary step when PHP could probably do the whole thing.

    Sorry to keep asking questions, feel free to ignore me, I'll work it out through experience but it's always good to get off on the correct footing

  • farflamex - Not a problem... I enjoy helping when i can

    So once the player data is received to PHP via POST its nothing more than an array of data. Its not any sort of real object (yet). If the array data you receive from the POST is already relative to the columns your updating in your database table (IE Player1.Score, Player1.Health, etc..) which are just basic properties that have no affect on other properties when updating then Objects aren't really necessary IMO.

    It would how ever make sense to do OOP (Build player objects) if at the time you receive the POST data, before you do anything with the array data, you first query the database and retrieve the player data and build the player objects with the SQL information. Then using methods from your player object you update the player with the new data you received from the array. IE $player1->AddExperience(10) which will update the database using some custom algorithm that may affect other player properties as a result of adding experience like attack level, defense level etc. all of which are updated by a signal command to "AddExperience" . If your player objects are complex like that then this would give you a standardized method of making changes to SQL data by working through the object. The issue is that the player then needs to be updated in C2 with the new information as well so there is lag in the time the player will achieve his new experience as he had to wait for PHP to do the processing. So if its a real-time achievement this probably wont work but if its an achievement at the end of round that is applied to the next round it would be fine.

    Personally I feel you should keep your objects in C2 and do all of your processing there instead of in PHP and instead PHP is just the wrapper for storing/retrieving information to/from the database. (As a developer it kills me to have to do this in the event sheet as its not really meant for this so I have to work around or hack to get the results i want) But If you also know JavaScript then what I would do (which I do) is create plugins that become your player object methods that allow you to write code for these complex events instead of trying to piece it together in the event sheet. If you really want to unlock the power of C2 you will need the ability to write JavaScript and create your own plugins to perform complex functions.

  • My game is turn-based, so PHP should be adequate for processing the logic of the game. One huge advantage also is that I can auto-run my PHP logic file as a Cron-Job which will be one less thing for me to do. If I made a sort of control panel, similar to how my game runs right now, I have to log in at the right time and set it running.

    The advantages of C2 are that I know the language very well and find it easier to manipulate objects. But I'm sure I can get the hang of it in PHP. Luckily, I'm in no rush, so what I think I'll do is, keep plodding away and see where it leads me.

    I have worked out that if I fetch my data with FETCH_CLASS, it puts it directly into a class, and then I keep an array of those objects and work my way through those. It's not quite as easy as C2 and reminds me of the 'good old days', looping through arrays etc, but it's fairly simple. I am a bit confused that my player object doesn't have certain values but it just adds them from the database anyway. E.G My players in the database have about 10 ratings, but in my class, I only added about 3 of them for testing. When I fetch the data with FETCH_CLASS, it creates the object from my class, fills the properties I've created and then just creates the others too. Making me think that I could actually just skip the properties and allow it to fill automatically anyway.

    Anyway, learning and enjoying myself as I go, it's fun

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • troublesum ... Sorry to bother you again but you seem knowledgeable on this stuff, so any ideas why this is happening? Pasting this from my other thread...

    I know this should be fairly basic so I must be doing something wrong.

    I'm sending a json_encoded string from my php file to C2. The string shows [4,3,1,3,1,2,1,1,0,3] when C2 receives it (when set in a text object). It's just 10 numbers in PHP.

    I then try to load it into my C2 array with Array -> Load from JSON string (String).

    The array is still empty, so I'm doing something wrong. Any ideas?

    Can you identify which stage this is going wrong at? Does that string [4,3,1,3,1,2,1,1,0,3] look like a json string to you? That's what it's showing when I echo it from php to a browser, then when I show it in a text object in C2, but when I convert it into my C2 array it's just empty.

  • troublesum ... Sorry to bother you again but you seem knowledgeable on this stuff, so any ideas why this is happening? Pasting this from my other thread...

    I know this should be fairly basic so I must be doing something wrong.

    I'm sending a json_encoded string from my php file to C2. The string shows [4,3,1,3,1,2,1,1,0,3] when C2 receives it (when set in a text object). It's just 10 numbers in PHP.

    I then try to load it into my C2 array with Array -> Load from JSON string (String).

    The array is still empty, so I'm doing something wrong. Any ideas?

    Can you identify which stage this is going wrong at? Does that string [4,3,1,3,1,2,1,1,0,3] look like a json string to you? That's what it's showing when I echo it from php to a browser, then when I show it in a text object in C2, but when I convert it into my C2 array it's just empty.

    This [4,3,1,3,1,2,1,1,0,3] cannot be loaded inside the array via the load from JSON since it is not correctly formatted, I think using a tokenat and removing the [ and ], you could load the values inside an array.

  • I posted this on your other thead but wanted to reply to this one as well.

    Make sure your encapsulating the php array in the format that the C2 array is expecting.

     $myArray = array();
        $myArray[] = 4;
        $myArray[] = 3;
        $myArray[] = 1;
        $myArray[] = 3;
        $myArray[] = 1;
    
        $output = array(
    	'c2array' => true,
    	'size' => array(
    	    0 => count($myArray),
    	    1 => 1,
    	    2 => 1
    	),
    	'data' => array()
        );
    
        $x = 0;
        foreach ($myArray as $value) {
    	$output['data'][$x] = array();
    	$output['data'][$x][0] = array();
    	$output['data'][$x][0][0] = $value;
    	$x++;
        }
    
        return json_encode($output);
    [/code:3rbxiej0]
    
    The resulting JSON string would look like this :
    {"c2array":true,"size":[5,1,1],"data":[[[4]],[[3]],[[1]],[[3]],[[1]]]}
    
    You can now take this string as is and load to the Array in C2
  • Sorry totally unrelated. I cant send you a private message, so I'll try here. I just loved the graphics on your latest game Jovian War. I was wondering if you could share the source of those graphics? Thank you.

  • k, I'll reply on the JW thread.

  • I have found that there seems to be an upper limit on the size of the json string, I think it was 32K characters, or perhaps larger. I think it's a string constraint, not specifically on ajax. A quick test would tell you. I discovered it as the xml file I was taking in got truncated.

  • I posted this on your other thead but wanted to reply to this one as well.

    Make sure your encapsulating the php array in the format that the C2 array is expecting.

    >  $myArray = array();
        $myArray[] = 4;
        $myArray[] = 3;
        $myArray[] = 1;
        $myArray[] = 3;
        $myArray[] = 1;
    
        $output = array(
    	'c2array' => true,
    	'size' => array(
    	    0 => count($myArray),
    	    1 => 1,
    	    2 => 1
    	),
    	'data' => array()
        );
    
        $x = 0;
        foreach ($myArray as $value) {
    	$output['data'][$x] = array();
    	$output['data'][$x][0] = array();
    	$output['data'][$x][0][0] = $value;
    	$x++;
        }
    
        return json_encode($output);
    [/code:2hjte4hn]
    
    The resulting JSON string would look like this :
    {"c2array":true,"size":[5,1,1],"data":[[[4]],[[3]],[[1]],[[3]],[[1]]]}
    
    You can now take this string as is and load to the Array in C2
    

    How would you format your json_encode($output) if all you want to do is return, say, five name/value pairs?

  • From C2 to PHP? If it's 5, I'd put them in an array and send them as above. You could do it as I did it at first, by making a string, separated by a symbol (e.g the pipe '|') and then 'explode' them at the other end.

    Have to say, having done quite a bit of PHP and C2 now, I'd go with json_encode all the time if it's already an array at either side. For a small amount of info, I'd probably just send it as a string.

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