Interpolate Expressions into javascript

  • This is a proposal to be able to interpolate C3 expressions into the javascript snippets that are created inside the event sheet. I am not really sure what the syntax would look like, but i would guess it be something like this

    (assume we have 2 sprite object in the event sheet sprite:player and sprite:enemy)

    On sprite:player collision with sprite:enemy => *js* let variable = {{Player.8Direction.VectorX}}

    or

    On sprite:player collision with sprite:enemy => *js* let variable = @(Player.8Direction.VectorX)

    in the above example @(Player.8Direction.VectorX) / {{Player.8Direction.VectorX}} is replaced with the value from the event sheet. the event sheet picks the player that has just collided with the enemy and runs the java script, when the java script code resolves the interpolation, it will used the picked instances and grab the players 8direction vector x property and store in the javascript variable.

    something like this allows for fluid interaction with the event sheet and the javascript modules. as of now it's pretty easy to send data from javascript to the event sheet via function call, but there is no way to send data from the event sheet to your javascript.

    the draw back to this approach is that the syntax used is not real javascript. and it could confuse people who are not familiar with the concept of interpolation or javascript. it is also really complicated to implement and might hinder perf if you have to evaluate the js code every time it runs.

    this is just one solution though? any solution to this would be great. maybe instead of the interpolation thing there could be a plugin that you can use to interface and pass data to the javascript code. or specific system actions

    as a work around i have been using a proxy object, pretty much one invisible object with a few instances variables that i pull into the js could at the start, but this is limited to just those instance variables on that object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think this would be really confusing, since it mashes together two different syntaxes (expressions and JavaScript, which are written differently). It also looks super complicated to implement.

    The next release has some other features to help ease passing values to and from JS - in particular there are features to access both local and global variables from script, and a script function to set the return value of an event function, so you can make a function expression return a value from script.

  • Awesome. That is is going to be great! Thanks

  • It's great that there will soon be methods added to "ease passing values to and from JS." I can't see myself using JS to write a whole game, or reinvent the behaviors already in Construct. But I could see myself writing smallish JS routines to manipulate variables, which might be a less cumbersome approach than using events and actions, at least in some cases.

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