How do I access JS object in C2?

0 favourites
  • 6 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Is it possible to access raw JS object properties in C2?

    I've fetched the object from AirConsole message. The object ATM is hardcoded and looks like below

    { touch: 999 }[/code:34yoe00s]
    
    I'm trying to fetch this property but can't really find the way. So I tried to convert it to string so I could parse it, but it's also not that easy. Does C2 have some security parsing before? Is it possible to access/strinfigy  JS object anyhow?
    
    This is the latest thing I've tried, but it retuns 0;
    [img="http://i67.tinypic.com/2qw32ti.png"]
  • If AirConsole.Message is "{ touch: 999 }" then you could do this the get the value of "touch"

    Browser.ExecJS("var a="&AirConsole.Message&";a.touch")

  • I just described the object's body. But it's not a string. It's an object. That's the point...

    EDIT: ah wait... right... I'll try that. Thanks

  • Meh this is frustrating...

    When AC sends this

    airconsole.message(AirConsole.SCREEN, {
                "message": "start"
              });[/code:16awribh]
    
    I can easily read the value ("start") just by reading [i]AirConsole.Message[/i] in C2.
    
    But when AC sends this
    [code:16awribh]
    airconsole.message(AirConsole.SCREEN, {
                "message": {
                  touch: 999
                }[/code:16awribh]
    
    ... then [i]AirConsole.Message[/i] returns "[object Object]", which is fine, but can't fetch the properties. 
    
    [i]Browser.ExecJS("var a="&AirConsole.Message&"; a.touch")[/i] and all other ways I have tried always return "0".
    
    Any other suggestions? I'm kinda out of ideas.... thanks
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll probably want to make a plugin to do this, or at least modify the one you use. C2 only handles strings or numbers, so the expression as is wont do it.

  • Right... it handles only string or numbers... I don't really have time to study C2 plugin SDK now. I code controller manually so I figured out that the best way would be to always send just a text which will be simply C2 dictionary JSON.

    Thanks for clarification R0J0hound

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