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 01-21-2008, 03:27 AM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
Just going to mess around with some stuff

hey, im Nightmare, and yes, im new to scripting, so now im going to try to learn to script.

im trying to make a weapon that will overheat, this is what i have so far:
PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
this.overheat_max 100;
  
this.overheat 0;
}

function 
onWeaponFired()
{
  
this.active = !this.active;
  if (
this.active)
  {
     
setTimer);
  }
  if (!
this.active)
  {
     
onCreated()
  }
}
function 
onKeyPressed()
{
  if (
this.key "s")
  {
    if (
this.active)
    {
      if (
this.overheat = !100)
      {
        
//shoot functions.. havent gotten that far..
        
this.overheat +=1;
      }
    }
  }
}

function 
onTimeOut()
{
  if (
this.overheat this.overheat_max)
  {
    
//makes it so it cant shoot anymore..
  
}

__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #2  
Old 01-21-2008, 05:57 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Needs some work

One thing I noticed right away was you were doing

if ( var = ! var2 )

use

if ( var != var2 )
__________________
Reply With Quote
  #3  
Old 01-21-2008, 02:15 PM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
Quote:
Originally Posted by cbkbud View Post
Needs some work

One thing I noticed right away was you were doing

if ( var = ! var2 )

use

if ( var != var2 )
ok ty.
__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #4  
Old 01-21-2008, 04:17 PM
Toxen Toxen is offline
A Toxic Fellow
Join Date: Jan 2008
Location: Georgia
Posts: 36
Toxen is on a distinguished road
Well try to change the key pressed part to this,

function onKeyPressed()
{
if (keydown2(getkeycode("s"),true))
{
if (this.active)
{
if (this.overheat = !100)
{
//shoot functions.. havent gotten that far..
this.overheat +=1;
}
}
}
}
Reply With Quote
  #5  
Old 01-21-2008, 04:36 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
this.overheat_max 100;
  
this.overheat 0;
}

function 
onWeaponFired()
{
  
this.active = !this.active;
  if (
this.active)
  {
     
setTimer);
  }
  if (!
this.active)
  {
     
onCreated()
  }
}
function 
onKeyPressedcodekeyind)
{
  if (
temp.key == "s")
  {
    if (
this.active)
    {
      if (
this.overheat != 100)
      {
        
this.angle getanglevecxplayer.dir), vecyplayer.dir));
        
shootthis.xthis.ythis.zthis.angle00"arrow"NULL);
        
this.overheat +=1;
        
sleep0.1);
      }
    }
  }
}

function 
onTimeOut()
{
  if (
this.overheat >= this.overheat_max)
  {
     
this.active 2;

      
sleep5);

      
this.active 1;
  }

  
setTimer0.05);

__________________
Deep into the Darkness peering...
Reply With Quote
  #6  
Old 01-21-2008, 05:45 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Toxen View Post
Well try to change the key pressed part to this,

function onKeyPressed()
{
if (keydown2(getkeycode("s"),true))
{
if (this.active)
{
if (this.overheat = !100)
{
//shoot functions.. havent gotten that far..
this.overheat +=1;
}
}
}
}
Why would you do this? Simply

PHP Code:
function onKeyPressedcodekey )
{
  if ( 
key == "s" )
  {
    if ( 
this.active )
    {
       
// etc
    
}
  }

No need for keydown2 except to tell if something is held down; the onKeyPressed event tells you the key.
__________________
Reply With Quote
  #7  
Old 01-23-2008, 04:31 AM
Toxen Toxen is offline
A Toxic Fellow
Join Date: Jan 2008
Location: Georgia
Posts: 36
Toxen is on a distinguished road
Well hes saying it over heats, so im guessing you needed to charge it ;O?
Reply With Quote
  #8  
Old 01-23-2008, 05:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
For guns you would want something like this:

PHP Code:
function onTimeOut()
{
  
temp.keydown2getKeyCode"s" ), true );
  if ( 
temp.)
  {
    if ( ! 
this.isKeyPressed )
    {
       
// the key is not being held down; has been pressed once.
    
}
    else
    {
      
// the key is being held down; not just pressed once.
    
}
  }
  
this.isKeyPressed temp.k;
  
setTimer0.05 );

Just an example.
__________________
Reply With Quote
  #9  
