Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Curiosity... (https://forums.graalonline.com/forums/showthread.php?t=81118)

Kristi 08-08-2008 05:57 PM

Curiosity...
 
Am I the only person that avoids using "with" as much as possible?

Whenever I create an object of any sort, I assign it a pointer. If the object is already created, I give it a pointer.

ex: temp.ani = showani(...);
temp.ani.prop = value;

When I have long lists of things, it seems easier to just glance at my code and see exactly what is going on, instead of tracing back with blocks.

What do you do and why? Discuss!

Crono 08-08-2008 06:00 PM

I never use with.

Stryke 08-08-2008 06:01 PM

I use with only with findimgs

DrakilorP2P 08-08-2008 06:33 PM

thiso. eww.

DustyPorViva 08-08-2008 06:49 PM

It depends on how many values of the object I am changing.

Chompy 08-08-2008 06:52 PM

Quote:

Originally Posted by DustyPorViva (Post 1412569)
It depends on how many values of the object I am changing.

Same here

cbk1994 08-08-2008 07:07 PM

Quote:

Originally Posted by Chompy (Post 1412570)
Same here

Agreed.

Crow 08-08-2008 07:12 PM

Quote:

Originally Posted by cbk1994 (Post 1412577)
Agreed.

Seconded.

LoneAngelIbesu 08-08-2008 07:24 PM

Quote:

Originally Posted by DustyPorViva (Post 1412569)
It depends on how many values of the object I am changing.

Yup, same here. As a rule of thumb, if I'm changing three or more values, I use with.

I mean, really... which one looks better? It may be more lines, but I guess I'm a block kind of guy. :cool:
PHP Code:

function TheParentObject.onMove(newxnewy) {
  
TheObject.newx TheParentObject.width 10;
  
TheObject.newy;
  
TheObject.text "Has been moved with parent object";
}
function 
TheParentObject.onMove(newxnewy) {
  
with(TheObject) {
    
this.newx TheParentObject.width 10;
    
this.newy;
    
this.text "Has been moved with parent object";
  }



Kristi 08-08-2008 07:27 PM

The top one looks better, and would look even better if you lined up your equal signs *tsktsk*

Dan 08-08-2008 07:30 PM

For me it kind of depends on the length of the object name, I found out (but never thought about).

Example;
PHP Code:

temp.object putnpc2(params[1][0],params[1][1],"");
temp.object.image params[2][0];
if (
params[2][1] == "")
  return;
temp.object.join(params[2][1]); 

or;
PHP Code:

with (@ genGUIName("Window_Scroll_EditMission_Scroll_List")) {
  
clearRows();
  for (
temp.1temp.<= mission.missionslist.size(); temp.++)
    
addRow(- 1,"Mission " temp.i);



Crow 08-08-2008 07:31 PM

Quote:

Originally Posted by Kristi (Post 1412587)
The top one looks better, and would look even better if you lined up your equal signs *tsktsk*

Lining up equal signs doesn't look cool if you ask me. I agree that the top one looks better in that case though. I only use with when I have to change more than 4 or 5 things.

LoneAngelIbesu 08-08-2008 07:31 PM

Quote:

Originally Posted by Kristi (Post 1412587)
The top one looks better, and would look even better if you lined up your equal signs *tsktsk*

I'm too lazy to press my space bar that many times. :) Another thing that I like about using with() is when there are really long object names. I try as hard as possible not make the horizontal scrollbar appear... but, I do that with everything.

Crow 08-08-2008 07:33 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1412590)
I'm too lazy to press my space bar that many times. :) Another thing that I like about using with() is when there are really long object names. I try as hard as possible not make the horizontal scrollbar appear... but, I do that with everything.

Tab key adds 2 spaces, and I don't think long object names are an excuse. You could just do something like this:

PHP Code:

temp.obj PrettyDamnLongObjectNameHere;
temp.obj.doStuff(); 


LoneAngelIbesu 08-08-2008 07:38 PM

Quote:

Originally Posted by Crow (Post 1412593)
Tab key adds 2 spaces, and I don't think long object names are an excuse. You could just do something like this:

PHP Code:

temp.obj PrettyDamnLongObjectNameHere;
temp.obj.doStuff(); 


Not when the object stuff is already nested four, five, six, etc. times. ;) The horizontal scrollbar is a personal challenge. I usually lose though... but when I do, I resize the window and it's like it never happened. /I'm crazy. I have mild symmetry compulsions. :'(

Besides, there are no excuses. Using with() is all about personal preference. Same about lining up equal signs.

Crow 08-08-2008 07:40 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1412594)
Besides, there are no excuses. Using with() is all about personal preference. Same about lining up equal signs.

Heh, through I guess :)

Kristi 08-08-2008 07:43 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1412594)
Same about lining up equal signs.

Preference or not, it is what is generally taught as standard coding practices in computer science.

LoneAngelIbesu 08-08-2008 07:46 PM

Quote:

Originally Posted by Kristi (Post 1412597)
Preference or not, it is what is generally taught as standard coding practices in computer science.

I have never taken a computer science class in my life. I'm self-taught. ^^

Kristi 08-08-2008 07:47 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1412598)
I have never taken a computer science class in my life. I'm self-taught. ^^

And it shows in your TERRIBLE coding preferences

LoneAngelIbesu 08-08-2008 07:49 PM

Quote:

Originally Posted by Kristi (Post 1412599)
And it shows in your TERRIBLE coding preferences

