2
\$\begingroup\$

I'm trying to create a hacking game where players design programs and hack other people's stuff. Users write their programs in JavaScript. I'm aiming for a hackmud-style system, where user programs can interact with the host game, for example, transferring funds.

Trouble is, I don't know where to start. I'm using C# to develop my game. Everything I found online for using JavaScript in C# interprets the script as a program on the host computer. This is a problem because I don't want the user code to have access to the host computer, just the game. Is there a standard architecture for a project like this?

\$\endgroup\$
  • \$\begingroup\$ That's a nice question! However I wouldn't proceed like this. Program the game in whatever language you like better. As for user input you could use a template and parse it instead of actual "code". \$\endgroup\$ – Valamorde Jan 15 '18 at 9:46
  • \$\begingroup\$ Example: you could have a predefined snippet like: ''connectTo.bank({username: test1, password: test2});'' and parse it to get desired values. \$\endgroup\$ – Valamorde Jan 15 '18 at 9:55
  • 2
    \$\begingroup\$ @Valamorde Writing an own interpreter for a scripting language is a project which seems easy at first glance, but becomes amazingly complicated when you start looking at the details. Using an existing interpreter is almost always a better idea. \$\endgroup\$ – Philipp Jan 15 '18 at 12:19
1
\$\begingroup\$

I would recommend using Microsoft's ClearScript. This includes an examples page that will provide the basics of setting up an interface where the script will interact with your game.

I have to admit to not having used it myself (though I have considered it in the past for a game, and have used C# scripting using Roslyn instead), but looking at the Examples and FAQTutorial pages reveal that it should be a simple task to implement a way for a users script to interact with your game.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.