Old 01-23-2008, 05:06 AM
PrinceOfKenshin PrinceOfKenshin is offline
That guy with a beard
PrinceOfKenshin's Avatar
Join Date: May 2004
Location: Ontario, Canada
Posts: 819
PrinceOfKenshin has a spectacular aura aboutPrinceOfKenshin has a spectacular aura about
Quote:
Originally Posted by cbkbud View Post
For guns you would want something like this:

PHP Code:
function onTimeOut()
{
  
temp.keydown2getKeyCode"s" ), true );
  if ( 
temp.)
  {
    if ( ! 
this.isKeyPressed )
    {
       
// the key is not being held down; has been pressed once.
    
}
    else
    {
      
// the key is being held down; not just pressed once.
    
}
  }
  
this.isKeyPressed temp.k;
  
setTimer0.05 );

Just an example.
I'm kinda new to gs2, why would you use a temp variable for that?
__________________


Quote:
Game Master (Server): Greetings PrinceOfKenshin, there are new posts on the forums that demand your urgent attention! God speed, the fate of the world is in your hands. If you fail, middle earth will forever be in the darkness and your children will be enslaved by McKain.
Reply With Quote
  #10  
Old 01-23-2008, 05:26 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by PrinceOfKenshin View Post
I'm kinda new to gs2, why would you use a temp variable for that?
Because there's no point in taking up memory when this doesn't need to be stored past this function.

If you knew GS1, it's basically equivelant to a variable with no prefix, which is lost after the function is over.

temp.k just told me true/false the key is pressed. I could have eliminated this and made it into an if statement; this was just easier and simpler.

this.isKeyPressed tells me if LAST time around it was pressed, so I can tell if it is being held down, or touched once. This is so you can have modes such as single, automatic, etc.
__________________
Reply With Quote
  #11  
Old 01-23-2008, 05:38 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
in essence, it causes a fraction of a fraction of less lag, (Which adds up quick) It basically saves Memory, (RAM Memory Space).

this.var is saved until it is updated again.

temp.var is saved until the function, that it was called in, ends.

=]
__________________
Deep into the Darkness peering...
Reply With Quote
  #12  
Old 01-24-2008, 03:04 AM
bscharff bscharff is offline
Bloo
bscharff's Avatar
Join Date: Sep 2006
Location: San Antonio, Texas
Posts: 185
bscharff has a little shameless behaviour in the past
Send a message via AIM to bscharff Send a message via MSN to bscharff Send a message via Yahoo to bscharff
*knocks on wood*
__________________
Trying to be nice now...
Reply With Quote
  #13  
Old 01-24-2008, 04:05 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by bscharff View Post
*knocks on wood*
err, what?
__________________
Reply With Quote
  #14  
Old 01-24-2008, 07:50 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by cbkbud View Post
Because there's no point in taking up memory when this doesn't need to be stored past this function.

If you knew GS1, it's basically equivelant to a variable with no prefix, which is lost after the function is over
temp variables still take up memory, it's just stored on the stack versus the heap. Variables defined with no prefix are global, they act now as they did in GS1 for backwards compatibility.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 01-25-2008 at 04:04 AM.. Reason: edited to reflect a good point made by Inver below
Reply With Quote
  #15  
Old 01-25-2008, 01:07 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Function parameters are also automatically temp. variables and can be referenced as such.

Once you declare a temp. variable you can reference it without the prefix and it will not be a global. Because of this for most functions I prefer to declare all my temp.variable = 0; at the beginning of the function.

Ex:
PHP Code:
public function save(filename) {
  
temp.output 0;
  
temp.0;
  
temp.0;
  
temp.keys this.getdynamicvarnames();
  
temp.vars 0;
  
  for (
0keys.size(); ++) {
    if (
this.(@ keys[i]).type() != -1) {
      continue;
    }
    
output.add("[" keys[i] @ "]");
    
vars this.(@ keys[i]).getdynamicvarnames();
    for (
0vars.size(); ++) {
      if (
this.(@ keys[i]).(@ vars[e]) != null) {
        
output.add(vars[e] @ "=" this.(@ keys[i]).(@ vars[e]));
      }
    }
  }
  
output.savelines(filename0);

__________________
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 02:12 PM.


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