Jump to content


Photo

Gmc Gml Syntax Coloring Ver: 2.1.2


  • Please log in to reply
98 replies to this topic

#1 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 08 April 2009 - 01:55 AM

GMC GML Syntax Coloring


Latest update: January 3, 2010

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
Posted Image
(click to enlarge)

Latest Updates
Version 2.1.2
  • Switched to GM8 coloring
  • Comments made italic

NOTE: This script is not guaranteed to work outside of Opera and Firefox 3.

Edited by gamer freak, 03 January 2010 - 08:07 PM.

  • 0

#2 Overman

Overman

    GMC Member

  • Banned Users
  • 884 posts

Posted 08 April 2009 - 02:00 AM

I can see this being useful for many people, good job.

#3 BBGaming

BBGaming

    Programmer

  • GMC Member
  • 2478 posts
  • Version:GM7

Posted 08 April 2009 - 02:04 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.
  • 0

Posted Image
Game Widgets
- Your pure-GML solution to API DLLs. Featured in Markup Magazine!

My Portfolio - All my good games and resources
Moved away from the forum - e-mail me if you need quick contact (hi_146@hotmail.com).


#4 Dr. Watz0n

Dr. Watz0n

    The Best Doctor

  • New Member
  • 351 posts

Posted 08 April 2009 - 02:24 AM

Mmm... tasty <_<.
  • 0

#5 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 08 April 2009 - 02:36 AM

Doesn't work with opera.
  • 0

#6 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 08 April 2009 - 02:55 AM

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).
  • 0

#7 makerofthegames

makerofthegames

    My last custom title

  • GMC Member
  • 7629 posts
  • Version:GM:Studio

Posted 08 April 2009 - 02:58 AM

Doesn't work with opera.

That goes without saying. <_<
  • 0

#8 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 08 April 2009 - 03:01 AM

Doesn't work with opera.

Are you talking about greasemonkey or the script itself?

Check this out:

http://my.opera.com/...monkey-in-opera
  • 0

#9 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 08 April 2009 - 03:37 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.
  • 0

gmc_signature.png


#10 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 08 April 2009 - 03:14 PM

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.c...taxhighlighter/

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.
  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#11 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 08 April 2009 - 10:21 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

argument
argument0
argument1
argument2
argument3
argument4
argument5
argument6
argument7
argument8
argument9
argument10
argument11

Edited by gamer freak, 04 November 2009 - 11:34 PM.

  • 0

#12 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 10 April 2009 - 09:52 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)

  • 0

#13 sanassar

sanassar

    GMC Member

  • GMC Member
  • 125 posts

Posted 11 April 2009 - 12:14 AM

Cool. I'm using it now.
  • 0
CODE
game_create(platform,online,shooter,like_halo);

We wish for this script everyday.(But if it is made I will use it and credit the people who made it .)
Well, now I'm making it, Just watch for all the new platformers made with GML coding. (EHEM! a script?)

I am a a Mega Geek in the GEEK test!

Moving forward, because we can't stop.

#14 pixelpig

pixelpig

    GMC Member

  • New Member
  • 805 posts

Posted 11 April 2009 - 05:16 AM

the biggest mistake i can see is the following:
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

Edited by pixelpig, 11 April 2009 - 06:03 AM.

  • 0
Click here to PM me if you need help.
Person #6, "Rolfero" -Put this in your sig but add 1 to the Person and mention who you got it from...(only on the GMC)
Decrypt This Challenge: Decrypt this file and PM me the outcome. You will appear on My sig :o (Hint, It has something to do with gamemaker)
upurload.com

#15 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 11 April 2009 - 05:31 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:
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:

if (global.fort == information)
{
  while (iffy)
  {
	 get_stiffy();
  }
  local.pin = "sin //poll";
}

Edited by flexaplex, 16 April 2009 - 12:03 AM.

  • 0
:]

#16 pixelpig

pixelpig

    GMC Member

  • New Member
  • 805 posts

Posted 11 April 2009 - 06:12 AM

horrah. ive gone through and fixed most of the errors including the global. one however global must be brown.
if(lol==12) {
show_info();
x=xprevious
}

