Any limits on AJAX post-data?

Get help using Construct 2

Post » Thu Jul 03, 2014 7:50 pm

Yeah that's true, thanks for the explanation. If JSON is better, I'd rather just stick with it (I've grown very patient with old age) until I'm comfortable with it. All new languages/concepts are difficult at first anyway.

Certainly I'd never need a pipe in any normal circumstance, so I don't see that being a problem.

Wow, I've been using C2 for years and for some reason, I'd never noticed that you can mix types in an array, so that does help make JSON more appealing. I was thinking I'd have to send the strings and integers in 2 seperate arrays, but apparently not.

This is almost tempting me to KEEP everything in an array during my C2 processing, but I absolutely hate arrays nowadays (used to swear by them until I became comfortable with objects). My old program (written in 1991) is all arrays and it's very difficult trying to work out what's happening when you read Rating(2,21) etc, it just makes no sense. So I always parse everything into an object when receiving in C2, then load it into an array to send it back to PHP, then split it again using your code and save it. Does sound long-winded when I could just keep it all in the array all of the time. But arrays are so hard to read and bug-ridden, I don't like that idea at all.

Plus, when returning the data to PHP, I don't intend to send all of the data anyway, only selected bits (i.e the bits that have changed). So I'm effectively creating a small temporary custom-array, just to post it as my JSON string. That seems sensible instead of constantly sending the whole object back and forth when only a single value might have changed, though it also means more PHP scripts. Hmmm, lots to think about, but for now I'll stick with the JSON code until I understand it better (actually I understand the JSON part now, just the PHP is still confusing me).
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Jul 03, 2014 7:54 pm

@farflamex I dont know how you feel about using 3rd party plugins but I also found that I didnt like the way Dictionaries and Arrays were stored in C2 so I created my own Table plugin that works with raw JSON data.

TRBLSM_Table.zip


Example:
help1.png


You can see in this example I just set my values and then can pass the entire table AsJSON how ever unlike C2 Arrays its pure JSON data with no additional overhead and is a named array storage instead of indexed integer values. Its basically the same as any array (hash table for those that prefere correct my symantics) your familure with working with in PHP.

Code: Select all

$jsonString = $_POST['c2Data'];

$array = json_decode($jsonString,true);

//$array['Player1']['Name'] = 'Troublesum' (string)
//$array['Player1']['Score'] = 1000 (int)
//$array['Player1']['Health'] = 100 (int)

//$array['Player2']['Name'] = 'Not Troublesum' (string)
//$array['Player2']['Score'] = 500  (int)
//$array['Player2']['Health'] = 20 (int)


You can see its much easier to work with and the value types (string),(int) are maintained. If your interested in using the plugin your more than welcome to. I have attached it above with a few examples on how to use it.
You do not have the required permissions to view the files attached to this post.
Last edited by troublesum on Thu Jul 03, 2014 11:19 pm, edited 2 times in total.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jul 03, 2014 8:00 pm

Cool, this looks really interesting and seems to cut out much of the work. It's not really the work that bothers me, just that I don't like messy code, and this looks nice and neat. Especially since the code looks similar on both sides, which will really help with readability.

Going to give it a try. Only downside I can see is that I'll need the add-on pretty much forever and I suppose that there's a danger of losing access to it in the future (mind you, I could store a copy on my server with all my data or something, just in case).
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Jul 03, 2014 8:04 pm

Looks excellent, you've done lots of work on that, seems to be very comprehensive too with every option I can think of. It did report a couple of errors when I loaded it up, but then went ahead and worked fine anyway, maybe something to do with newer versions of C2 or something?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Jul 03, 2014 8:07 pm

Possibly... I do only install the stable releases of C2 soim not on the latest (174).. try saving and re-opening and see if the error comes up. I don't have any errors when I open it so if you still get them upload a screen shot for me if you can. Thanks
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jul 03, 2014 10:03 pm

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
---------------------------
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Jul 03, 2014 10:33 pm

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!
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jul 03, 2014 10:52 pm

Yay, cool :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sat Jul 05, 2014 2:25 pm

@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 :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun Jul 06, 2014 1:48 am

@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.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Armench, Artcadev, farsen, newt and 13 guests