Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

turning javascript function into widget (sugarcube 2)

$
0
0
Hey everybody!

I have a very similar issue to the one I had here, where @TheMadExile exile helped me out big time, so I tried to follow his steps as exactly as I could.

So, I have a javascript function which takes an array as an argument and fills a <div> with the array's shuffled contents. User can drag and drop the array elements into another <div> and rearrange them. The moment the array has been put in the right order, boolean "orderCorrect" turns true.
The point of the thing is to have language students put a dialog in the right order. You can see a working example here: http://deutschdetektiv.net/exp/dialog.html

In order to use the function as a widget in SC 2, I took the following steps:

1. script uses jQueryUI, so I pasted jQuery UI into the Story javascript
2. below jQuery UI, I pasted the desired javascript function (http://deutschdetektiv.net/exp/assets/js/script.js)
3. CSS was put in the Story Stylesheet
4. In order to call the function and set up the necessary html, I tried to adapt TME's widget from the above mentioned solution:
<<widget "dialog">>\
<<script>>
shuffler(State.variables.args[0]);
<</script>>
<div id="dialogs_container">
    <div id="left_container">
        <ul>

        </ul>
    </div>
    <div id="right_container">

    </div>
</div>

<<button "Check">>
<<replace "#result">><<if orderCorrect>>wisely<<else>>poorly<</if>>!<</replace>>
<</button>> &nbsp; \
You chose… <span id="result">?</span>
<</widget>>

5. Widget was used like this:
<<dialog ["Hey Bill", "Hey Joe.", "Can you pick me up at the airport tonight?", "What time?", "I should arrive at 6.30.", "Can´t make it until 7", "Ok, I´ll wait for you until 7. See you later", "See you."]>>


I get an
Error [tw-user-script-0]: undefined is not a function.

I thought it might be something scope-related and called windows.shuffler, which also didn't work.

Could somebody have a look through the code?

Thanks in advance,

euba

Viewing all articles
Browse latest Browse all 1844

Trending Articles