How to change "global variables" externally?

Get help using Construct 2

Post » Tue Feb 12, 2013 10:27 am

Hello,

I am currently in the process of exploring the possibilities of Construct 2 for us. Figuring out if we can do with it what we need but i have hit a problem.

The problem is i am trying to change one of the global variable's values through an external javascript.
This is mainly because we want to create a game that more or less has an infinite amount of levels. So instead of letting construct 2 create levels we have decided to do this with PHP (?level=2 etc.) What i need now is a way to adjust the values of the global variables with information retrieved from the database.

But i cannot seem to be able to figure out how to change the values of the global variables within the index.php page without using ajax/xml/json request within construct 2.

Hopefully somebody is able to assist me with my issue. Or provide me with information if there are better/easier ways to achieve this.

PS: Sorry for any english writing mistakes.
B
2
Posts: 9
Reputation: 443

Post » Tue Feb 12, 2013 11:46 am

Sry for my bad English.

I think you misunderstand something, in every programming language you need to make database request to get data out of your Database. In Javascript(This is what Construct generate) its not directly possible. You could only make an Ajax request to a PHP file which get you the data out of the database.

So the logic is:
1. Ajax Request on a Php file with some Parameters
2. Php file makes the database request and some magic stuff with the data
3. Ajax on complete, save the result in your global variables.

You need to understand that between Javascript and Php must be any connection, mostly is ajax used.

The other Problem is that Php is a server side language, it just makes something if you say "Hei Php go" and than it will execute your code one time, not more.

No other tool like Gamesalad, Gamemaker and so on can work with Php files without Ajax, Json and so on. Not even native code!
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Tue Feb 12, 2013 12:18 pm

Yes i fully understand that but my question is more:

<?php
$a = 'hello';
?>
var a = <?php echo json_encode($a); ?>;

But then apply that for the global variables in construct 2. So i could change the information in the variables based on the level dynamically. Simply by encoding the raw string data retrieved from the database.

But i would like to prevent editing the runtime.js and rather be able to do this on the index.html(.php) page. schippie2013-02-12 12:21:09
B
2
Posts: 9
Reputation: 443

Post » Wed Feb 13, 2013 1:18 pm

This is possible but no good idea because variables can be changed anytime you change your construct code.

But if you think you will never update your game, you could do this with JQuery or PhpQuery.

if you have a real example I could tell you how to do it easily.
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Wed Feb 13, 2013 2:42 pm

Thank you for replying, i have found a way to get variables into the game now through a different route. The callJS plugin did it.
B
2
Posts: 9
Reputation: 443


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 26 guests