Setting min/max of a slider through a variable

Twine Version: 2.6.2, sugarcube 2 (also the latest one).

Heya! I’m someone who did a decent bit of python before and spent a lot of time writing in choice-script, so I naturally assumed that making a game on twine cannot be that difficult. Oh boy, was I wrong since I seem to be completely lost in the mysteries of JS (wtf is this :sob: ).

I’ve been following the HiEv’s tutorial on sliders (can’t link it) and got them to work without issue. The problem is, how would I go about setting min/max values of this:
<input type="range" id="slidetest" name="slidetest" min="0" max="100" value="25" class="slider" data-var="$test" oninput="SugarCubeInput(this)">
dynamically, through a variable? For example, have something like:
<<set _sliderMax to EXP/10>>
determine the upper limit for the range? I’ve tried doing min="0" max="_sliderMax", removind/adding brackets and stuff, but that obviously didn’t work.

I also googled it and tried to tinker with document.getElementById("slidetest").setAttribute("max", _sliderMax); in the <<script>> tag, but also failed in getting any results. I was probably doing something very stupid, but I would love it if someone could point me in the right direction. Because I feel like a caveman trying to make fire by hitting two rocks against each other :sweat_smile:

You can use the evaluation directive, i.e. @max="_sliderMax", like this:

 <input type="range" id="slidetest" name="slidetest" min="0" @max="_sliderMax" value="25" class="slider" data-var="$test" oninput="SugarCubeInput(this)">
1 Like

This worked, thanks a lot! I literally spent hours trying to figure this out yesterday, should’ve asked around sooner haha.