Problem with global variable.

Get help using Construct 2

Post » Thu Apr 12, 2012 12:57 am

Hi people, first of all i give thanks to the creator/s of this awesome program.

Well i have a problem here... If someone can help me i will apreciate so much :P

My problem:

I create a game of math calculations, i have a web page and i want to get the "Score"(a global variable of my game) to my webpage, well when i see the code named c2runtime.js, i try get the value of the global variable...


I can get the value with this code at the end of the script:

function showScore()
{
     $.post("score.php", {score: Score(*)}, function(data) {
     alert(data);});

}
(*) there i need to put the name of the global variable to pass the score to the php file.

Someone knows if this is possible?

Thanks. :)
B
3
Posts: 7
Reputation: 339

Post » Thu Apr 12, 2012 1:40 pm

No one knows anything about this problem? :/.

When i open the source code c2runtime.js

[-1,z.l.prototype.d.S,g,[[11,"Score"], how i can get this value... Is a kind of gigantic array with more big array's inside...

Volh2012-04-12 14:01:33
B
3
Posts: 7
Reputation: 339

Post » Thu Apr 12, 2012 2:02 pm

You have many possibilities for that:
With the Id property
or easier directly with ajax or ajaxpost plugin..
There are some examples linked in the howto faqs and a tutorial for the ajaxplugin..Joe72012-04-12 14:11:07
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Apr 12, 2012 2:09 pm

Men if i can make this... I will love u XDDD

Then i need to get the name of my text box... Yes i use a text box to show my score in the game.

How i can get the ID of the text box? :/ tyyyyyyy!
B
3
Posts: 7
Reputation: 339

Post » Thu Apr 12, 2012 2:15 pm

In the linked post is a screenshot of the javascript lines.. but sending score and.. is very easy with the built in ajaxplugin or if you want pass it per post with a custom ajaxpost plugin.. Joe72012-04-12 14:17:16
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Apr 12, 2012 2:30 pm

[QUOTE=Joe7] In the linked post is a screenshot of the javascript lines.. but sending score and.. is very easy with the built in ajaxplugin or if you want pass it per post with a custom ajaxpost plugin.. [/QUOTE]

Ty, i can't make this with a label...?

Because my porpuse is... Get the score at the final of the game... :/


c2runtime.js i add this:

function showScore()
{
     var myScore = document.getElementById('testScore');
     alert("ola");
     $.post("score.php", {score: myScore}, function(data) {
     alert(data);});

}

testScore is the ID of my text box.

now my php code:

<?
$score = $_POST['score'];
echo $score;
?>

html code:

<html>
<head>
<title>Untitled Document</title>
<script src="c2runtime.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write("<script src='jquery-1.7.1.min.js'>\x3C/script>")</script>
</head>
<body>
<button id="showID" onclick="showScore()">Show Score</button>
</body>
</html>Volh2012-04-12 14:56:37
B
3
Posts: 7
Reputation: 339


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest