Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-04-2011, 12:25 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by Tricxta View Post
Whats peoples on thoughts as far as readability goes if I did:
NPC Code:
function onCreated()echo "Hello world!";



I think it improves readability as its a smaller area to focus on however some might argue it decreases readability, can someone please clarify this?
I hate that! My first script I decided to work on was learning Dustys hammer and he did things sort of like that.. the missing brackets are the only reason I couldn't understand the parts I wanted to learn were
level.tiles[x,y];
and
updateboard(x,y,L,W);

I went through the script so many times trying to figure out the part of the script that did it only to realize it was two commands..

Then I made a beach. ^.^
But I've asked so many people to help me get what was doing it and no one could tell me..

Quote:
Originally Posted by cbk1994 View Post
GScript is object-oriented, so you want to get away from thinking of it as command-based. To disable the chat bar, you need to act on its GUI object, named ChatBar.

There is a list of server functions here, and a list of client functions here. These are not completely up-to-date, so use scripthelp as well.
Is this better then commands.rtf? / the new GS2 server cammands file that was floating around somewhere on the forum?

Quote:
Originally Posted by Emera View Post
No pressure...
But i agree lol. I am looking forward to this!
i hope to see a lot of people there!
It's already up, you should go to:
http://scriptingschool.forumotion.com/.


Quote:
Originally Posted by IaMnOtAnEwB2_red38 View Post
This seems interesting, a few years ago I was in the middle of learning GS1 and I seemed to catch on quickly, but never gave myself a chance to pick it back up after the GS2 conversion. Count me in.

Email: [email protected]
I know exactly what you mean! It took me 2-3 months ago to start learning GS2 after learning GS1 about five years ago.. after Babylon died 'in my head apparently it carried on for a good amount of time' along with GS1, I gave up on trying to learn too.

Quote:
Originally Posted by fowlplay4 View Post
Sorry but that forum is just dreadful.

Couldn't you just use the Group (Moderated) functionality on these forums, and Thread posts for assignments/challenges?
I agree.. It would be nice to have him as a moderator and our own thing on the forum.. I like the PHP system on here with the nice colors. ;o

Quote:
Originally Posted by papajchris View Post
I was going through a few themes so hopefully you took a look while I was adjusting things. I personally like having it on a different website as all scripting things are in one place. Once a thread dies I plan to adjust the title to what the thread may be about (such as functions) and make it easy to search. I like the ability to make changes, but if it ends up not working we can come here
But I also agree with this... if he does do it on here, there is a chance it could 'die' and a lot of people would not want to post on it because of the so called 'proper etiquette' of this forum. I know I wouldn't want to be yelled at again for posting on a 'dead' thread that interests me and can annoy a whole lot of other people.. I think if he could manage his own subject / thread where we could post subforums inside of it, it could go well on here.

It would get all messy in only one or two threads..

Again, I'd rather post on here.. and greatly like the PHP system on here, but as he said, he'd at least be able to manage it on there. Perhaps this could be worked out?
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #2  
Old 05-04-2011, 02:27 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
Quote:
Originally Posted by Devil_Lord2 View Post
I hate that! My first script I decided to work on was learning Dustys hammer and he did things sort of like that.. the missing brackets are the only reason I couldn't understand the parts I wanted to learn were
level.tiles[x,y];
and
updateboard(x,y,L,W);
Actually, having single like script blocks within if() or loops is common.

The problem in this case is he was asking about a function without brackets.

