How do I use php in Construct 2?

Get help using Construct 2

Post » Sun Sep 11, 2011 8:53 am

The title says it all.
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Post » Sun Sep 11, 2011 12:54 pm

You can't use PHP in Construct 2, but you can use it with Construct 2.

Using the Construct 2 AJAX object you can make a GET request to a PHP page, for example:

"http://www.mysite.com/receiver.php?action=highscore&username=Tom&score=28000"
Image Image
Scirra Founder
B
125
S
37
G
25
Posts: 3,945
Reputation: 44,922

Post » Sun Sep 11, 2011 1:17 pm

Example of using AJAX object in C2.
WAMPserver a good software to make local webserver so that you can test your PHP scripts before hosting them online.
W3Schools PHP tutorials and references.

Forum ate my previous answer and Tom answered the question anyway.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Mon Sep 12, 2011 6:09 pm

great software. The best I have seen so far!

BTW Kyatric how to make your example work?Mehtab2011-09-12 18:39:59
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Post » Tue Sep 13, 2011 12:37 am

Read the comments.
Replace the url with an url from your server like Tom gave.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Sep 13, 2011 6:31 am

But how will I get the specific data. For e.j in

http://www.mysite.com/receiver.php?action=highscore&username=Tom&score=280

how will I get the score which is 280 and assign it on a text?
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Post » Tue Sep 13, 2011 6:36 am

[QUOTE=Mehtab] But how will I get the specific data. For e.j in

http://www.mysite.com/receiver.php?action=highscore&username=Tom&score=280

how will I get the score which is 280 and assign it on a text?[/QUOTE]

When you make a request to the page, the output of the capturing page will stuff the result then send it back to the calling page. In this case, I assume your game.

You can access the payload by using the AJAX object as in:

AJAX.LastData

You can then set that data to a text box or pass it over to another variable in your game.

B
18
S
8
G
7
Posts: 120
Reputation: 5,630

Post » Tue Sep 13, 2011 12:47 pm

But the AJAX.LastData doesn't returning any data.
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Post » Tue Sep 13, 2011 12:59 pm

[QUOTE=Mehtab] But the AJAX.LastData doesn't returning any data.[/QUOTE]

If it doesn't appear to be returning data then you may want to check the page that is suppose to be returning the data. If the page is throwing an error or returning blanks, then yes, the AJAX.LastData will not return anything.

If the page is returning or showing data, then it may be that the events you've set up in your game is not setting or assigning the AJAX.LastData payload to your target object. For example, a text box that keeps track of scores or users.

Ghengis2011-09-13 13:00:02
B
18
S
8
G
7
Posts: 120
Reputation: 5,630

Post » Tue Sep 13, 2011 1:02 pm

Can you show me step by step? That will be a great appreciation.
B
12
S
5
G
5
Posts: 80
Reputation: 3,572

Next

Return to How do I....?

Who is online

Users browsing this forum: YoHoho and 14 guests