3
\$\begingroup\$

I was wondering if in GameMaker it would be possible to allow people to code a small bit of the game in so that they then unlock that move/code?

Think of the game DLC Quest, in the way that you had to find a few coins and then you were able to buy the ability to jump, would it be possible to do this but instead of getting people to buy the ability to jump, get them to code it? (Only a little bit of code, of course, not an entire script?)

\$\endgroup\$
  • \$\begingroup\$ Yes, it is possible. You may need to write your own custom library that parses the text that the player inputs, but it is possible. \$\endgroup\$ – PixelArtDragon Sep 14 '16 at 19:34
6
\$\begingroup\$

What you're describing is effectively running gameplay mechanics in a virtual machine, which can simplify the process of authoring them and insulate against bad behaviour.

As it happens, a lot of games already do their gameplay like this under the hood! If you've ever heard developers talk about incorporating scripting languages like Lua, or node graph systems like Unreal's Blueprints, this is how they work.

These scripting methods let game/level/quest designers, who might have less hardcore coding experience than the programmers/developers on the team, quickly prototype and iterate on ideas, without recompiling after every change (sometimes editing live while the game is running), and (usually) without crashing the system when a gameplay script isn't quite right for the situation.

To go from this to what you describe, you'd just be adding a friendly user interface inside the game so the player can script this behaviour themselves. This could take the form of typing commands into a text editor, or snapping together blocks/modules, or wiring up a web of nodes, for example.

Once a gameplay script has been created, it's just raw data to feed through the game's scripting system, which doesn't need to care whether it came from a designer or from the player (apart from maybe giving designer scripts a higher level of trust/permissions to muck with aspects of the game state which you might decide to treat as off-limits to the player to maintain challenge and/or stability...)

There's a thriving genre of games exploring programming-by-the-player as a core mechanic in different ways, including...

For some insights into how you might implement such a virtual machine yourself, check out the Game Programming Patterns article on what they call the "Bytecode" pattern (although the same concepts apply even if you don't boil down to literal bytecode as your internal representation)

One thing to watch out for:

"...and have the programme check to see if its right"

This can be a bit more complicated than it may sound at first. You could literally check whether player's script == solution but this is pretty narrow & brittle. As any programmer or problem-solver knows, there's usually many ways to approach a task, and it's less fun if the player has to guess & regurgitate the one (or one of several) solutions the game considers "right," versus inventing their own.

Mechanically analyzing a program's code to determine whether it would have the desired behaviour is also often not feasible.

So usually the best way to check the player's script is to actually run it and see what happens - evaluating the player on the result of the program rather than the code itself (although you can still use code-based challenge stats to get players to try aiming for "fewest instructions used" or "solve without using [forbidden command]" etc)

\$\endgroup\$
-2
\$\begingroup\$

There is the function execute_string(string,arg1,arg2,...). The arguments are optional and are the same format as script arguments. Other than that, I do not know of any means to do it without coding your own custom language and parser. However, checking for correctness it not feasible. You can check for syntax errors in that the player will receive them, but that is it. Perhaps make a one-time checkpoint that will delete upon loading and be removed once the code is finished and that section completed? Then, if the game crashed they can just reload.

\$\endgroup\$
  • 2
    \$\begingroup\$ Letting users execute something that might crash the game sounds super annoying. \$\endgroup\$ – Tyyppi_77 Jun 8 '17 at 20:59
  • \$\begingroup\$ @Tyyppi_77 Most errors will just pop up with a box saying ignore and abort. Ignoring just ignores the ran code. Re-propmting the user to edit their code and confirm the feature after a couple frames or so will easily handle this. If they write something significant enough to only allow the abort option, then it is something nontrivial that probably wouldn't be done by someone intending to play the game properly. To be fair, there is one game which uses such a construct as a glorified cheat/modding box to let people mess with stuff. So, it's not totally unstable. \$\endgroup\$ – user64742 Jun 8 '17 at 21:05
  • \$\begingroup\$ tl;dr it won't always crash. It will just alert the player with a built in box at the time of execution (which might be every frame) \$\endgroup\$ – user64742 Jun 8 '17 at 21:05
  • \$\begingroup\$ Cheats/mods are a totally different thing, where I'd feel comfortable to say that the user is responsible for crashes. If a modder accidentally corrupts their saves with some unstable mod-code, it's the modder's fault, but if I type something into a gameplay-dialog code editor, I'd expect to be sandboxed out of touching anything critical. \$\endgroup\$ – Tyyppi_77 Jun 8 '17 at 21:24
  • \$\begingroup\$ @Tyyppi_77 refer to my statement of "I do not know of any means to do it without coding your own custom language and parser.". I might be great at using game maker but I am not going to write a whole language. \$\endgroup\$ – user64742 Jun 8 '17 at 21:30

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.