Edited by pixelpig, 11 April 2009 - 07:30 AM.

  • 0
Click here to PM me if you need help.
Person #6, "Rolfero" -Put this in your sig but add 1 to the Person and mention who you got it from...(only on the GMC)
Decrypt This Challenge: Decrypt this file and PM me the outcome. You will appear on My sig :o (Hint, It has something to do with gamemaker)
upurload.com

#17 Bill23

Bill23

    GMC Member

  • GMC Member
  • 460 posts
  • Version:GM:Studio

Posted 11 April 2009 - 01:59 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).

Edited by Bill23, 11 April 2009 - 02:00 PM.

  • 0
Posted Image
Posted ImagePosted Image

#18 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1002 posts
  • Version:Unknown

Posted 11 April 2009 - 08:23 PM

Nice idea. If you can iron out the bugs this will be very useful.

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.
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:
$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: ^, &, |, ~.

Edited by xDanielx, 11 April 2009 - 08:26 PM.

  • 0

#19 edmunn

edmunn

    GMC Member

  • New Member
  • 1298 posts

Posted 11 April 2009 - 08:36 PM

Fantastic idea!
  • 0

Posted Image
Please PM / Email your suggestions!

15.4" Apple MacBook Pro Late 08', 2.8 GHz Intel Core 2 Duo, 4GB RAM, SSD
Mac OS X Lion


:)

#20 pixelpig

pixelpig

    GMC Member

  • New Member
  • 805 posts

Posted 12 April 2009 - 06:33 PM

just a thought now youve made this couldntthey just put:
<script type="text/javascript" src="http://userscripts.o...r.js"></script>
at the top of page in gmc?
  • 0
Click here to PM me if you need help.
Person #6, "Rolfero" -Put this in your sig but add 1 to the Person and mention who you got it from...(only on the GMC)
Decrypt This Challenge: Decrypt this file and PM me the outcome. You will appear on My sig :o (Hint, It has something to do with gamemaker)
upurload.com

#21 makerofthegames

makerofthegames

    My last custom title

  • GMC Member
  • 7629 posts
  • Version:GM:Studio

Posted 12 April 2009 - 07:48 PM

Yeah, they could..There are some obvious drawbacks to that, though, like the bugs.
  • 0

#22 chaz13

chaz13

    GMC Member

  • GMC Member
  • 4214 posts
  • Version:Unknown

Posted 12 April 2009 - 07:58 PM

This is brilliant, thanks.
  • 0

#23 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 13 April 2009 - 01:34 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.

Edited by Tahnok, 13 April 2009 - 01:35 AM.

  • 0

gmc_signature.png


#24 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 13 April 2009 - 01:58 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.
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#25 king_of_llamas

king_of_llamas

    KoL Games

  • New Member
  • 1079 posts

Posted 13 April 2009 - 02:35 AM

very, very nice.
To bad I use Chrome now :P
If I go back to Firefox I will DL this for sure tho.
  • 0
I am looking for team members! See my thread!
http://gmc.yoyogames...howtopic=504050

#26 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 13 April 2009 - 03:01 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.
  • 0

#27 Bill23

Bill23

    GMC Member

  • GMC Member
  • 460 posts
  • Version:GM:Studio

Posted 13 April 2009 - 11:28 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.
  • 0
Posted Image
Posted ImagePosted Image

#28 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 13 April 2009 - 11:44 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)
  • 0

#29 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1002 posts
  • Version:Unknown

Posted 13 April 2009 - 11:44 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:
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

Edited by xDanielx, 13 April 2009 - 11:45 PM.

  • 0

#30 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 14 April 2009 - 12:58 AM

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:

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?
  • 0

#31 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1002 posts
  • Version:Unknown

Posted 14 April 2009 - 10:12 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.
  • 0

#32 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 14 April 2009 - 10:19 PM

Yeah, like with sprites too...
  • 0

#33 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 15 April 2009 - 11:33 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

  • 0

#34 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 16 April 2009 - 12:04 AM

