Windows Getting a custom code snippet added to the menu

FacesOfMu

Member
Hey all,

I typed out this whole message with a question for help and advice on it, but then something clicked, I tried it, and got it to work! It seemed sad to waste the post, especially if there's another user out there in the future that could really use what I learned. Seems like there could be a good reason to have a new forum prefix for these kinds of discoveries and solutions!

So, after some weeks of trying to ignore a looming architectural problem, I decided to bite the bullet and do a mass reformat of my code (Is there a word or meme for when programmers have to do this??).

Where previously I didn't use them, Code Snippets were going to be invaluable. I did some research on this yesterday and it took me a loooong time to find any docs on Code Snippets. Finally found it here: https://docs2.yoyogames.com/source/_build/2_interface/1_editors/scripts.html

I tried a few times to add my own option to the right click > Code Snippets list. After an hour or so it just seemed like there were some special rules or methods that I wasn't aware of

Here's what's said in the docs:
Another very handy tool you have at your disposal when editing your scripts is the use of Code Snippets. By pressing F4 you will open the code snippet pop-up, which permits you to select one of the commonly used code methods. You can also define your own code snippets if you want to, saving them to the directory where you installed GameMaker Studio 2 in the following location: \GameMaker Studio 2\TextEditor\snippets.txt. You can edit this file with any text editor following these rules:

  • Each snippet is on a separate line (there should be no blank lines).
  • Each snippet starts with the name of the snippet (which is what is shown in the menu) followed by the colon :)) followed by the actual snippet of code.
  • Use $ for a newline and put the text that needs to be selected first between | symbols.
See the examples that are already in the file to see how it is set up following the rules above, and it is strongly recommended that you make a backup of it before you start changing anything, and also back up any edits you make to the file, as should re-installing the program or updating it revert the changes that you make you can use the backup to redo them again.
Note, I'm running Windows.

So I did a file search and found snippets.txt file and added a new line as so:
Code:
D - Debug:///@arg debug $ var debug        = argument[1]; $var tabs        = debug[1]; $debug            = debug[0]; $if(debug) show_debug_message(s_t(tabs) + "Start of ") $tabs++;
I didn't use the | | markers as I only wanted to insert this code, not paste over some (though I added it in my last attempt to make this appear).
After every edit I would restart GMS2, and the snippets wouldn't change.

Today, what clicked was that I seem to have two installs of GMS2: One that I downloaded from yoyogames directly as a trial and activated (installed to C:\Program Files\GameMaker Studio 2\), and one that I had linked to Steam (C:\Program Files (x86)\Steam\steamapps\common\GameMaker Studio 2 Desktop\).

I realised I was editing the snippets.txt file of one while running the other. I did some edits, ran each GMS2 and saw my new lines in the menu. Hurrah!

Now I have a copy of snippets.txt on my desktop and when I change it I have a batch file that copies it to both locations. I could just delete one of the GMS2 shortcuts on my desktop to make sure I always run the same program every time, but I can't remember how got to having two and I don't want to forget about the other.

I hope this helps someone else!
 
Top