Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-26-2006, 07:48 AM
_Z3phyr_ _Z3phyr_ is offline
Banned
Join Date: Sep 2003
Location: Louisiane
Posts: 390
_Z3phyr_ is an unknown quantity at this point
Learning GS2: A Tailor Script

If you do not like the forum format, check this site out for a website format of this post: - http://www.freewebs.com/zephyrtk/gs2.../art01GS2.html
The link to the original post of this in the Delterian Forums is here:
- http://forums.delteria.com/index.php...221&#entry7221


This thread is made for those who are completely new to GS2, but are assumed to be at least familiar with GS1, or old GScript. Sort of a way for GS1 scripters to familiarize themselves with this new monster... except its in plain English and makes it all easy to understand. The following is an example of a GS2 Tailor Script created solely by me from Scratch, and declared correct by scripters Riot, Ajira, Maniaman, and MisconceptioN.

I hope that the following will help you learn GS2, if you are not already smart about it:

-=-=-



Here's how I'll work this:
I will post the old GScript (if I bothered to convert it somehow) and then the new one. In this post, I have the old one and I'll post it first and do a fast brief on how it works, then do the new GScript and then put the effort onto explaining that.

TAILOR SCRIPT
BEFORE YOU READ THE SCRIPT, please keep in mind that there are many many ways to make GScript do whatever you want to. The glass is half full, or the glass is half empty. They both mean the same thing, but they use different ways of explaining it. The same applies to GScript and any other computer or foreign language you ever might want to learn.

In these two scripts, the function is for the player to say "/set clothes/tunic PART COLOR."

ALSO, in GS2 I was told that the functions "setPARTcolor()" is deprecated (meaning they're old and there's better/easier ways to do them), but for the purposes of this I'm doing this so you can relate the Old to the New GSCript.


NPC Code:

