Lack of @import in editor? Part 2

IFforClassroom
02 Apr 2023, 23:21

Here's ChatGPT's best stab at making it easy to import JavaScript or curly bracket Squiffy code. It doesn't understand @set attributes. I think you have to keep JavaScript in separate .txt/.sq files from curly bracket Squiffy code, but ChatGPT will keep playing with that.

Step 1
Make .txt or .sq files. These files can each contain JavaScript or curly bracket Squiffy code. Not both, for now.

Step 2
Save your txt. or .sq files in in a zip folder. Upload it to http://textadventures.co.uk/submit/submitfile

Step 3
Open whatever tool you use to make Squiffy games. I use the editor. put this section anywhere you want. replace the url from the @set API := line with the url that http://textadventures.co.uk/submit/submitfile gave you. And no space before or after "/".

[[IMPORT]]:
@set API := https://media.textadventures.co.uk/games/RnNu0cyO_UWw226YSa-B4A/Squiffy%20API%20Demo / {import}.txt
    var API = squiffy.get("API");
    var next = squiffy.get("next");
    $.get(API)
    .done(function (data, status, xhr) {
        try {
            squiffy.ui.processText(data);
        } catch (e) {
            squiffy.set("error", e.message);
        }
        try {
            eval(data);
        } catch (e) {
        }
        squiffy.story.go(next);
    })
    .fail(function (data, status, xhr) {
        squiffy.set("data", status);
        squiffy.story.go(next);
    });

Step 4
The following method for importing JavaScript and curly bracket Squiffy code now works:

@title Squiffy API Demo
@start Import DateTime


[[Import DateTime]]:
@set import = DateTime
@set next = English Conventions
    squiffy.story.go("IMPORT");


[[English Conventions]]:
@set import = Process DateTime
@set next = test
    squiffy.story.go("IMPORT");


[[test]]:
    squiffy.set("week", Math.trunc(get("week")));


{@0=@0}
It's {hour}:{if 0=0:0}{else:‍}{minutes} {AMPM} in the {TimeOfDay} on {xday}, {Month} {datenum}{th}, week {week} of {year}.

Now if somebody wants to streamline this further, say, by

  • translating this into something story.js can understand
  • eliminating the @set next and squiffy.story.go()
  • making it possible to have JS and curly code in the same .txt/.sq

that would be very cool of them.

P.S. Some of the details won't work unless you're using Squiffy 5.1.4 by mrangel


IFforClassroom
28 Apr 2023, 01:21

🦗


Concordia English Language Academy
12 May 2023, 01:05

I know you're asking for help, but I don't know much, and I actually have a question for you.

Is there a secure way to import my students' names ? I want their names to appear randomly in a game.


IFforClassroom
15 May 2023, 04:42

I guess when you publish your game you can select "Only people I give the link to." But that's still not very secure. Anybody who opens the game can still "inspect page source." I made an API of nicknames that my students chose for themselves as well as an id number that's only used in my classes. I would not recommend using any real names or identifying information. Sorry to not be more helpful.