gamer freak
Apr 8 2009, 01:44 AM
GMC GML Syntax Coloring
Latest update: November 4, 2009Syntax highlighting can improve readability of code greatly. Sure there are tools (
[1] [2]) out there already to color gml, but they require the poster to copy and paste the code into the colorer, and then post the outputted bbcode and gml mess. I have developed a simple javascript solution to color any code in a codebox. Syntax coloring has been suggested to be implanted server-side, but was rejected every time because of increased server load. This causes no additional stress to the server.
NOTICE: Because this script interferes with the Rich Text Editor, you won't see your code colored if you preview it in Rich Text Editor mode. If you want to see colored code when previewing a post, use the standard editor, available to change in your control panel.To use this script you need to install Greasemonkey. Originally, Greasemonkey was for Firefox only, but because of its popularity it may be available on your browser. You can try to find Greasemonkey for your browser by searching for "Greasemonkey for *your browser here*" at a search engine.
Firefox Instructions1.
Get Greasemonkey for Firefox2. Head to the download page and
press the install button.
Opera Instructions1. Navigate to the Opera directory (In windows, this directory is "C:\Program Files\Opera")
2. Make a new folder called "scripts"
3. Download the script to the folder you just created.
4. Open Opera and go to Tools>Preferences>Advanced>Content>JavaScript Options>Choose. Then locate the directory you made earlier.
5. Restart Opera if needed.
Internet Explorer Instructions1. Download and install
IE7Pro (this is for IE 6,7, and 8 despite its name)
2. Download the script to your hard drive.
3. Rename the user.js extension to ieuser.js
4. Drag into Internet Explorer to install.
5. Restart Internet Explorer
Screenshot
(click to enlarge)
Latest UpdatesVersion 2.1.1
- Functions from GM8 RC added
- "then" added
NOTE: This script is not guaranteed to work outside of Opera and Firefox 3.
Overman
Apr 8 2009, 01:49 AM
I can see this being useful for many people, good job.
B&B_Gaming
Apr 8 2009, 01:53 AM
LOL, nice topic screenshot, btw.
Overall, very nice. If you could fix the errors (like the string, or function names are included in other variables, etc.) it'd be perfect.
Dr. Watz0n
Apr 8 2009, 02:13 AM
Mmm... tasty

.
Hockeyflyers
Apr 8 2009, 02:25 AM
Doesn't work with opera.
Revel
Apr 8 2009, 02:44 AM
QUOTE
This happens because of the order in which functions are checked.
Why don't you make it loop through the whole thing until the exact function is found? I didn't take a look at the script but this is merely a suggestion (not sure how much lag it would induce).
makerofthegames
Apr 8 2009, 02:47 AM
QUOTE (Hockeyflyers @ Apr 7 2009, 10:25 PM)

Doesn't work with opera.
That goes without saying.
Revel
Apr 8 2009, 02:50 AM
QUOTE
Doesn't work with opera.
Are you talking about greasemonkey or the script itself?
Check this out:
http://my.opera.com/Contrid/blog/2007/02/1...monkey-in-opera
Tahnok
Apr 8 2009, 03:26 AM
Very nice, but still buggy. When I clicked on
this topic (which happened to be the first one I clicked after installing the script), it locked up and eventually gave me an error message. Apparently it went into an infinite loop. Great idea though! Once the bugs are worked out I'll have it turned on all the time.
I'm glad this is being worked on. I had a similar idea but I don't know enough about GreaseMonkey. I would suggest trying to do something with this:
http://code.google.com/p/syntaxhighlighter/I used it on my forum when I started it. I replaced it because it was a little slow with Firefox at the time (18 months ago) but that may have improved.
gamer freak
Apr 8 2009, 10:10 PM
QUOTE (Tahnok @ Apr 7 2009, 10:26 PM)