PHP Code:
function onCreated() {
  if (
foo == bar) return true;
}
function 
onPlayerEnters() {
  for (
pl:players)
    
pl.chat "Welcome!";

Both of which are used commonly. At that point, I think its a matter of preference whether you include brackets for 1 line codes.
__________________

Reply With Quote
  #3  
Old 05-04-2011, 11:38 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oo_jazz_oo View Post
Actually, having single like script blocks within if() or loops is common.

The problem in this case is he was asking about a function without brackets.

PHP Code:
function onCreated() {
  if (
foo == bar) return true;
}
function 
onPlayerEnters() {
  for (
pl:players)
    
pl.chat "Welcome!";

Both of which are used commonly. At that point, I think its a matter of preference whether you include brackets for 1 line codes.
Please don't teach people to exclude braces for one-line statements . It's a hard habit to break, and it just makes it a pain when you try to change code later.
__________________
Reply With Quote
  #4  
Old 05-05-2011, 12:48 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
Quote:
Originally Posted by cbk1994 View Post
Please don't teach people to exclude braces for one-line statements . It's a hard habit to break, and it just makes it a pain when you try to change code later.
I dont see a huge problem in using one line codes without brackets for certain instances.
PHP Code:
function check(xy) {
  if (
== y) return true;

Like in that instance. Does it really make it any more readable...any more efficient...any more anything by adding the brackets?
__________________

Reply With Quote
  #5  
Old 05-05-2011, 01:24 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oo_jazz_oo View Post
I dont see a huge problem in using one line codes without brackets for certain instances.
PHP Code:
function check(xy) {
  if (
== y) return true;

Like in that instance. Does it really make it any more readable...any more efficient...any more anything by adding the brackets?
Yes, it makes it more readable, and it makes it easier to expand upon, especially if some parts of the code aren't properly indented. There are tons of arguments for this on stackoverflow and other programming sites—check them out.
__________________
Reply With Quote
  #6  
Old 05-05-2011, 01:26 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by oo_jazz_oo View Post
I dont see a huge problem in using one line codes without brackets for certain instances.
PHP Code:
function check(xy) {
  if (
== y) return true;

Like in that instance. Does it really make it any more readable...any more efficient...any more anything by adding the brackets?
Bad example because if you're going to take shortcuts, take the best shortcut.

PHP Code:
function check(xy) {
  return 
temp.== temp.y;

In general, I try to always include brackets for one-line statements. Consistency not only improves readability (imo), but it makes your code a lot less error-prone.

If you start saying "oh, well in this instance is it really a problem?" your styling is probably very confusing and inconsistent, and you're much more likely to **** up.
__________________
Reply With Quote
  #7  
Old 05-05-2011, 01:31 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by oo_jazz_oo View Post
I dont see a huge problem in using one line codes without brackets for certain instances.
PHP Code:
function check(xy) {
  if (
== y) return true;

Like in that instance. Does it really make it any more readable...any more efficient...any more anything by adding the brackets?
On first site I would say it was a mistake, and fix it to have brackets..
I agree not to teach like this, but if you are the only one ever going to touch your scripts.. I suppose it doesn't matter if it works for you.. lol

But if someone in the future may have to go over it.. Again it could confuse them... I'm not totally experienced in programming, so I don't know, others may be able to pick it up what it means faster.. Even if I did pick it up, I'd take the time to fix it towards a common style for others and myself in case I look at it again in the future.




Quote:
Originally Posted by salesman View Post
PHP Code:
function check(xy) {
  return 
temp.== temp.y;

This would return true if true? and if it isn't the same, it would still return false?


I'm only wondering because I would do:
this.variable = 0;
if (this.variable == 1){
dostuff();
}

I use 0 and 1.. and later on if I need to I can increase it if I want it to be 2, 3, or 4.. but even if it stays on and off, true or false, I still use 0 and 1.. should I start doing true and false for those special things that only use true or false?
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #8  
Old 05-05-2011, 01:37 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Devil_Lord2 View Post
On first site I would say it was a mistake, and fix it to have brackets..
I agree not to teach like this, but if you are the only one ever going to touch your scripts.. I suppose it doesn't matter if it works for you.. lol

But if someone in the future may have to go over it.. Again it could confuse them... I'm not totally experienced in programming, so I don't know, others may be able to pick it up what it means faster.. Even if I did pick it up, I'd take the time to fix it towards a common style for others and myself in case I look at it again in the future.
It is good practice to always format well, even if you're the only person who is going to see it. You will generally make less mistakes.


Quote:
This would return true if true? and if it isn't the same, it would still return false?
It will return the result of the statement.

PHP Code:
echo(== 1); // echoes true
echo(== 0); // echoes false
echo("a" == "a"); // echoes true
echo((2) == 7); // echoes true 
__________________
Reply With Quote
  #9  
Old 05-05-2011, 01:56 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by cbk1994 View Post
It is good practice to always format well, even if you're the only person who is going to see it. You will generally make less mistakes.
I only meant if 'he' wanted to do it, and no one else would see it, he can go ahead.. Not saying everyone in general should do it lol.. I took the time in changing Stefans 2001 baddy script styling it correctly. D:

If I didn't I don't think I'd ever have figured out what it was doing..
But I agree.. It is kind of like doing a turn single at a turn or stop sign even if there is no one else there to see.. Still a good habit to keep/practice..



Quote:
Originally Posted by cbk1994 View Post
It will return the result of the statement.

PHP Code:
echo(== 1); // echoes true
echo(== 0); // echoes false
echo("a" == "a"); // echoes true
echo((2) == 7); // echoes true 
Oh I see.. So would this be a good thing inside a class / function for ... w/e the function might do.. assuming the point is to be true or false... Also, can you return more then one thing, for instance maybe X and Y? or would you have to return X and Y in an array with X and Y in it?

I usually do this. variables so they work through the whole script D: and have not made any real functions that needed to be in classes and used everywhere, but I would like to make a bush system.. and other things..

One more thing... xD returns do not return temp. variables? I've had a problem with this and had to make the temp. a this. to pass it back x.x;
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:01 AM.


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