How do I send data to my php script? (AJAX question)

Get help using Construct 2

Post » Sun Jun 29, 2014 9:30 pm

Years of BASIC programming have made this really confusing. It's all working fine, the PHP part at least, but I'm trying to do things BASIC ways and presumably it just doesn't work that way. For example, I'm trying to do tests on the new $output values, but it's kinda ignoring me... e.g


if ($output[1] = 2) {
$query = $db->prepare("UPDATE Players SET PositionRT = :NewPos WHERE ID = :ID");
}

if ($output[1] = 3) {
$query = $db->prepare("UPDATE Players SET PositionYT = :NewPos WHERE ID = :ID");
}

This ALWAYS executes the 2nd statement, even if $output[1] doesn't equal 3 :(
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun Jun 29, 2014 9:49 pm

I think it's actually running both of those: http://www.php.net/manual/en/language.o ... arison.php

PHP is kinda like C languages, you need to use == when doing a check (= sets a value) :)

Still, I'd love if every language was a quick and simple as BASIC :P
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Sun Jun 29, 2014 10:49 pm

Ahhh cool yes. I've been learning non-stop for about 5 days and although I read about == and === a couple of days ago, it's already been filtered out by the extra stuff. In fairness, I do remember learning BASIC in the 80's and it took ages for it to really settle in, so it's the same thing. But yeah, it would be nice if they had BASIC syntax. I'm converting a game over from 1991, which was written in BASIC, long before visual or objects or anything like that. It was pure spaghetti and I was younger and less patient, so my program is an absolute unreadable mess. My plan was to convert it to a modern language, all nice and neat but PHP looks exactly like my 1991 program, only worse :p

But I believe this is the way the programming world is headed and at least we have C2 to make the front-end UBER easy, which would be the hardest part. I just need to learn PHP and build the 'guts' of the game in that but it'll be a while before PHP sinks in methinks :)

Thanks, as you say, it's currently running all of the 'if' statements, I'll change to == :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun Jun 29, 2014 11:02 pm

All working fine now, thanks guys. Whole weekend's work, but got it done, can sort've say I can now select/update/insert from C2 into mysql database on my server... now I can sleep :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Jul 03, 2014 4:04 am

Any chance you could help me out with turning this code into a 2d array in PHP? I understand the basic PHP syntax for 2d arrays, i.e array[0] [0] instead of just array [0]. Just struggling to work out how this is chopping it up into the array in the first place. For example, right now I'm sending a 10 x 3 array asJSON.

This was your code from above to turn it into a 1d array. How do I adjust it?

foreach ($c2ArrayData as $z) {
foreach ($z as $y) {
foreach ($y as $x) {
$output[count($output)] = $x;
}
}
}
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Previous

Return to How do I....?

Who is online

Users browsing this forum: bluesun66, Malhog, plinkie, Syazanie Amirin and 1 guest