I like to think of myself as a revolutionist. I got my style from Inverness, no matter how many times he denies it.

DrakilorP2P 08-08-2008 08:34 PM

Quote:

Originally Posted by Kristi (Post 1412599)
And it shows in your TERRIBLE coding preferences

I wish I had taken computer science courses so that I could be cool like you and line up my equal signs.

Dan 08-08-2008 11:20 PM

Quote:

Originally Posted by Kristi (Post 1412599)
And it shows in your TERRIBLE coding preferences

You're so great :cool:

Inverness 08-09-2008 12:15 AM

I don't line up my equal signs either, if you don't like it, sucks to be you.
Quote:

Originally Posted by LoneAngelIbesu (Post 1412601)
I like to think of myself as a revolutionist. I got my style from Inverness, no matter how many times he denies it.

You're not something that bothers me enough to deny. :D

Tigairius 08-09-2008 12:15 AM

I use with() just about as much as I assign a pointer. Some functions on GK don't even work properly unless you use with(), and as many other people said it depends how many values I'm editing at once.

cbk1994 08-09-2008 12:20 AM

Quote:

Originally Posted by Tigairius (Post 1412674)
Some functions on GK don't even work properly unless you use with()

GK's functions. :\

Inverness 08-09-2008 12:23 AM

Using with() on serverside is how you change the calling player.

xXziroXx 08-09-2008 12:31 AM

Quote:

Originally Posted by Tigairius (Post 1412674)
it depends how many values I'm editing at once.

Agreed.

Admins 08-09-2008 12:48 AM

It can reduce problems with typing errors (typing the same object name over and over again), it can also make scripts look easier to understand. If you need to write very efficient code then it should probably be avoided (e.g. loops inside with() are not optimized), but that should not happen often.
Making scripts look easier to understand is often more important than you think, because code often needs to be understood by other scripters to be able to fix or improve stuff (or by yourself in the future).

Cloven 08-10-2008 12:18 PM

Quote:

Originally Posted by Stefan (Post 1412692)
It can reduce problems with typing errors (typing the same object name over and over again), it can also make scripts look easier to understand. If you need to write very efficient code then it should probably be avoided (e.g. loops inside with() are not optimized), but that should not happen often.
Making scripts look easier to understand is often more important than you think, because code often needs to be understood by other scripters to be able to fix or improve stuff (or by yourself in the future).

In my opinion, the first (and possibly best thing) people can do in general is use practical, logical names for their variables and/or functions as they apply to the npc they're being used in. This makes it 10x easier on any future scripter who may have to edit/debug your work if they can relate easily to the code in front of them.

WhiteDragon 08-10-2008 09:54 PM

Quote:

Originally Posted by Kristi (Post 1412597)
Preference or not, it is what is generally taught as standard coding practices in computer science.

Never been taught to me before... and even if you have been taught that it may only be that fact that you had some cracked old professor.

Loriel 08-10-2008 10:13 PM

Quote:

Originally Posted by Kristi (Post 1412597)
Preference or not, it is what is generally taught as standard coding practices in computer science.

Computer science is no more about aligning equals signs than astronomy is, uh, about having those nice little bronze ornaments on your telescopes.

:\

zokemon 08-10-2008 10:55 PM

I use with when creating objects (like GUIs) to make it match with the new blocks.

Quote:

Originally Posted by Kristi (Post 1412597)
Preference or not, it is what is generally taught as standard coding practices in computer science.

Not a single CIS class I've taken has taught such a practice, though it does make sense.

Kristi 08-11-2008 07:23 AM

Quote:

Originally Posted by zokemon (Post 1413232)
i use with when creating objects (like guis) to make it match with the new blocks.



Not a single cis class i've taken has taught such a practice, though it does make sense.

cis <> cs

Mark Sir Link 08-11-2008 08:40 AM

I've yet to be taught to line up equal signs after Computer Science, AP Computer Science AB, and Computer Systems, but perhaps year 4 will be my lucky year!

Loriel 08-11-2008 02:00 PM

Quote:

Originally Posted by Kristi (Post 1413301)
cis <> cs

I am watching CSI: Miami every week and have yet to see them line up any equal signs.

Inverness 08-11-2008 02:59 PM

Quote:

Originally Posted by Loriel (Post 1413327)
I am watching CSI: Miami every week and have yet to see them line up any equal signs.

I tried to find the humor in that but I just couldn't do it.

Loriel 08-11-2008 03:03 PM

Quote:

Originally Posted by Inverness (Post 1413333)
I tried to find the humor in that but I just couldn't do it.

I tried to find the humor in your mom but I just could not do that either

Kristi 08-11-2008 04:32 PM

Quote:

Originally Posted by Loriel (Post 1413334)
I tried to find the humor in your mom but I just could not do that either

I should probably be deleting this instead of loling at it

zokemon 08-11-2008 05:36 PM

Quote:

Originally Posted by Kristi (Post 1413301)
cis <> cs

CIS = Computer Information Sciences

It just means the department also include more then just programming classes. I was however, referring to the programming classes that I've taken.

Kristi 08-11-2008 05:41 PM

Quote:

Originally Posted by zokemon (Post 1413373)
CIS = Computer Information Sciences

It just means the department also include more then just programming classes. I was however, referring to the programming classes that I've taken.

CIS = Computer Information Systems....


All times are GMT +2. The time now is 04:37 PM.

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