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 06-06-2003, 02:45 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
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...)
__________________
Reply With Quote
  #2  
Old 06-06-2003, 03:40 AM
Pokilty Pokilty is offline
Registered User
Join Date: Nov 2002
Posts: 101
Pokilty is on a distinguished road
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.
__________________
"I have not failed. I've just found 10,000 ways that won't work."
"Logic is in the eye of the logician."
Reply With Quote
  #3  
Old 06-06-2003, 03:49 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
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.
__________________
Reply With Quote
  #4  
Old 06-06-2003, 04:10 AM
Jeff Jeff is offline
Registered User
Join Date: Oct 2002
Location: Nebraska, USA
Posts: 707
Jeff is on a distinguished road
Use with to transfer strings around instead of using server strings. More efficient and less error-prone, too
__________________
Jeff, the Archduke of Dustari
Member of the LAT on Graal The Adventure
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GO d+ s++:+ !a C++ UL+(UL+++)@ P+ L+(++)>+++ E---- W++@ N- !o ?K w(w--) !O !M@ !V PS- PE+ Y PGP t+ 5 X R tv(tv+) b++(b+)>b++++ DI(DI+) D-- G e->e++++ h! !r y
------END GEEK CODE BLOCK------
Reply With Quote
  #5  
Old 06-06-2003, 07:55 PM
DarkShadows_Legend DarkShadows_Legend is offline
Cult of the Winky
DarkShadows_Legend's Avatar
Join Date: Apr 2003
Location: Florida
Posts: 614
DarkShadows_Legend is on a distinguished road
Send a message via AIM to 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?
__________________
- Criminal X

"I rather be hated for being myself, than be liked for being what you like best. I go above the influence, not under." - Me
Reply With Quote
  #6  
Old 06-06-2003, 09:29 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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);

Reply With Quote
  #7  
Old 06-06-2003, 09:59 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
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
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #8  
Old 06-07-2003, 12:48 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
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
Aw... I Hate that.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #9  
Old 06-10-2003, 05:46 PM
TB3 TB3 is offline
Registered User
TB3's Avatar
Join Date: May 2001
Location: US of A State of VA
Posts: 658
TB3 is on a distinguished road
Send a message via Yahoo to TB3
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.
__________________

To the sun of your age, I arise
Reply With Quote
  #10  
Old 06-10-2003, 05:55 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
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++)
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #11  
Old 06-10-2003, 06:04 PM
TB3 TB3 is offline
Registered User
TB3's Avatar
Join Date: May 2001
Location: US of A State of VA
Posts: 658
TB3 is on a distinguished road
Send a message via Yahoo to TB3
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
__________________

To the sun of your age, I arise
Reply With Quote
  #12  
Old 06-11-2003, 02:34 AM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
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..
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #13  
Old 06-11-2003, 03:32 AM
Tseng Tseng is offline
Sublime
Tseng's Avatar
Join Date: Jan 2003
Location: California
Posts: 0
Tseng is on a distinguished road
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.
__________________
Funny Things:
Quote:
Originally posted by Stefan
I didn't ban you, I only played a little bit with my RC.
-----
Reply With Quote
  #14  
Old 06-11-2003, 11:08 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
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.
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #15  
Old 06-19-2003, 07:46 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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})

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:35 PM.


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