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 02-28-2010, 09:20 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
My script isn't working, what to do. A step by step guide.

How i check my scripts.
I understand that i am quite the nooby scripter,
but i figured that there are more noobier scripters out there.
And i was hoping this method i use might help more people.
This method is strictly about problems that the npc server doesn't show
when you update your script.
This is the script that i will be using to demonstrate this method,
i have deliberately faulted it,
because i thought it would be clearer like this then working with a functional script.
PHP Code:
//#CLIENTSIDE
function onKeyPressed(code,key)
{
  if( 
key == "f")
  {
    if(
player.== 1)
    {
      
replaceAni("walk""idle");
      
temp.0;
      while(
temp.4)
      {
        
temp.+= 0.5;
        
player.+= 0.2/temp.i;
        
sleep(0.05);
        if(
player.1)
        {
          
settimer(0.05);
        }
        else if(
temp.== 4)
        {
          
temp.0;
          while(
temp.4)
          {
            
temp.+= 0.5;
            if(
player.< -0.5)
            {
              
replaceAni("walk""walk");
              
player.0;
              
sleep(0.05);
            }
            else
            {
              
player.-= 0.2/temp.i;
              
sleep(0.05);
            }
          }
        }
      }
    }  
  }

now this script is not completely functioning, because i have put 2 errors in here.
NOw here is the method i use:
I take this line:
PHP Code:
player.chat "succes"
but you can also use an echo if you prefer.
And i put it after the first conditional, like this.
PHP Code:
//#CLIENTSIDE
function onKeyPressed(code,key)
{
  if( 
key == "f")
  {
    
player.chat == "succes";
    if(
player.== 1)
    {
      
replaceAni("walk""idle");
      
temp.0;
      while(
temp.4)
      {
        
temp.+= 0.5;
        
player.+= 0.2/temp.i;
        
sleep(0.05);
        if(
player.1)
        {
          
settimer(0.05);
        }
        else if(
temp.== 4)
        {
          
temp.0;
          while(
temp.4)
          {
            
temp.+= 0.5;
            if(
player.< -0.5)
            {
              
replaceAni("walk""walk");
              
player.0;
              
sleep(0.05);
            }
            else
            {
              
player.-= 0.2/temp.i;
              
sleep(0.05);
            }
          }
        }
      }
    }  
  }

Because there is nothing wrong with this part, whenever i press f,
my player will say "succes".

I will delete the player.chat i have put in my script,
and put it after the next conditional.
Like this.
PHP Code:
//#CLIENTSIDE
function onKeyPressed(code,key)
{
  if( 
key == "f")
  {
    if(
player.== 1)
    {
      
player.chat "succes"
      
replaceAni("walk""idle");
      
temp.0;
      while(
temp.4)
      {
        
temp.+= 0.5;
        
player.+= 0.2/temp.i;
        
sleep(0.05);
        if(
player.1)
        {
          
settimer(0.05);
        }
        else if(
temp.== 4)
        {
          
temp.0;
          while(
temp.4)
          {
            
temp.+= 0.5;
            if(
player.< -0.5)
            {
              
replaceAni("walk""walk");
              
player.0;
              
sleep(0.05);
            }
            else
            {
              
player.-= 0.2/temp.i;
              
sleep(0.05);
            }
          }
        }
      }
    }  
  }

You will see that the player will now not say anything,
which means that there is an error somewhere in the script between here and the last conditional.
The error is obviously that player.z starts at 0,
so as long as our player is on the ground, nothing will happen.

Once we fix this, this script is still not working,
because there is also an error further ahead in the script.
So if you know how your script is supposed to work, you can check it step by step,
in the order of which your script is supposed to work.
And you should be able to locate the errors.
Now that you have located the errors, you can use the /scripthelp command on the RC,
Check the wiki. http://wiki.graal.us, search the forum if a topic about it exists,
ask a friend for help, and if all of that didn't work,
post a topic on the forums about your problem.

I hope this has helped some people, and again, i know that i'm not a good scripter(yet).
But i think this method might help some people. And help people understand how their scripts work.
And how to fix them if they are not working.

And, although i might have better put this at the start,
in case you don't understand what the script is supposed to do.
this is a script that makes your player jump in the air, although not over objects yet.
Reply With Quote
  #2  
Old 02-28-2010, 09:39 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
Hmm- what is it you're trying to do? like a jump script?
__________________
Reply With Quote
  #3  
Old 02-28-2010, 09:41 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
Quote:
Originally Posted by xAndrewx View Post
Hmm- what is it you're trying to do? like a jump script?
did you bother reading the post?
Reply With Quote
  #4  
Old 02-28-2010, 09:44 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
I did- but really it sounded as though you had a problem, not how you debug your graal codes lol
__________________
Reply With Quote
  #5  
Old 02-28-2010, 09:51 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It also helps to use functions instead of excessive amounts of nesting.
__________________
Quote:
Reply With Quote
  #6  
Old 02-28-2010, 09:54 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
I don't mean to sound rude- but can you also explain what your code is supposed to do? thank you
__________________
Reply With Quote
  #7  
Old 02-28-2010, 10:08 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
Quote:
Originally Posted by xAndrewx View Post
I don't mean to sound rude- but can you also explain what your code is supposed to do? thank you

Quote:
Originally Posted by Liberated View Post
And, although i might have better put this at the start,
in case you don't understand what the script is supposed to do.
this is a script that makes your player jump in the air, although not over objects yet.
this.
Reply With Quote
  #8  
Old 02-28-2010, 10:09 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
I don't mean to sound rude- but can you also explain what your code is supposed to do? thank you
Doesn't matter, he's just trying to show how he debugs his code. I'd say it'd be easier (better even) to use a this.var instead, and then monitoring it with Jerret's debugger.
Reply With Quote
  #9  
Old 02-28-2010, 10:10 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 Crow View Post
Doesn't matter, he's just trying to show how he debugs his code. I'd say it'd be easier (better even) to use a this.var instead, and then monitoring it with Jerret's debugger.
of-course it matters.

HTML Code:
function onKeyPressed(code, key) {
  if (temp.key == "w") {
    player.z = 0.05;
    for (temp.i = 0; temp.i < 1; temp.i += 0.05) {
      if (player.z > 0) {
        player.z += (temp.i > 0.5? -temp.i: temp.i);
      } else {
        player.z = 0;
      }
      sleep(0.05);
    }
  }
}
A basic jump script
__________________

Last edited by xAndrewx; 02-28-2010 at 10:23 PM..
Reply With Quote
  #10  
Old 03-01-2010, 12:58 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
Not a bad help. I'm sure it will help many people. It's ok to script things into your scripts to help you see what's going on.
__________________
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
  #11  
Old 03-01-2010, 12:59 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
sleep() is terrible by the way, guys. Use scheduleevent/timeout or waitfor depending on what you need.
Reply With Quote
  #12  
Old 03-01-2010, 01:53 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
of-course it matters.
It does not in this case. This thread is supposed to be a guide on how to easily debug your script, not which code to use for a certain purpose. The script in the OP serves purely as an example.
Reply With Quote
  #13  
Old 03-01-2010, 09:32 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 Crow View Post
It does not in this case. This thread is supposed to be a guide on how to easily debug your script, not which code to use for a certain purpose. The script in the OP serves purely as an example.
Right- so in this case what you're saying is he should have just posted "I debug my scripts using the players chat!"? lol
__________________
Reply With Quote
  #14  
Old 03-01-2010, 09:52 PM
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 xAndrewx View Post
Right- so in this case what you're saying is he should have just posted "I debug my scripts using the players chat!"? lol
So.. you misunderstood the point of the entire post, and now your still not going to let it go?
__________________
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
  #15  
Old 03-01-2010, 09:59 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Debugging takes a little logic and problem-solving skills. If you lack that, good luck!
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 05:34 AM.


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