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 08-31-2006, 04:41 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Learning GS2 :D

I was problem solving with Chicken yesterday and he was teaching me about each aspect of GS2. So I learned alot really. Here's a couple things I put together with Chicken_l33t.

Simple Light Switch

PHP Code:
function onCreated()
{
this.Number_1 0;
this.Number_2 0;
if (
this.Number_1 this.Number_2 0);
this.value 0;
}
function 
onPlayertouchesme()
{
if (
this.value 0);
this.value 1;
player.chat "On!";
}
else 
{
this.value 0;
player.chat "Off!";

Chat Text Changer

PHP Code:
function onCreated()
{
this.StringArray "GS1 sux.","GS2 is awesome.","blah";
}
function 
onPlayerchats()
{
this.value int(random(0,2));
player.chat this.StringArray[this.value];

How'd I do for a beginner?

E: Eew wasn't in PHP. My bad. :]
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #2  
Old 08-31-2006, 04:57 PM
KuJi KuJi is offline
Banned
Join Date: Apr 2004
Location: Staten Island, New York
Posts: 2,202
KuJi will become famous soon enough
Send a message via ICQ to KuJi Send a message via AIM to KuJi Send a message via MSN to KuJi Send a message via Yahoo to KuJi
One of my irl friends wanted to learn @ 3 AM yesterday (around the time you imed me :o).

He made a staff npc or so with a buncha commands in like 20-30 minutes. :P
Reply With Quote
  #3  
Old 09-01-2006, 12:05 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
PHP Code:
this.test "foo","bar","baz"
... is incorrect. You should use this for arrays:
PHP Code:
this.test = {"foo""bar""baz"}; 
Also, you need to put if checks as a block. This is incorrect:
PHP Code:
if (this.foo);
bar(); 
This is correct:
PHP Code:
if (this.foo)
{
  
bar();

Also, you forgot to close your brackets on a function.
PHP Code:
function onFoo()
{
  
//

Also, you can just do this.value = !this.value; to make a toggle for this.value being true or false.
PHP Code:
function onWeaponFired()
{
  
this.enabled = !this.enabled;

  if (
this.enabled)
  {
    
//
  
}
    else
  {
    
//
  
}

Also, don't use = inside an if statement, since = is assignment. You are probably overwriting the value by using = inside an if. Use == instead since it doesn't do anything but compare:
PHP Code:
this.value 3;

if (
this.value == 3)
{
  
//

Also, it's onPlayerTouchsMe(), not onPlayerTouchesMe().

Sorry.
Reply With Quote
  #4  
Old 09-01-2006, 12:55 AM
zephirot zephirot is offline
Banned?
Join Date: Sep 2004
Location: Paris
Posts: 1,311
zephirot is a name known to allzephirot is a name known to allzephirot is a name known to all
Send a message via AIM to zephirot Send a message via MSN to zephirot
Skyld, teach me how to script .
__________________

Quote:
Originally Posted by unixmad
Can you just shut up ?
MAGA
MFGA
MEGA
Reply With Quote
  #5  
Old 09-01-2006, 01:36 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Skyld
PHP Code:
this.test "foo","bar","baz"
... is incorrect. You should use this for arrays:
PHP Code:
this.test = {"foo""bar""baz"}; 
What's wrong with me using
PHP Code:
this.StringArray = {"foo","bar","baz"}; 
Quote:
Also, you need to put if checks as a block. This is incorrect:
PHP Code:
if (this.foo);
bar(); 
Don't quite understand why this is necessary? I'm not trying to make an event or call a function or whatever it is. I simply wanted to change the players chat. These were two different scripts. :[

Quote:
This is correct:
PHP Code:
if (this.foo)
{
  
bar();

How does is this relevant to what I was trying to do? You'd have to show me Skyld as from reading it it doesn't seem it applies to anything I was aimnig for.

Quote:
Also, you forgot to close your brackets on a function.
PHP Code:
function onFoo()
{
  
//

Err, I thought I did. That's my mistake then. Very careless of me I agree with you.

Quote:
Also, you can just do this.value = !this.value; to make a toggle for this.value being true or false.
PHP Code:
function onWeaponFired()
{
  
this.enabled = !this.enabled;

  if (
this.enabled)
  {
    
//
  
}
    else
  {
    
//
  
}

I haven't quite gotten to learning these more advanced ways of putting things. Hence me putting "Learning GS2".

Quote:
Also, don't use = inside an if statement, since = is assignment. You are probably overwriting the value by using = inside an if. Use == instead since it doesn't do anything but compare:
PHP Code:
this.value 3;

if (
this.value == 3)
{
  
//

Also, it's onPlayerTouchsMe(), not onPlayerTouchesMe().

Sorry.
Alas another careless mistake on my part. But I'm learning new things and basically using caveman style GS2. The basic of basic commands here. :/
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #6  
Old 09-01-2006, 01:41 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Here I rewrote it zeroing in on all problems. Be happy Skyld and leave me and my caveman scriptign alone. >:[

PHP Code:
function onCreated()
{
this.value 0;
}
function 
onPlayerTouchsMe()
{
if (
this.value 0);
this.value 1;
player.chat "On!";
}
else
{
this.value 0;
player.chat "Off!";

__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.

Last edited by killerogue; 09-01-2006 at 01:42 AM.. Reason: Forgot to add the last PHP tag.
Reply With Quote
  #7  
Old 09-01-2006, 05:10 AM
Moondeath_2 Moondeath_2 is offline
"..."
Moondeath_2's Avatar
Join Date: Jan 2006
Location: Far Far Away.
Posts: 238
Moondeath_2 is an unknown quantity at this point
Send a message via AIM to Moondeath_2 Send a message via MSN to Moondeath_2 Send a message via Yahoo to Moondeath_2
Meow. I feel like teaching and stuff, if anyone is paying attention to this forum and wishes to aim me for some scripting help. I'll try to be as of best help as possible even considering it's late, and i'm sick.


Edit: Come onnnnnn i'm bored >_>
__________________
Aim: DarkFireXZ3
Email: [email protected] or [email protected]
Common Location: Unholy Nation
Gscript, Playerworld Rules, Support Center
Reply With Quote
  #8  
Old 09-01-2006, 03:26 PM
zephirot zephirot is offline
Banned?
Join Date: Sep 2004
Location: Paris
Posts: 1,311
zephirot is a name known to allzephirot is a name known to allzephirot is a name known to all
Send a message via AIM to zephirot Send a message via MSN to zephirot
Well, I added you , as soon as you lgo on AIM, I will bug you.
__________________

Quote:
Originally Posted by unixmad
Can you just shut up ?
MAGA
MFGA
MEGA
Reply With Quote
  #9  
Old 09-01-2006, 05:02 PM
_Z3phyr_ _Z3phyr_ is offline
Banned
Join Date: Sep 2003
Location: Louisiane
Posts: 390
_Z3phyr_ is an unknown quantity at this point
Quote:
this.enabled = !this.enabled;
I like that as a switch.

What I previously used was
PHP Code:
this.enabled this.enabled
but that's more simple.
Reply With Quote
  #10  
Old 09-01-2006, 05:45 PM
Draenin Draenin is offline
Magnificent Bastard
Draenin's Avatar
Join Date: Dec 2004
Location: Bermuda Triangle
Posts: 6,790
Draenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud ofDraenin has much to be proud of
Send a message via AIM to Draenin Send a message via MSN to Draenin Send a message via Yahoo to Draenin
Quote:
Originally Posted by killerogue
What's wrong with me using
PHP Code:
this.StringArray = {"foo","bar","baz"}; 
Because that format is mainly used for arrays, which are a little different than a plain variable.

This is a lot more efficient, though: (Not to mention, it should work.)
PHP Code:
function onCreated()
{
this.value 0;
}
function 
onPlayerTouchsMe()
{
if (
this.value 0);
this.value 1;
player.chat "On!";
}
else
{
this.value 0;
player.chat "Off!";

The else case is a bit unnecessary, though, as the variable this.value will stay at 0 unless you change it, which you have done in your if case.
Reply With Quote
  #11  
Old 09-01-2006, 08:18 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
there are a couple of minor problems with your code there, problems that will stop it executing the way you expect it to.

PHP Code:
...
if (
this.value 0); //here
this.value 1;
player.chat "On!";
}
else {
... 
Firstly, after an if should be a { not a ;.
Secondly, comparision is done with == not =.

= is used to set values and can be read as "becomes". == can be read as "is equal to", so that line of code should be this:
PHP Code:
if (this.value == 0) { 
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #12  
Old 09-11-2006, 06:58 PM
jami_jamie jami_jamie is offline
Registered User
jami_jamie's Avatar
Join Date: Jan 2006
Posts: 9
jami_jamie is on a distinguished road
Quote:
Originally Posted by JkWhoSaysNi
Secondly, comparision is done with == not =.

= is used to set values and can be read as "becomes". == can be read as "is equal to", so that line of code should be this:
PHP Code:
if (this.value == 0) { 
We already picked up on that during this thread. Dont repeat it. xD
Reply With Quote
  #13  
Old 09-12-2006, 03:32 AM
Chicken_l33t Chicken_l33t is offline
Banned
Join Date: Sep 2002
Location: NewZealand
Posts: 467
Chicken_l33t is on a distinguished road
Now I look like a noob, lol. Anyway good work with the fixing of it killer.
Reply With Quote
  #14  
Old 09-12-2006, 02:42 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Draenin
Because that format is mainly used for arrays, which are a little different than a plain variable.

This is a lot more efficient, though: (Not to mention, it should work.)
PHP Code:
function onCreated()
{
this.value 0;
}
function 
onPlayerTouchsMe()
{
if (
this.value 0);
this.value 1;
player.chat "On!";
}
else
{
this.value 0;
player.chat "Off!";

The else case is a bit unnecessary, though, as the variable this.value will stay at 0 unless you change it, which you have done in your if case.
If you're going to use PHP tags, please format your code so it's readable.

Also, there are a few errors, such as the semi-colon after the if statement, and the fact that you are missing a curly-brace at the end (which would have been easily distinguishable if you had formatted your code )

Fixed (Differentish) version:

PHP Code:
function onCreated() {
  
this.value false;  // Kind of redundant, values get reset when the NPC is created serverside anyway.
}

function 
onPlayerTouchsMe() {
  
this.value = !this.value;

  if(
this.value) {
    
player.chat "On";
  } else {
    
player.chat "Off";
  }

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #15  
Old 09-12-2006, 02:43 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jami_jamie
We already picked up on that during this thread. Dont repeat it. xD
It wasn't fixed in Draenin's example. Don't reply to the thread if you don't read it
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
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 10:32 AM.


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