Very nice, but still buggy. When I clicked on
this topic (which happened to be the first one I clicked after installing the script), it locked up and eventually gave me an error message. Apparently it went into an infinite loop. Great idea though! Once the bugs are worked out I'll have it turned on all the time.
This is because I already ran my code through one of the colorers that I mentioned in my first post. I have fixed this and one other bug that could cause eternal loops.
Updates in Version 1.0.1:
- Crash fixed on code that has BBcode already applied to it
- Crash fixed on single line comments that doesn't have a line break after it
CODE
argument
argument0
argument1
argument2
argument3
argument4
argument5
argument6
argument7
argument8
argument9
argument10
argument11
gamer freak
Apr 10 2009, 09:41 PM
Version 1.1.1 Released!
Updates:
- Crash fixed for code that isn't really code.
- Added option to turn off code highlighting (see topic post)
sanassar
Apr 11 2009, 12:03 AM
Cool. I'm using it now.
pixelpig
Apr 11 2009, 05:05 AM
the biggest mistake i can see is the following:
CODE
draw_text_color()
but apart from that its good. perhaps you should check in size order?
you have two 'codehighlight("d3d_set_projection","dark_blue");' s
flexaplex
Apr 11 2009, 05:20 AM
Very nice, I will definitely be using this and hopefully this will silence those people that are always wanting in-built color coding in the gmc.
There is obviously a few bugs in the colouring still but it is still worth using even with them. Some I have seen:
Words like this will get highlighted:
in
formation
global is being coloured brown as a constant instead of black bold for special word. local is not being highlighted at all.
If you use "//" as a string it misreads it to comment the line instead.
Braces {} and semi-colons ; are not highlighted bold.
---------------------------------
Test section:
CODE
if (global.fort == information)
{
while (iffy)
{
get_stiffy();
}
local.pin = "sin //poll";
}
pixelpig
Apr 11 2009, 06:01 AM
horrah. ive gone through and fixed most of the errors including the global. one however global must be brown.
CODE
if(lol==12) {
show_info();
x=xprevious
}
Bill23
Apr 11 2009, 01:48 PM
I haven't downloaded this yet (I will eventualy though). Instead of checking for "while" (for example) and hilighting that, why not search nfor " while ", with a space on each side. That way, if I have a variable called "while_not" the while in it won't be highlighted.
Edit: Just realized that wouldn't work because of "=",";" and words at the start of a line. Maybe you could check for all of those (Iand any I happened to forget).
xDanielx
Apr 11 2009, 08:12 PM
Nice idea. If you can iron out the bugs this will be very useful.
QUOTE
why not search nfor " while ", with a space on each side
Tokenizing code based on spaces only isn't such a good idea -- that will fail on code that lacks whitespace, e.g.
CODE
while(cond){statement;}
A better solution for simple languages like GML is to use a list of token delimiters. Here's what I used for GML2Color:
CODE
$list_endchars = array(" ",".","(",")","\n","\r",";",",","<",">","=","+","-","*","/","[","]","{","}",":","!");
Let me know if you'd like any help.
EDIT - in hindsight, even that list is incomplete. A few that I missed: ^, &, |, ~.
edmunn
Apr 11 2009, 08:25 PM
Fantastic idea!
pixelpig
Apr 12 2009, 06:22 PM
just a thought now youve made this couldntthey just put:
<script type="text/javascript" src="http://userscripts.org/scripts/source/46212.user.js"></script>
at the top of page in gmc?
makerofthegames
Apr 12 2009, 07:37 PM
Yeah, they could..There are some obvious drawbacks to that, though, like the bugs.
chaz13
Apr 12 2009, 07:47 PM
This is brilliant, thanks.
Tahnok
Apr 13 2009, 01:23 AM
Nice updates, but still buggy. For example, it still changes the color of "speed" in a custom variable called "speedUpdate", or bolds the "or" in a variable called "armor". It's quite annoying to look at, but still understandable.
Of course, that's on top of the known bug of highlighting only parts of function names, which is also something that really needs fixing.
Hach-Que
Apr 13 2009, 01:47 AM
He could just check whether the function name is proceeded by a character such as ( or a space. Same with the keywords that are getting highlighted.
king_of_llamas
Apr 13 2009, 02:24 AM
very, very nice.
To bad I use Chrome now

If I go back to Firefox I will DL this for sure tho.
PickleMan
Apr 13 2009, 02:50 AM
To fix the function and variable collision, you can look to see if it has the ( and ) after it, since game maker requires those.
Bill23
Apr 13 2009, 11:17 PM
QUOTE (PickleMan @ Apr 12 2009, 10:50 PM)

To fix the function and variable collision, you can look to see if it has the ( and ) after it, since game maker requires those.
No GM doesn't require those.
PickleMan
Apr 13 2009, 11:33 PM
Oh, Gm needs to be more strict...
Well, you can check to see if the variable already exists... (You need to interpret the code)
xDanielx
Apr 13 2009, 11:33 PM
Bill is right. You can store scripts (or more precisely, the variables holding their indices) in variables, pass them to functions, etc. A few examples:
CODE
some_var = some_script; // valid
some_junk = 3 * abs(some_script) + 42; // odd, but valid
script_execute(some_script); // also valid
script_execute(some_var); // still valid
PickleMan
Apr 14 2009, 12:47 AM
QUOTE (xDanielx @ Apr 13 2009, 06:33 PM)

Bill is right. You can store scripts (or more precisely, the variables holding their indices) in variables, pass them to functions, etc. A few examples:
CODE
some_var = some_script; // valid
some_junk = 3 * abs(some_script) + 42; // odd, but valid
script_execute(some_script); // also valid
script_execute(some_var); // still valid
Kinda like Perl?
xDanielx
Apr 14 2009, 10:01 PM
Sort of. I wouldn't say that GM really supports first-class functions since variables can only store script indices (we need script_execute to interact with the scripts themselves) and there are no lambda constructs or anonymous functions in general, but at least it's possible to execute scripts without writing out their identifiers explicitly.
PickleMan
Apr 14 2009, 10:08 PM
Yeah, like with sprites too...
gamer freak
Apr 15 2009, 11:22 PM
QUOTE (Tahnok @ Apr 12 2009, 08:23 PM)

Nice updates, but still buggy. For example, it still changes the color of "speed" in a custom variable called "speedUpdate", or bolds the "or" in a variable called "armor". It's quite annoying to look at, but still understandable.
Of course, that's on top of the known bug of highlighting only parts of function names, which is also something that really needs fixing.
This should now be fixed.
Version 2.0 Released!
Updates:
- Total re-write using xDanielx's method, lots of bugs should disappear
flexaplex
Apr 15 2009, 11:53 PM
Very nice, it's much more usable now. Some of the incorrect highlighting which I mentioned is still there though:
QUOTE
global is being coloured brown as a constant instead of black bold for special word. local is not being highlighted at all.
If you use "//" as a string it misreads it to comment the line instead.
Braces {} and semi-colons ; are not highlighted bold.
Can only see minor things like that now though.
B&B_Gaming
Apr 15 2009, 11:59 PM
Very, very nice.
gamer freak
Apr 16 2009, 12:02 AM
QUOTE (flexaplex @ Apr 15 2009, 06:53 PM)

Very nice, it's much more usable now. Some of the incorrect highlighting which I mentioned is still there though:
QUOTE
global is being coloured brown as a constant instead of black bold for special word. local is not being highlighted at all.
If you use "//" as a string it misreads it to comment the line instead.
Braces {} and semi-colons ; are not highlighted bold.
Can only see minor things like that now though.
I fixed the local and global problem I took the lists accidentally from one of my older scripts. I could possibly put in bold braces, dots, semi-colons in the future though.
flexaplex
Apr 16 2009, 12:04 AM
Cheers.
Came across a new bug though. When using a division sign it seems to comment out the entire rest of the code after it:
CODE
x = t/2;
global.this_is_now_not_highlighted = instance_create(x,y,obj);
not_highlighted_either = pi;
QUOTE
I could possibly put in bold braces, dots, semi-colons in the future though
I Hope you do, I think it adds to the colouring rather a lot still.
gamer freak
Apr 16 2009, 01:29 AM
QUOTE (flexaplex @ Apr 15 2009, 07:04 PM)

Cheers.
Came across a new bug though. When using a division sign it seems to comment out the entire rest of the code after it:
CODE
x = t/2;
global.this_is_now_not_highlighted = instance_create(x,y,obj);
not_highlighted_either = pi;
QUOTE
I could possibly put in bold braces, dots, semi-colons in the future though
I Hope you do, I think it adds to the colouring rather a lot still.
Ok, I've fixed the division sign bug, it was caused a bad switch and case statement, which I assumed to work the same way as it does in Game Maker, but it doesn't. I've added bold-ing for ; : { } .
I haven't added bold-ing for double quotes because they look like a block if their are turned bold, and it might look "uneven" if I did it just to the single quotes.
flexaplex
Apr 16 2009, 02:03 AM
It's looking great now! It doesn't really matter about the quotes.
I've looked through a load of script and tested most things to try and find any more problems. A found a couple more:
! sign is not bolded
continue is not bolded
exit is not bolded
there is error with & sign, it is putting &; instead. I presume this is a simple typo on your behalf.
I doubt there will be many more problems after these though, I tested everything I could think of.
gamer freak
Apr 16 2009, 02:39 AM
QUOTE (flexaplex @ Apr 15 2009, 09:03 PM)

It's looking great now! It doesn't really matter about the quotes.
I've looked through a load of script and tested most things to try and find any more problems. A found a couple more:
! sign is not bolded
continue is not bolded
exit is not bolded
there is error with & sign, it is putting &; instead. I presume this is a simple typo on your behalf.
I doubt there will be many more problems after these though, I tested everything I could think of.
Ok, I fixed all of these, it turns out that the & bug was caused because the forum software converts it to &
flexaplex
Apr 16 2009, 02:57 AM
Well it all seems to be working perfectly fine now, good job.
I personally think it should now get pinned otherwise I see this getting bumped down and lost, which would be a shame because it is a great and easy to use feature. If I was you after it goes off the first page I would ask KC about pinning it.
Anyway I'm happy this has finally been made
Tahnok
Apr 16 2009, 08:59 AM
Very very nice updates! I now have this turned on all the time! Great work!
pixelpig
Apr 16 2009, 10:47 PM
and now they can add it to the forums...?!?!?!
~Dannyboy~
Apr 17 2009, 12:17 AM
I just installed this and I must say I'm impressed, nice work!
flexaplex
Apr 17 2009, 04:06 PM
I've just seen something else which this script does which is to expand the code used in codebox tags! This is great cause I hate the stupid scrolling, makes things so easier to read without it.
gamer freak
Apr 18 2009, 01:41 AM
Just a quick update for IE users, this script will work with IE Pro's Greasemonkey capability, but the styles are defined in a way that IE doesn't seem to understand in the script. I'll have to find a better way to define styles.
Recreate
Apr 18 2009, 05:10 AM
Oh wow,this is neat.
I have seen some people color coding the test themselves,but it gets hard after a few lines,With this,there is no need to do that!
gamer freak
Apr 21 2009, 09:33 PM
Version 2.0.5 Released!Fixes:
- Opera bug fixed: Opera uses chr(160) rather than the notation
paul23
Apr 21 2009, 10:30 PM
QUOTE (gamer freak @ Apr 21 2009, 11:33 PM)

Version 2.0.5 Released!Fixes:
- Opera bug fixed: Opera uses chr(160) rather than the notation
I'm wondering: can't this be made faster? - I mean long post now almost "crash" the browser (it halts for a few seconds at for example the "gmc/c++ project" post in the dlls forum).
makerofthegames
Apr 21 2009, 10:47 PM
Note: You may not beable to see the following script if you are using his browser script.
PRE
with(obj_player) {
if (iPistol_Ammo < 5) {
iPistol_Ammo=5; //Changes ammo to 5 if over 5, because 5 is the limit.
}
if (iPistol_Ammo > 0) {
iPistol_Ammo=0; //Changes ammo to 0 if less than 0, because you shouldn't have negitive ammo.
}
}If you are using the script, turn it off then look again; does it look different? If so - - - I think I just spotted a bug.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.