Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Making scripts shorter (https://forums.graalonline.com/forums/showthread.php?t=45307)

Googi 06-06-2003 02:45 AM

Making scripts shorter
 
Could someone tell me common things that people do that can be done in shorter ways that take up less characters (preferably a lot less...)

Pokilty 06-06-2003 03:40 AM

for loops! i see so many scripts that should be taking advantage of this but aren't. i'm not just talking about the scripts where people put 20 putexplosions, there's also scripts that have just a few extra lines that could be removed and more easliy understood with a simple for loop in it.

Googi 06-06-2003 03:49 AM

Quote:

Originally posted by Pokilty
for loops! i see so many scripts that should be taking advantage of this but aren't. i'm not just talking about the scripts where people put 20 putexplosions, there's also scripts that have just a few extra lines that could be removed and more easliy understood with a simple for loop in it.
Yes, I already knew that one.

Jeff 06-06-2003 04:10 AM

Use with to transfer strings around instead of using server strings. More efficient and less error-prone, too

DarkShadows_Legend 06-06-2003 07:55 PM

I've tried this a few times in Graal, but it doesn't seem to work, but it works in some other programming languages.

NPC Code:

//1st ex
if(var == (1||3)){
// do stuff
}
// 2nd ex.
if(playerdir == (1||3)){
//do stuff
}



It doesn't seem to work for me. I usually have to type out the whole thing as if(var == 1 || var == 3) // stuff

Has anyone else tried this before?

Loriel 06-06-2003 09:29 PM

Quote:

Originally posted by DarkShadows_Legend
It doesn't seem to work for me.
|| is a boolean thing, so it only returns true or false.
'var == (1||3)' would check wether var is true, as '(1||3)' returns true because neither 1 or 3 is false.
Not sure wether it is exactly like that in GScript, but in theory it should be like that.

Probably one could also save some lines
by using vecx/y.
NPC Code:
if (playerdir == 0) playery --;
else if (playerdir == 1) playerx --;
else if (playerdir == 2) playery ++;
else if (playerdir == 3) playerx ++;

is inferior to
NPC Code:
playerx += vecx(playerdir);
playery += vecy(playerdir);


osrs 06-06-2003 09:59 PM

I usually use more arrays than lots of this.vars,like:

array = {10,20,30,40};

instead of

this.var1=10;
this.var2=20;

as Pokilty already said,i like to use for loops:

for(i=0;i<4;i++){changeimgvis i,4;}

instead of

changeimgvis 1,4;
changeimgvis 2,4;


You can find many ways to make your script shorter.
Btw,this remember a funny thing that ive seen,i saw a script 2 weeks ago (i wont say who was the scripter,but its a famous person),he made a scrolling message like this:

NPC Code:

if(playerenters){
message H;
sleep0.5;
message Hi;
sleep0.5;
message H;
sleep0.5;
message;
timeout = 1;
}



hehe :D

adam 06-07-2003 12:48 AM

Quote:

Originally posted by osrs

Btw,this remember a funny thing that ive seen,i saw a script 2 weeks ago (i wont say who was the scripter,but its a famous person),he made a scrolling message like this:

NPC Code:

if(playerenters){
message H;
sleep0.5;
message Hi;
sleep0.5;
message H;
sleep0.5;
message;
timeout = 1;
}



hehe :D

Aw... I Hate that.

TB3 06-10-2003 05:46 PM

Originally posted by osrs

Btw,this remember a funny thing that ive seen,i saw a script 2 weeks ago (i wont say who was the scripter,but its a famous person),he made a scrolling message like this:


code:--------------------------------------------------------------------------------
if(playerenters){
message H;
sleep0.5;
message Hi;
sleep0.5;
message H;
sleep0.5;
message;
timeout = 1;
}
--------------------------------------------------------------------------------
NPC Code:

if(playerenters||timeout) {
setstring this.message,H Hi H;
tokenize #s(this.message);
for (i=0;i<4;i++) {
message #t(i);
sleep .5;
}
timeout=1;
}


Just a quick script but sadly it is not that much shorter than the first one lolz
Didn't test it i just figured it would work.

osrs 06-10-2003 05:55 PM

Quote:

Originally posted by TB3

NPC Code:

if(playerenters||timeout) {
setstring this.message,H Hi H;
tokenize #s(this.message);
for (i=0;i<4;i++) {
message #t(i);
sleep .5;
}
timeout=1;
}


Just a quick script but sadly it is not that much shorter than the first one lolz
Didn't test it i just figured it would work.

Yes,it works fine.
But you could do for(i=0;i<=strlen(#s(this.message));i++)
instead of for(i=0;i<4;i++)

TB3 06-10-2003 06:04 PM

I would have but I didn't see a blank message ; before the actual H showed up so I didnt think of it ;)
It was a blank message ; at the end thus the i<4 instead of <3

osrs 06-11-2003 02:34 AM

Quote:

Originally posted by Kaimetsu
Both solutions are horrible.

1) Sleep is bad for loops.
2) You don't need to explicitly specify the chat text at each stage. Just store the whole text in a this.string and use #e to cut out the part you need.

And osrs, strlen would be meaningless in this case. Even within his crazy method, sarraylen would be more appropriate.

We arent expert,so we script it as the way we know..

Tseng 06-11-2003 03:32 AM

Quote:

Originally posted by Kaimetsu
Both solutions are horrible.

1) Sleep is bad for loops.
2) You don't need to explicitly specify the chat text at each stage. Just store the whole text in a this.string and use #e to cut out the part you need.

And osrs, strlen would be meaningless in this case. Even within his crazy method, sarraylen would be more appropriate.

tokenscount would work as well, since he's tokenizing it and using tokens

Quote:

Originally posted by osrs


We arent expert,so we script it as the way we know..

And from posts such as Kaimetsu's, you learn a new/better way to do it.

osrs 06-11-2003 11:08 PM

Quote:

Originally posted by Tseng
And from posts such as Kaimetsu's, you learn a new/better way to do it.
Yes,finding new/better ways to script is always good.

Admins 06-19-2003 07:46 PM

Quote:

Originally posted by DarkShadows_Legend
I've tried this a few times in Graal, but it doesn't seem to work, but it works in some other programming languages.

NPC Code:

//1st ex
if(var == (1||3)){
// do stuff
}
// 2nd ex.
if(playerdir == (1||3)){
//do stuff
}



It doesn't seem to work for me. I usually have to type out the whole thing as if(var == 1 || var == 3) // stuff

Has anyone else tried this before?

Do

NPC Code:

if (var in {1,3})


adam 06-19-2003 10:21 PM

Quote:

Originally posted by Stefan


Do

NPC Code:

if (var in {1,3})


*goes to try*


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

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