HTML Element - How do I Read Inputs

0 favourites
  • 6 posts
From the Asset Store
Supports keyboard, mouse and gamepads. Supports several gamepads at once.
  • Hi, everybody!

    I've played around a little with the (built-in) HTML Element, and it's absolutely the best way to handle UIs and menus in Construct. You can make logical layouts, position and format elements with ease, and intuitively read out variables as they change.

    But.

    I can't figure out how you're supposed to take input FROM elements and feed them TO the game logic. For example, say you have an element representing a sound menu, and a few lines in is a volume slider. When a user moves the slider, it should change a "volume" global variable.

    I keep thinking there should be a "get attribute" expression, where you specify the attribute and selector to get back the value as a string. (Imagine the inverse of the "set attribute" action.) The best I've been able to do so far is having a separate form object and setting it focused when a particular HTML ID is clicked, but that's too janky for anything but internal tools.

    Does anybody know if this is possible right now, and if so, how it's supposed to work?

    Thanks ahead of time!

    Caleb

    Tagged:

  • Hi caleb,

    You can use scripts in the sheet to assign/get values.

    For example:

    runtime.globalVars.volumeNumber = document.getElementById("volume").value;

    That gets the value of the element id "volume" and assigns it to a global variable named volumeNumber.

    You can use localVars too for local variables.

    Edit:

    More info here -- construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

  • Thanks, plazatin. I was half afraid someone was going to say scripting, but sounds like that's the way to go, and now I'm finally out of excuses not to jump in. I'll update when I get it working.

    EDIT:

    My. Gosh. That's so flippin' easy! There's predictive text and color coding and everything. I should have tried this forever ago!

    Thanks again, plazatin. If Bennetts Skunkworks Project B ever goes public, you get a mention in the credits.

  • There would be another way but a bit more convoluted. You could use links in the html to send posts or gets to a php script then use Ajax to send requests back to the php. If you're interested I just posted in tools earlier a html element that loads news via Ajax requests to a website.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Welcome. Also, don't be intimidated by scripting, Javascript is pretty nice and there's the ton of resources online on top of the documentation here. Try it out, and you might find that it's not as intimidating as you thought.

    Wish you luck in your Skunkworks Project!

    Thanks, plazatin. I was half afraid someone was going to say scripting, but sounds like that's the way to go, and now I'm finally out of excuses not to jump in. I'll update when I get it working.

    EDIT:

    My. Gosh. That's so flippin' easy! There's predictive text and color coding and everything. I should have tried this forever ago!

    Thanks again, plazatin. If Bennetts Skunkworks Project B ever goes public, you get a mention in the credits.

  • Javascript is good, but it would be better without it. In the end, the implementation could be like this expression.

    HTMLElement.Value("#volume")

    HTMLElement.Text("span")

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