Very nice, it's much more usable now. Some of the incorrect highlighting which I mentioned is still there though:

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.

Edited by flexaplex, 16 April 2009 - 12:14 AM.

  • 0
:]

#35 BBGaming

BBGaming

    Programmer

  • GMC Member
  • 2478 posts
  • Version:GM7

Posted 16 April 2009 - 12:10 AM

Very, very nice.
  • 0

Posted Image
Game Widgets
- Your pure-GML solution to API DLLs. Featured in Markup Magazine!

My Portfolio - All my good games and resources
Moved away from the forum - e-mail me if you need quick contact (hi_146@hotmail.com).


#36 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 16 April 2009 - 12:13 AM

Very nice, it's much more usable now. Some of the incorrect highlighting which I mentioned is still there though:

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.

Edited by gamer freak, 31 July 2009 - 02:35 AM.

  • 0

#37 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 16 April 2009 - 12:15 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:

x = t/2;
global.this_is_now_not_highlighted = instance_create(x,y,obj);
not_highlighted_either = pi;

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.

Edited by flexaplex, 16 April 2009 - 12:21 AM.

  • 0
:]

#38 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 16 April 2009 - 01:40 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:

x = t/2;
global.this_is_now_not_highlighted = instance_create(x,y,obj);
not_highlighted_either = pi;

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.
  • 0

#39 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 16 April 2009 - 02:14 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.

Edited by flexaplex, 16 April 2009 - 02:17 AM.

  • 0
:]

#40 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 16 April 2009 - 02:50 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.


Ok, I fixed all of these, it turns out that the & bug was caused because the forum software converts it to &amp;
  • 0

#41 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 16 April 2009 - 03:08 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 :D
  • 0
:]

#42 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 16 April 2009 - 09:10 AM

Very very nice updates! I now have this turned on all the time! Great work!
  • 0

gmc_signature.png


#43 pixelpig

pixelpig

    GMC Member

  • New Member
  • 805 posts

Posted 16 April 2009 - 10:58 PM

and now they can add it to the forums...?!?!?!

Edited by pixelpig, 16 April 2009 - 11:00 PM.

  • 0
Click here to PM me if you need help.
Person #6, "Rolfero" -Put this in your sig but add 1 to the Person and mention who you got it from...(only on the GMC)
Decrypt This Challenge: Decrypt this file and PM me the outcome. You will appear on My sig :o (Hint, It has something to do with gamemaker)
upurload.com

#44 ~Dannyboy~

~Dannyboy~

    ~hoqhuue(|~

  • GMC Member
  • 2144 posts
  • Version:GM8

Posted 17 April 2009 - 12:28 AM

I just installed this and I must say I'm impressed, nice work!
  • 0

I cannot comprehend how intelligent people who spend much of their time designing and creating graphics, audio and code
refuse to believe that they themselves must have been designed and created.

Table Soccer | Yet Another Pacman | Astroblobs | GM Credits | GM Lego NXT | My Site

Posted Image


#45 flexaplex

flexaplex

    GMC Member

  • Global Moderators
  • 4814 posts
  • Version:GM8

Posted 17 April 2009 - 04:17 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.
  • 0
:]

#46 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 18 April 2009 - 01:52 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.
  • 0

#47 Recreate

Recreate

    Furry

  • GMC Member
  • 2992 posts
  • Version:GM:Studio

Posted 18 April 2009 - 05:21 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!
  • 0

If the post that you are reading was created prior to 2011. For the safety of the general public, It is not to be regarded under any circumstances.
Please don't ask me to join your group at anything.


#48 gamer freak

gamer freak

    Voice of Logic

  • New Member
  • 402 posts

Posted 21 April 2009 - 09:44 PM

Version 2.0.5 Released!
Fixes:
  • Opera bug fixed: Opera uses chr(160) rather than the notation &nbsp;

  • 0

#49 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 21 April 2009 - 10:41 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).
  • 0

#50 makerofthegames

makerofthegames

    My last custom title

  • GMC Member
  • 7629 posts
  • Version:GM:Studio

Posted 21 April 2009 - 10:58 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. ^_^
  • 0