how to add javascripts functions to events

Get help using Construct 2

Post » Sat Jun 16, 2012 9:34 pm

hello. i created an event that starts a game when user clicks an image
i want to add a javascript function before that events (or, as the first command of the event) that makes an ajax request to the server about opening a new game, then waits for the server to reply the game_id, and then continue with the rest of the event.

i come from the world of javascript and i have pretty good knowlagde of how things are done. (i just havn't found the feature in the construct2 editor...)

and i want to do it without the need to start reading and understanding the entire generated construca code.

little example of what i mean

// pseado-code of how it is now
"function (){
            game_id = null
            number_of_balls = 4
            gender = 'male'
            etc...
            startShootingBalls()
}"

// as i want it to be
"function (){
            $.post('/new_game',function(response) {
                        game_id = response.game_id
                        number_of_balls = 4
                        gender = 'male'
                        etc ...
                        startShootingBalls()
            }
}"

is there an easy way to do it?

thanks
B
23
S
5
G
4
Posts: 48
Reputation: 5,197

Post » Sat Jun 16, 2012 10:27 pm

Try using the AJAX object. Try to avoid thinking in code, it probably won't help much - Construct 2 can do most things you need to in events.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sun Jun 17, 2012 11:09 am

i want to connect to a server that can save details on the user: score, badges, friends that he invites to the facebook game...
how can i do this?
B
23
S
5
G
4
Posts: 48
Reputation: 5,197


Return to How do I....?

Who is online

Users browsing this forum: Kagubro and 15 guests