// OLD GSCRIPT
if (created) {
setstring this.parts,"skin","coat","sleeves","shoe","belt";
}
if (playerchats) {
tokenize #c;
if (startswith(/set,#c)) {
if (strequals(#t(1),clothes) || strequals(#t(1),tunic)) {
for (i=0;i<=strlen(this.parts);i++) {
if (strequals(#t(2),#I(this.parts,#v(i)))) {
setskincolor #t(3);
//setskincolor is the only one I listed just as an example rather than type it all out.
} else {
message Invalid Clothing part/color!;
}
}
}
}
}
//~Michael Lee, 05.11.05



Brief description of the above OLD GSCRIPT:
I will assume that you know how the basic syntax works and what "playerchats/startswith/strequals" and all that crap means...
This script tokenizes what the player says and checks to see if certain phrases are met before they set the part. They use (startswith(/set,#c)) to check if the player is trying to use a /set command, then checks everything after it to see what the player is trying to set (in this case, the player is trying to change his clothing colors). Everything after that checks and sets the player's request accordingly (Note that "all" isn't set in this script).


NPC Code:

// NEW GSCRIPT
function onPlayerchats() {
tokens = player.chat.tokenize();
if (tokens[0] == "/set") {
if (tokens[1] in {"clothes","tunic"}) {
switch (tokens[2]) {
case "skin": setskincolor(tokens[3]); break;
case "coat": setcoatcolor(tokens[3]); break;
case "sleeve": setsleevecolor(tokens[3]); break;
case "shoe": setshoecolor(tokens[3]); break;
case "belt": setbeltcolor(tokens[3]); break;
default : message("**Error: Invalid part**"); break;
}
}
}
}
//~Michael Lee 05.11.05



Brief description of the above NEW GSCRIPT:

First off, everything in GS2 is in functions. When in GS1 you would say:
NPC Code:
if (created) { ... }


in GS2 you would say:
NPC Code:
function onCreated() { ... }


Here, where in GS1 you would say:
NPC Code:
if (playertouchsme) { ... }


in GS2 you would say:
NPC Code:
function onPlayertouchsme() { ... }


This rule applies to all built-in conditions. Also note that "offCreated" or "offPlayertouchsme" don't exist — but I can't tell you that 100% even though it makes sense. A near-but-not-entirely-complete list of all default built-in functions are listed in the Graal Wiki.

Secondly, the next line in the GS2 script:
NPC Code:
tokens = player.chat.tokenize();


is the equivalent to the GS1 command:
NPC Code:
tokenize #c;


In many programming languages like JavaScript or C++, you can perform functions to variables AS you call them or even set them!
In GS2, you use the tokenize(); function at the end of "player.chat" in order to tokenize the variable "player.chat" (which is the equivalent of #c in GS1). As for the variable "tokens," it is an array. Instead of (in GS1) saying "#t(NUMBER)", you can (in GS2) say "tokens[NUMBER]" to do the exact same thing (same rules apply - 0 is the first word, 1 is the second, etc).

Thirdly, the actual checking of the tokens in the new GS2 is simple if you understand what I just said above. The function of this script is so that the player can change his or her clothing colors by saying /set PART COLOR. the first word this player should say is "/set" which should be equal to tokens[0] (or in GS1, "#t(0)" ).
NPC Code:

if (tokens[0] == "/set") {
...
}


The same applies to the other words, where tokens[1] (or, #t(1) in GS1) is the name of the part and tokens[2] (or, #t(2) in GS1) is the name of the color.
NPC Code:

if (tokens[1] in {"clothes","tunic"}) {
switch (tokens[2]) {
case "skin": setskincolor(tokens[3]); break;
case "coat": setcoatcolor(tokens[3]); break;
case "sleeve": setsleevecolor(tokens[3]); break;
case "shoe": setshoecolor(tokens[3]); break;
case "belt": setbeltcolor(tokens[3]); break;
default : message("**Error: Invalid part**"); break;
}
}


I will assume that you know how a switch function works in scripting. If you don't, check this out for an example of how it works in PHP.

The part about "in {"clothes","tunic"}" simply means that if tokens[1] is one of the things in the bracket signs { } (either "clothes" or "tunic", then it will be true). You can have one thing (although that wouldn't be the most efficient way of doing it...), two things, five things, whatever...

Now this GS2 tailor script doesn't check to see if you supply the right colors, only if you supply the correct part name (as long as it's listed in the "case" section, but you can always add more on the off-chance that more parts can be changed in the game in the future). If you give the incorrect part name, then it says:
NPC Code:

default : message("**Error: Invalid part**"); break;


Note that in GS2, the function "message();" is the same as saying "message msghere; in GS1.


SIDENOTE: When, like in the message(); command, you want to not show a variable, you do not put the variable in quotes. To make that work, you end the quotes and then put in a special symbol (in the GraalWiki, it's called the "concat" — short for concatenating — function but that's nothing more than a fancy word for "combine" and the correct symbol is "@" — the "at" sign like in an e-mail address).

QUICK EXAMPLE OF HOW TO USE THE @ (CONCAT) SIGN:
NPC Code:
message("You currently have" @ player.hp @ "HEARTS");


the @ sign is used as a break between the constant text (which is in quotes) and the variable (player.hp). The basic rule for this is that when you have something in quotes, the script will read the text as text ONLY. If you put "player.hp" in quotes then it will say "player.hp" and think that you're just saying the word, not the variable.




Hope this helps.




-=-=-

If there are any questions whatsoever, please direct them to [email protected] . I might not be able to respond easily on these forums because I don't have an active Gold account so I can't post whenever I feel like it when I'm here. Always in moderation, right?
Reply With Quote
  #2  
Old 05-26-2006, 02:28 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
A more efficient way to write a taylor script might be like:

PHP Code:
function onCreated() {
  
// Don't know the order of the partnames in the colors[] array
  // You'll have to find this bit out for yourself.
  
this.partslist = { "skin""coat""sleeves""shoes""belt" };
}

function 
onPlayerChars() {
  if(
player.chat.starts("/set")) {
    
temp.tokens player.chat.substring(4,-1).tokenize();

    if(
this.partslist.index(temp.tokens[0]) >= 0) {
      
player.colors[this.partslist.index(temp.tokens[0])] = temp.tokens[1];
    } else {
      
player.chat "Invalid Body Part";
    }
  }

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 06-11-2006, 08:45 AM
_Z3phyr_ _Z3phyr_ is offline
Banned
Join Date: Sep 2003
Location: Louisiane
Posts: 390
_Z3phyr_ is an unknown quantity at this point
Quote:
Originally Posted by _Z3phyr_
Thirdly, the actual checking of the tokens in the new GS2 is simple if you understand what I just said above. The function of this script is so that the player can change his or her clothing colors by saying /set PART COLOR. the first word this player should say is "/set" which should be equal to tokens[0] (or in GS1, "#t(0)" ).
NPC Code:

if (tokens[0] == "/set") {
...
}


The same applies to the other words, where tokens[1] (or, #t(1) in GS1) is the name of the part and tokens[2] (or, #t(2) in GS1) is the name of the color.
NPC Code:

if (tokens[1] in {"clothes","tunic"}) {
switch (tokens[2]) {
case "skin": setskincolor(tokens[3]); break;
case "coat": setcoatcolor(tokens[3]); break;
case "sleeve": setsleevecolor(tokens[3]); break;
case "shoe": setshoecolor(tokens[3]); break;
case "belt": setbeltcolor(tokens[3]); break;
default : message("**Error: Invalid part**"); break;
}
}

Correction, since I can't edit my post for some reason:

The function of the script is REALLY to say /set clothes_or_tunic PART COLOR.

I said this at the top of the post, but changed it there. My fault.

tokens[0] (#t(0)) is /set
tokens[1] (#t(1))is either clothes OR tunic
tokens[2] (etc) is PART
tokens[3] is COLOR


and btw the script the above poster made is good and all if you're fluent in GS2, but this tutorial is about teaching GS1 scripters how to do GS2, so yeah - teach it by relating one to the other.
Reply With Quote
  #4  
Old 06-11-2006, 12:14 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Or even a better way to make a tailoring script..

PHP Code:
function onPlayerChats()
{
  
tokens player.chat.tokenize();
  
BodyParts = { "skin""coat""sleeves""shoes""belt""all"};
  
BodyColors = { "white""yellow""orange""pink""red",
    
"darkred""lightgreen""green""darkgreen""lightblue",
      
"blue""darkblue""brown""cynober""purple",
        
"darkpurple""lightgray""gray""black"};
  if (
BodyParts.indextokens[0]) > -&& BodyColors.indextokens[1]) > -1) {
    if (
tokens[0] != "all"player.colorsBodyParts.indextokens[0])] = tokens[1];
    else {
      for (
iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1];
    }
    
player.chat "Changed " tokens[0] @ " to " tokens[1] @ "!";
  }



HOWEVER, good job with the tutorial!
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #5  
Old 06-12-2006, 05:42 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by xXziroXx
Or even a better way to make a tailoring script..

PHP Code:
function onPlayerChats()
{
  
tokens player.chat.tokenize();
  
BodyParts = { "skin""coat""sleeves""shoes""belt""all"};
  
BodyColors = { "white""yellow""orange""pink""red",
    
"darkred""lightgreen""green""darkgreen""lightblue",
      
"blue""darkblue""brown""cynober""purple",
        
"darkpurple""lightgray""gray""black"};
  if (
BodyParts.indextokens[0]) > -&& BodyColors.indextokens[1]) > -1) {
    if (
tokens[0] != "all"player.colorsBodyParts.indextokens[0])] = tokens[1];
    else {
      for (
iBodyPartsplayer.colorsBodyParts.indexi)] = tokens[1];
    }
    
player.chat "Changed " tokens[0] @ " to " tokens[1] @ "!";
  }



HOWEVER, good job with the tutorial!
I'd prefer my version of it.
  1. You are limiting what types of colors they can change to. In Graal you can also change your color to a number instead of the color name.
  2. Those annoying spaces between the opening parenthesis and the first parameter. Why the HELL do you and contiga do that? It is the stupidest thing I've ever seen, and is beyond annoying to read.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #6  
Old 06-12-2006, 02:09 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by ApothiX
I'd prefer my version of it.
  1. You are limiting what types of colors they can change to. In Graal you can also change your color to a number instead of the color name.
  2. Those annoying spaces between the opening parenthesis and the first parameter. Why the HELL do you and contiga do that? It is the stupidest thing I've ever seen, and is beyond annoying to read.
Blame Contiga for showing me that stupid way of styling back on Endora!
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #7  
Old 06-13-2006, 12:11 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by xXziroXx
Blame Contiga for showing me that stupid way of styling back on Endora!
I have been. Do the honorable thing and drop it!
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #8  
Old 06-13-2006, 09:37 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by ApothiX
I have been. Do the honorable thing and drop it!
Eh, it is a perfectly valid way of formatting. Some people[or a lot of programmers of other prog. languages] prefer his way, I believe. For example, Rick uses that way [if I recall correctly?]. Everyone has their own way of doing it... as long as it is some kind of standard, it's alright.
Reply With Quote
  #9  
Old 06-14-2006, 07:27 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Python523
Eh, it is a perfectly valid way of formatting. Some people[or a lot of programmers of other prog. languages] prefer his way, I believe. For example, Rick uses that way [if I recall correctly?]. Everyone has their own way of doing it... as long as it is some kind of standard, it's alright.
No, a lot of programmers put spaces between the first AND last parenthesis. Contiga and Ziro only put a space between the first parenthesis and the parameter list.


Normal way:
NPC Code:
foo( bar );


Their way:
NPC Code:
foo( bar);

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #10  
Old 06-14-2006, 09:25 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by ApothiX
No, a lot of programmers put spaces between the first AND last parenthesis. Contiga and Ziro only put a space between the first parenthesis and the parameter list.


Normal way:
NPC Code:
foo( bar );


Their way:
NPC Code:
foo( bar);

Oh, I didn't even notice that. That's just a little bit weird, but you must be pretty picky.
Reply With Quote
  #11  
Old 06-14-2006, 09:55 AM
_Z3phyr_ _Z3phyr_ is offline
Banned
Join Date: Sep 2003
Location: Louisiane
Posts: 390
_Z3phyr_ is an unknown quantity at this point
*re-rail*

So, I'm sure this thread along with its wonderful contributions by the above posters will help people who aren't familiar with GS2, but are familiar with GS1 learn the language, right? That's the purpose of this thread, after all...


(btw about y'all's argument/debate/whatever...

Quote:
Originally Posted by me
BEFORE YOU READ THE SCRIPT, please keep in mind that there are many many ways to make GScript do whatever you want to. The glass is half full, or the glass is half empty. They both mean the same thing, but they use different ways of explaining it. The same applies to GScript and any other computer or foreign language you ever might want to learn.
hope that contributes to the ending of it and on with the purpose of the thread, which is to introduce a methodology of GS2 learning by translation and explanation so that the scripter can learn through relation, which is the method that I am learning)
Reply With Quote
  #12  
Old 06-15-2006, 01:59 PM
D4rKv310c1ty D4rKv310c1ty is offline
Registered User
Join Date: Feb 2005
Posts: 1,358
D4rKv310c1ty is on a distinguished road
I swear someone said something about a GS1 to GS2 script convertor.

Why don't you just stick to learning GS1 and convert it all
and then learn the scripts which actually do require GS2
Reply With Quote
  #13  
Old 06-15-2006, 04:51 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by D4rKv310c1ty
I swear someone said something about a GS1 to GS2 script convertor.

Why don't you just stick to learning GS1 and convert it all
and then learn the scripts which actually do require GS2
Because it makes so much more sense to skip old gscript completely and learn the new engine. Old gscript is a very illogical language at times; it is easier to learn the new engine if you just ignore the old one.

I guess the old engine won't survive for long with Graal 4 being widely spread out anyway.
__________________
Skyld
Reply With Quote
  #14  
Old 06-16-2006, 07:05 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Python523
Oh, I didn't even notice that. That's just a little bit weird, but you must be pretty picky.
Perhaps, but it just drives me when they're doing it with arrays and such.
ie:
PHP Code:
function SomeFunctionfoobar) {
  
this.myarray = new[ 1];
  
this.myarray0].add"weeEe");
  echo( 
this.myarray0][ 0]);

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #15  
Old 06-16-2006, 08:10 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
They might as well just do this.

PHP Code:
function SomeFunction(foo,bar){this.myarray=new[1];this.myarray[0].add("weeEe");echo(this.myarray[0][0]);} 
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 11:42 AM.


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