how to add javascripts functions to events

0 favourites
  • 3 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • 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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)