Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   GS2 Beautifier (https://forums.graalonline.com/forums/showthread.php?t=134264161)

fowlplay4 08-10-2011 04:17 AM

GS2 Beautifier
 
Disclaimer

If you already style your own code as you write it then you don't really need this unless you frequently find yourself styling other people's code. I.e: Forum helpers such as myself.

The Problem

If your code looks like this when you post it:

PHP Code:

//#CLIENTSIDE
function onCreated() {
if(
etc){
dostuff();
}
else
{
youneedthis();
}


You need to beautify/style your code before anyone else will be able to understand and read it properly. Readable code makes it much easier for others who want to help you.

After running it through the beautifier you're left with this:

PHP Code:

//#CLIENTSIDE

function onCreated() {
  if (
etc) {
    
dostuff();
  } else {
    
youneedthis();
  }


As you learn how to script and program, you'll also get into the habit of indenting and styling your own code as you write but until then you can just use the GS2 Beautifier before posting/sharing your code.

The Quick Fix

After witnessing an issue caused by the jsbeautifier.org and actual GS2 code I have forked the project, and modified it to properly support the following:

- public functions
- //#CLIENTSIDE
- Concatenation Symbols: @=, @, SPC, NL, TAB

I've also changed the default settings on the site to the style most experienced scripters use:

- Indent with two spaces
- Braces with control statements

PHP Code:

//#CLIENTSIDE
function onCreated() {
  echo(
"This is how it styles it...");


Instructions

1. Go to http://fp4.ca/gs2beautifier
2. Paste your code into the box
3. Click 'Beautify GS2'

DustyPorViva 08-10-2011 04:21 AM

Highlight shows #CLIENTSIDE has a space after it in the beautified code block. Does this generate that? If so you might want to fix that because I'm pretty sure that breaks scripts.

WhiteDragon 08-10-2011 04:23 AM

Great!

fowlplay4 08-10-2011 04:25 AM

Quote:

Originally Posted by DustyPorViva (Post 1662800)
Highlight shows #CLIENTSIDE has a space after it in the beautified code block. Does this generate that? If so you might want to fix that because I'm pretty sure that breaks scripts.

Good catch, fixed.

Tolnaftate2004 08-10-2011 06:45 AM

PHP Code:

(@something

becomes
PHP Code:

( @ something

which just looks... odd.

fowlplay4 08-10-2011 06:58 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1662830)
which just looks... odd.

I agree, fixed.

Emera 08-10-2011 10:45 AM

+ rep. Very nice and very handy. Thank you!

Crow 08-10-2011 10:58 AM

Gotta spread some rep first. Nice work.

Rave_J 08-13-2011 11:29 PM

easier way is
just copy the script open level editor
and put it in a npc and hit the style button and it will put it neatly


also i notice
level editor since v6 thing stefan updated
level editor will read most of gs2 from a npc
just dnt make it server side to use
but it will read it clientside just fine

Deas_Voice 08-13-2011 11:36 PM

looking good (:

have to spread the love before i can give you some..

edit; just noticed that your triggerclient is missing the "gui" parameter

fowlplay4 08-13-2011 11:40 PM

Quote:

Originally Posted by Rave_J (Post 1663424)
easier way is
just copy the script open level editor
and put it in a npc and hit the style button and it will put it neatly

No it isn't, and all that does indent your code.

GS2 Beautifier way: Open browser, go to website, paste code, click button.
Level Editor way: Open level editor, drag npc on to level, open npc script window, paste code, click button.

If you even looked at the example you would see that it does so much more than the level editor does.

Quote:

Originally Posted by Deas_Voice (Post 1663425)
edit; just noticed that your triggerclient is missing the "gui" parameter

It isn't a strict requirement to put "weapon" or "gui" you can just put the weapon's name and it will still work.

Rave_J 08-13-2011 11:47 PM

i never say that it didnt do more
i was stating there was a easier way maybe some people prefer to do just to set the style of ur code nicer. and i was saying u can gs2 script in level editor to a point just nothing on server side which is guis,systems ect like that just basic scripting for the levels to at least people can get the feel of it and somewhat use to it

but ur gs2 beautifier is nice dont get me wrong would be cool if u can add where it tells u errors
and suggestions on how to fix

Crow 08-14-2011 12:04 AM

Quote:

Originally Posted by Rave_J (Post 1663427)
i never say that it didnt do more
i was stating there was a easier way maybe some people prefer to do just to set the style of ur code nicer. and i was saying u can gs2 script in level editor to a point just nothing on server side which is guis,systems ect like that just basic scripting for the levels to at least people can get the feel of it and somewhat use to it

but ur gs2 beautifier is nice dont get me wrong would be cool if u can add where it tells u errors
and suggestions on how to fix

I suggest you get the **** out of subforums you do not belong in.

fowlplay4 08-14-2011 12:05 AM

Quote:

Originally Posted by Rave_J (Post 1663427)
but ur gs2 beautifier is nice dont get me wrong would be cool if u can add where it tells u errors
and suggestions on how to fix

The purpose is to style the code properly so other scripters such as myself can actually read your (and others) code, diagnose errors and suggest solutions to problems.

It is in no way meant to actually compile and run code. The level editor doesn't even do that properly with GS2.

It can't even do one of the most basic GS2 scripts:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  echo(
"Hello world!");


Level Editor Error: Unknown command: echo("Hello world!")

cbk1994 08-14-2011 12:17 AM

Quote:

Originally Posted by Crow (Post 1663433)
I suggest you get the **** out of subforums you do not belong in.

+1

If you have questions or advice, you're always welcome, but we don't need useless, misinformed spam in these forums.

Rave_J 08-14-2011 01:00 AM

just cause i mention graal has a code styler thing
and u get ur pantys in a wald but u know im not going to be inmature so im done talking to theses idiots

imbavik 09-06-2011 03:17 PM

thank you for posting this :), rep+

moondeath 11-14-2011 09:12 PM

Quote:

Originally Posted by fowlplay4 (Post 1662799)
Stuff


Did Stefan delete the "/style" command since I quit playing Graal? :confused:

fowlplay4 11-14-2011 09:23 PM

Quote:

Originally Posted by moondeath (Post 1674204)
Did Stefan delete the "/style" command since I quit playing Graal? :confused:

No it's still there but it requires you to have the code on NC.

Also in the past I've seen it completely butcher scripts as well.

moondeath 11-14-2011 09:25 PM

Quote:

Originally Posted by fowlplay4 (Post 1674205)
No it's still there but it requires you to have the code on NC.

Also in the past I've seen it completely butcher scripts as well.

Okay that's a problem, why? :noob:

And I have never had that problem... I guess it just liked me better.

fowlplay4 11-14-2011 10:02 PM

Quote:

Originally Posted by moondeath (Post 1674206)
Okay that's a problem, why? :noob:

And I have never had that problem... I guess it just liked me better.

Keep in mind I primarily use this tool to style other people's code and specific sections of code.

Couple reasons:

1. I don't want to copy and paste other people's code into my RC unless I absolutely have to.
2. Using RC to style is a slow/tedious process and only styles code in one way. See comparison below.

Using the beautifier website:
Copy code posted on forums -> Open Tab to GS2 Beautifier -> Paste -> Style

Using RC:
Copy code posted on forums -> Open RC -> Create a new class npc -> Paste -> Click Apply -> Close Script -> Type in /style class testscriptname -> Re-Open Script

xAndrewx 11-15-2011 09:13 AM

i remember it messing with code too, which I didn't like

Emera 03-20-2012 07:52 PM

Pardon the bumb, but I've just spotted an error with how it styles a part of my code. I've got a chunk in my script that says
PHP Code:

if (this.algo = > this.algo2) { 

RC spits out an error if there's a space after the '=' sign, but doesn't if it's removed. :P

cbk1994 03-21-2012 02:22 AM

Quote:

Originally Posted by Emera (Post 1689397)
Pardon the bumb, but I've just spotted an error with how it styles a part of my code. I've got a chunk in my script that says
PHP Code:

if (this.algo = > this.algo2) { 

RC spits out an error if there's a space after the '=' sign, but doesn't if it's removed. :P

It's an error, but you should be doing >= instead of => anyway to comply with general programming conventions.

Emera 03-21-2012 05:08 PM

Ok, thanks <3

callimuc 10-13-2012 10:59 PM

a small bump, but you might now want to update the example script in there. it is still using
PHP Code:

player.triggerclient(this.name"hello world"); 

(not having the "gui"/"weapon" part).
not that people are learning from that example but it should be given correctly :)

fowlplay4 10-13-2012 11:28 PM

Quote:

Originally Posted by callimuc (Post 1705689)
a small bump, but you might now want to update the example script in there. it is still using
PHP Code:

player.triggerclient(this.name"hello world"); 

(not having the "gui"/"weapon" part).
not that people are learning from that example but it should be given correctly :)

done.

TheGodAngelo 10-14-2012 02:41 AM

Quote:

Originally Posted by Rave_J (Post 1663446)
just cause i mention graal has a code styler thing
and u get ur pantys in a wald but u know im not going to be inmature so im done talking to theses idiots

how do you tolerate the red squiggly lines under your words when you type a post? it always irks me! and I'm not even a grammar Nazi.


All times are GMT +2. The time now is 04:09 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.