Help - Search - Members - Calendar
Full Version: Gmc Gml Syntax Coloring Ver: 2.1.1
Game Maker Community > General > The Community
Pages: 1, 2
gamer freak
GMC GML Syntax Coloring


Latest update: November 4, 2009

Syntax 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.

Download


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 Instructions
1. Get Greasemonkey for Firefox
2. Head to the download page and press the install button.

Opera Instructions
1. 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 Instructions
1. 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 Updates
Version 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
I can see this being useful for many people, good job.
B&B_Gaming
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
Mmm... tasty smile.gif.
Hockeyflyers
Doesn't work with opera.
Revel
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
QUOTE (Hockeyflyers @ Apr 7 2009, 10:25 PM) *
Doesn't work with opera.

That goes without saying. snitch.gif
Revel
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
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.
xot
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
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
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
Cool. I'm using it now.
pixelpig
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
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:
information

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
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
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
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
Fantastic idea!
pixelpig
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
Yeah, they could..There are some obvious drawbacks to that, though, like the bugs.
chaz13
This is brilliant, thanks.
Tahnok
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
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
very, very nice.
To bad I use Chrome now tongue.gif
If I go back to Firefox I will DL this for sure tho.
PickleMan
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
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
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
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
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
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
Yeah, like with sprites too...
gamer freak
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
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
Very, very nice.
gamer freak
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
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
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
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
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 &amp;
flexaplex
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 smile.gif
Tahnok
Very very nice updates! I now have this turned on all the time! Great work!
pixelpig
and now they can add it to the forums...?!?!?!
~Dannyboy~
I just installed this and I must say I'm impressed, nice work!
flexaplex
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
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
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
Version 2.0.5 Released!
Fixes:
  • Opera bug fixed: Opera uses chr(160) rather than the notation &nbsp;
paul23
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 &nbsp;

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
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. snitch.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.