Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   My script isn't working, what to do. A step by step guide. (https://forums.graalonline.com/forums/showthread.php?t=134258209)

Liberated 02-28-2010 09:20 PM

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.

xAndrewx 02-28-2010 09:39 PM

Hmm- what is it you're trying to do? like a jump script?

Liberated 02-28-2010 09:41 PM

Quote:

Originally Posted by xAndrewx (Post 1559644)
Hmm- what is it you're trying to do? like a jump script?

did you bother reading the post?

xAndrewx 02-28-2010 09:44 PM

I did- but really it sounded as though you had a problem, not how you debug your graal codes lol

fowlplay4 02-28-2010 09:51 PM

It also helps to use functions instead of excessive amounts of nesting.

xAndrewx 02-28-2010 09:54 PM

I don't mean to sound rude- but can you also explain what your code is supposed to do? thank you

Liberated 02-28-2010 10:08 PM

Quote:

Originally Posted by xAndrewx (Post 1559649)
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 (Post 1559641)
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.

Crow 02-28-2010 10:09 PM

Quote:

Originally Posted by xAndrewx (Post 1559649)
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.

xAndrewx 02-28-2010 10:10 PM

Quote:

Originally Posted by Crow (Post 1559657)
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

adam 03-01-2010 12:58 AM

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.

WhiteDragon 03-01-2010 12:59 AM

sleep() is terrible by the way, guys. Use scheduleevent/timeout or waitfor depending on what you need.

Crow 03-01-2010 01:53 PM

Quote:

Originally Posted by xAndrewx (Post 1559660)
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.

xAndrewx 03-01-2010 09:32 PM

Quote:

Originally Posted by Crow (Post 1559876)
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

adam 03-01-2010 09:52 PM

Quote:

Originally Posted by xAndrewx (Post 1559965)
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?

DustyPorViva 03-01-2010 09:59 PM

Debugging takes a little logic and problem-solving skills. If you lack that, good luck!


All times are GMT +2. The time now is 12:40 AM.

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