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 04-21-2006, 05:14 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
Frequently asked questions about the new scripting engine

There are quite a few common questions about the new scripting engine, and it's syntax, which I hope to answer here for those new to the new engine.

There is a starting guide to the new engine, which you can find here. If you still have unanswered questions, take a look in this thread.

Do I have the new engine enabled on my server?
You can test to see if the new engine is enabled on your server by using a basic script like this:
PHP Code:
function onCreated()
{
  
sendtorc("The new engine is enabled!");

This script should send "The new engine is enabled!" to RC chat if it is enabled, and if not, you can request it be enabled on your server by using the GraalOnline Support Center.

Does the old engine scripting still work on a server where the new engine is enabled?
Yes. However, you may notice a couple of differences. Mostly, they are:
  • Any compiler errors will appear in RC, regardless of which version of gscript you are using.
  • Strings are unset when their value is set to 0 (zero), and thus, may not appear in the player attributes or server strings.

Is it okay to mix new script engine code and old script engine code?
Preferably not. Even though the code will work, it is generally encouraged that a script uses only the new or the old engine.

From using the old scripting engine, I have been using #s, #v and #I to access variables. How do I do it in the new engine?
Old gscript was not able to tell the difference between strings, numeric variables and "string lists" (arrays), so these message codes were used to get the contents of these variables. However, in the new engine, the variable are "variant", which means that the engine already knows what type of data is being stored. Therefore, you can store variables like this:
PHP Code:
this.string "String data";
this.number 3;
this.array = {"First Member""Second Member""etc"}; 
And you can similarly read them just by using their names:
PHP Code:
echo(this.string); // will echo "String data"
echo(this.number); // will echo "3"
echo(this.array); // will echo "First member,Second Member,etc"
echo(this.array[0]); // will echo "First member"
echo(this.array[1]); // will echo "Second member" 
In the old engine, I used more message codes like #c and #n to modify the chat text, nickname and other attributes about the NPC or player. How do I do this in the new engine?
In the new engine, there are new objects for the player, the NPC, etc. Here are some examples on how to set the player's attributes:
PHP Code:
setplayerprop #c,New chat text;
player.chat "New chat text";

setplayerprop #n,New nickname;
player.nick "New nickname";

setplayerprop #g,New guild tag;
player.guild "New guild tag"
Similarly, because you can set attributes about the NPC in a similar way:
PHP Code:
setcharprop #c,New chat text;
this.chat "New chat text";

setcharprop #n,New nickname;
this.nick "New nickname";

setcharprop #g,New guild tag;
this.guild "New guild tag"
Is there a list of all the alternatives to the message codes (#c, etc)?
Yes! There is a list on the GraalBible. You can find it here.

How do I join together values?
There are a set of operators for this. They are called "string concatenation" operators. They work like this:
PHP Code:
this.value "foo" "bar";
// producing "foobar"

this.value "foo" SPC "bar";
// producing "foo bar"

this.value "foo" TAB "bar";
// producing "foo         bar"

this.value "foo" NL "bar";
// producing "foo
bar
There MUST be a value on each side of an operator like this. This will not work:
PHP Code:
this.value "foo" NL
How do timeouts work in the new engine?
There is a new command in the new engine for setting a timeout. It works like this:
PHP Code:
function onCreated()
{
  
setTimer(3); // set the timeout to 3 seconds
}

function 
onTimeout()
{
  
// this will be called after 3 seconds

What are the new engine alternatives to getnpc() and getplayer()?
They are findplayer(), findnpc(), findweapon(), findweaponnpc(). Except, there is now new functionality that allows you to do this:
PHP Code:
findPlayer("Skyld").chat "foo";
findPlayer("Skyld").clientr.variable "value"
However, the old with () method still works:
PHP Code:
with (findPlayer("Skyld"))
{
  
clientr.variable "value";
  
chat "foo";

I understand that functions can now take parameters, how does this work?
They absolutely do! Function parameters work in one of two ways. If you define the function with variables, then this is how it will work:
PHP Code:
myFunction("foo""bar");

function 
myFunction(temp.test1temp.test2)
{
  
// temp.test1 will equal "foo"
  // temp.test2 will equal "bar"

Also, the params[] array is populated with any parameters given to the function, so in the previous example, params[] would look like this:
PHP Code:
params = {"foo""bar"}; 
Function parameters can take any data type (strings, numbers, arrays, object links, etc).

Can functions return values to wherever the function was called?
Yes! The return; function is used for this, and this is how it is done:
PHP Code:
this.variable myFunction("foo""bar");

function 
myFunction(temp.test1temp.test2)
{
  return 
temp.test1 temp.test2;

this.variable will be set to "foobar".

Are there any more reference materials on the new engine?
Yes! You can find them on the GraalBible, at http://wiki.graal.net/Creation/Dev/GScript.

Opinions/suggestions?
Please post them! Only constructive criticism, opinions or suggestions are welcome, though. Others will be deleted!
__________________
Skyld

Last edited by Skyld; 12-13-2006 at 01:21 AM..
Reply With Quote
  #2  
Old 04-21-2006, 05:24 PM
Malinko Malinko is offline
Unholy Nation
Join Date: Mar 2004
Location: Massachusetts, U.S.A.
Posts: 1,782
Malinko is on a distinguished road
Send a message via AIM to Malinko
Nice!
Reply With Quote
  #3  
Old 04-21-2006, 05:59 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
Great work Skyld, thumbs up!
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #4  
Old 04-27-2006, 03:29 AM
RefinoheaT RefinoheaT is offline
Delteria Developer
RefinoheaT's Avatar
Join Date: Jun 2005
Location: New York, USA
Posts: 29
RefinoheaT is on a distinguished road
Send a message via AIM to RefinoheaT Send a message via MSN to RefinoheaT
Is there/will there be a new commands.txt for gscript2 which explains this kind of stuff?

If not it would be really nice to have a convert commands.txt. For example, one that shows the old way, then shows the new way. It would be extremely useful.
__________________
+1 Post
--Staff Accomplishments--
Events Admin on Delteria
Events Admin on Babylon
Events Chief on N-Pulse
Events Developer on Delteria
Events Developer on N-Pulse
Developer on Delteria
LAT on N-Pulse
LAT on Shaded Legend
GP on N-Pulse
----------------------------
Reply With Quote
  #5  
Old 04-27-2006, 02:14 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by RefinoheaT
Is there/will there be a new commands.txt for gscript2 which explains this kind of stuff?

If not it would be really nice to have a convert commands.txt. For example, one that shows the old way, then shows the new way. It would be extremely useful.
wiki.graal.us and wiki.graal.net both provide the 'commands.rtf-esque' documentation for the new engine.

Or you can run Graal4 with the -listscriptfunctions command line option. This will generate a file called docu_scriptfunctionslatest.txt or something along those lines.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #6  
Old 04-27-2006, 05:30 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Very cool Skyld, you should write a little something about the findnpc() too.
Reply With Quote
  #7  
Old 05-15-2006, 06:55 AM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
Curious, is there any difference between \n and NL, besides personal preference?
__________________

I hope for nothing. I fear nothing. I am free.
Reply With Quote
  #8  
Old 05-15-2006, 07:17 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 Skyld
Can functions return values to wherever the function was called?
Yes! The return; function is used for this, and this is how it is done:
How does the return function return values, then? Clearly if it just returns them, there will be infinite recursion.

Quote:
Please post them! Only constructive criticism, opinions or suggestions are welcome, though. Others will be deleted!
Can you give an unbiased definition of such?
Reply With Quote
  #9  
Old 05-15-2006, 07:29 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 Raeiphon
Curious, is there any difference between \n and NL, besides personal preference?
\n is used inside strings, where NL is a string concationation operator that should be used between values.
PHP Code:
this.var = "Foo\nBar";
this.var = "Foo" NL "Bar"
__________________
Skyld
Reply With Quote
  #10  
Old 06-09-2006, 09:14 AM
AgretTehLeet AgretTehLeet is offline
Registered User
AgretTehLeet's Avatar
Join Date: Oct 2005
Location: Melbourne, Victoria, Australia
Posts: 13
AgretTehLeet is on a distinguished road
Send a message via ICQ to AgretTehLeet Send a message via AIM to AgretTehLeet Send a message via MSN to AgretTehLeet Send a message via Yahoo to AgretTehLeet
Skyld I take it you mean concatenation and i'd have just said "string connecting operator"
__________________

(¯`·._¤²°°²Agret²°°²¤_.·´¯)
¸.-~·*'˜¨¯Ï”m_†hê_ôñë_åñd_õñl¥_Åg®ê†¨˜'*·~-.¸
Reply With Quote
  #11  
Old 09-22-2006, 05:20 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
I'd look into TAB again skyld, doesn't work...
__________________

Reply With Quote
  #12  
Old 09-22-2006, 08:58 AM
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 ZeroTrack View Post
I'd look into TAB again skyld, doesn't work...
Yes it does.
Reply With Quote
  #13  
Old 09-22-2006, 01:52 PM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
Err then how come
temp.test = "This" TAB "Tabs";
echo(temp.test);

Didn't create a tab, it delimited it fine... But no tab
__________________

Reply With Quote
  #14  
Old 09-22-2006, 05:05 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
I don't see a problem with it.

It could be that the client F2 window and RC are just not showing tabspaces, but they are being inserted. See the textlist attached.
Attached Thumbnails
Click image for larger version

Name:	Picture 4.png
Views:	1122
Size:	46.6 KB
ID:	37928  
Reply With Quote
  #15  
Old 09-22-2006, 07:09 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Skyld View Post
I don't see a problem with it.

It could be that the client F2 window and RC are just not showing tabspaces, but they are being inserted. See the textlist attached.
I remember using tab with sendtorc, seemed to work fine...
__________________
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 04:00 AM.


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