How do I pull variables from a php page?

Get help using Construct 2

Post » Fri Oct 07, 2011 10:30 pm

Ok, here is the link:
http://www.4shared.com/file/4djW66uI/construct_2_ajax_sample.html


jax.php:

<?php
$level=77l
echo $level
?>.

I'm running my own server on my personal computer so I don't know exactly how this will work for you. If you have any questions I will try and help out as much as possible.
B
3
G
1
Posts: 50
Reputation: 725

Post » Sun Oct 09, 2011 1:19 am

I am wondering if this was useful or not? If it wasn't please let me know so I can post something better. This was something I did really fast. I was/am hoping it will help anyone with the AJAX feature who is having troubles with it. Give me your opinions. And constructive criticism is very much welcome. Thanx
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 11, 2011 3:26 am

Maybe I'm a bit slow, but I still can't figure this out. Let's say, for instance, that our game has four different levels (layouts). We want a way for the person playing who has gotten to level 3 to be able to go to 7-11 or hang out with friends and not have to come back and start over at level (layout) 1 but continue where they left off at level (layout) 3.

So how, utilizing these AJAX requests, php and subsequent sql, do we save which layout they were on and other pertinent info?

I know we would need a way to create a php login, send the user's info to a php login script, update the sql database and maintain a session.

We would also need to save the last layout (level) into the sql database for that user via a php script, then call that data into our html5 application from the database through php and into our game then have our game render the proper level (layout).

So my question is, how would that be done?

B
22
S
9
G
3
Posts: 202
Reputation: 3,645

Post » Tue Oct 11, 2011 3:35 am

By the way. Am I supposed to get a syntax error on line2?

The syntax looks fine to me. I'm not seeing any unexpected ' or " or[] anywhere. droptank212011-10-11 03:46:42
B
22
S
9
G
3
Posts: 202
Reputation: 3,645

Post » Tue Oct 11, 2011 10:30 am

It's easy. When you send the call to the page just do this:

"jax.php?level=" & level & "&score=" & score

On your php page just call them like:

<?php

$level = $_GET['level'].
$score = $_GET['score'].

?>

I replaced the semicolons with periods because they won't show when I post this. And make sure there is a semicolon at the end of line 2 and 3. Then from there you can save to your database and call it back say when a user is logged in or something. If you can't figure it out I will repost a working demo when I get off work.
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 11, 2011 4:27 pm

Thank you guys, this is all very useful information for me. I'm not a programmer, not in any professional sense, all my experience in the past has been scripting mods built with construction programs for other games (Elder Scrolls stuff). I've been reading a book about databases and php, and I was very excited when I saw the ajax ability in C2. However I also needed info on how to connect the dots between C2 and accessing a server database, so all this is very helpful for noobs like me. This topic has been bookmarked on my browser for reference.
B
7
G
2
Posts: 12
Reputation: 1,112

Post » Tue Oct 11, 2011 8:35 pm

than good! I will wait with keen that work. I am following this article. did not have privileges to write. From already thank you very much
B
7
S
2
G
4
Posts: 18
Reputation: 2,578

Post » Tue Oct 11, 2011 9:59 pm

Ok, I'm working on this example, but I ran into a minor problem. It seems to me that you can only pull one variable at a time from a request. So far I have multiple events for each request. I'm trying to figure out how I can do this without so many events. But I can use the same server side page to call all the data. I will post what I have when it's done.
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 11, 2011 10:43 pm

OK, this is the website I'm working on:

My Website

Right now I have the AJAX example I'm working on posted on it. It's calling jax.php and sending the request to get two different values from the same page. In a little bit I will post the source for contruct 2.b781rev2011-10-11 22:43:55
B
3
G
1
Posts: 50
Reputation: 725

Post » Tue Oct 11, 2011 10:43 pm

Concatenation is the key on PHP side.
String expressions on C2's side.

Edit: Your website returns an error 503 atm.
Edit2: No more.Kyatric2011-10-11 22:45:17
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: 6,999
Reputation: 57,793

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, mindragon73 and 26 guests