Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Best way to send twine-data to server for further processing (formmailer, etc.) [SC2]

I am designing a psychological-test-like-game (kind of in the tradition of TLC). As a feedback, I want users to receive an email with the interpretation of their given answers.

So basically, twine variables (arrays, strings and numbers) should be sent to a server, where they are interpreted and sent via a form mailer script.

What is the best way to accomplish this? I was thinking that an html form with hidden elements (containing the variables) would be easiest, but then I´d have a problem with the arrays.

I checked out the google drive macro, which can write twine data into a google spreadsheet, but I´d rather go for a more direct approach on my web hosting service.

Thanks in advance,

euba

Comments

  • euba25 wrote: »
    What is the best way to accomplish this? I was thinking that an html form with hidden elements (containing the variables) would be easiest, but then I´d have a problem with the arrays.
    A form processed server-side would probably would be the easiest, yes.

    Why do you think that you'd have issues with arrays? Simply encode them in a manner which is easy to decode server-side.

    EXAMPLES

    You could JSON+URI encode them. For example:
    <<='<input type="hidden" value="' + encodeURIComponent(JSON.stringify($array)) + '">'>>
    
    To reverse that server-side, simply URI decode the value and then parse the JSON—both of which should be easily enough done in whatever language is used server-side.


    Alternatively, you could join the members with a character which will not, or cannot, appear within them as a delimiter. Though, again, you should probably URI encode the value before printing it as part of the hidden element. For example:
    <<='<input type="hidden" value="' + encodeURIComponent($array.join('|')) + '">'>>
    
    To reverse that server-side, simply URI decode the value and then split on the delimiter character.


    There are other ways you could do this, but those are probably the two easiest. I'd go with the JSON version if at all possible, since that will give you the greatest fidelity.
  • Great. Thank you!
Sign In or Register to comment.