Jump to content

Help a newbie


xakingas

Recommended Posts

Hello and happy Christmas everyone, I'm really new on scripting and started to make my first script (simple power fisher). After coding the basis I tried to run the script on a test account, but after the login handler logs in the account, the client pretty much freezes and processor goes 100%, anyone has an idea where I messed up? I think I'm returning something somewhere where I shouldn't

code.jpg

Edited by xakingas
Link to comment
Share on other sites

the scriptmanifest has a missing parameter logo

version = 0, logo = "")

more:

getAnimation == -1 is same as !if(myPlayer().isAnimating() {

i would avoid returning the value 444 or anything else than 0, the script needs to work like clockwork because logic will break

+ the bot will be sluggish (it adds up weird pattern characteristics on top )

use conditional sleeps on condition, static sleeps are more or less used for debugging

conditional sleeps make sure that if your latency spikes or irrelevant event occurs, ur script still sleeps --> very until the condition is done

Edited by extatus
Link to comment
Share on other sites

6 hours ago, xakingas said:

After coding the basis I tried to run the script on a test account, but after the login handler logs in the account, the client pretty much freezes and processor goes 100%, anyone has an idea where I messed up?

I'm not sure if this will fix the problem but you should't have a variable holding the inventory instance. Just get the inventory instance every time you need to use it. And fishing spots are npcs, not objects.

6 hours ago, extatus said:

i would avoid returning the value 444 or anything else than 0, the script needs to work like clockwork because logic will break

:???:

  • Like 1
Link to comment
Share on other sites

Your inv variable is not in the proper scope of your script.

You are checking if the inventory is full in your onloop, but your inv variable is outside of the onloop, maybe it's right but it looks wrong to me. Also you are using a while loop which is frowned upon because your onloop is already an endless loop. Two endless loops is redundant. All you need to do is check if your player is animating there is a function. myPlayer().isAnimating() I think.

The way I would do it would be this:

if (!myPlayer().isAnimating()) {
  RS2Object Bubul = getObjects().closest(1530);//bubbles
  if (Bubul != null) {
    Bubul.interact("Net");
    new ConditionalSleep(5_000) {
      @Override
      public boolean condition() throws InterruptedException {
      	return myPlayer().isAnimating();
      }
    }.sleep();
  }
}

 

Link to comment
Share on other sites

4 hours ago, Script Kid said:

I'm not sure if this will fix the problem but you should't have a variable holding the inventory instance. Just get the inventory instance every time you need to use it. And fishing spots are npcs, not objects.

:???:

Just to clarify, as i posted that in 5 am. :lol:

As Haysae mentioned, the onLoop is already an endless loop.  If your script breaks to ping fluctuation or script not looping perfectly, using >0 return values means artificially recreating slugginess that is completely unnecessary. If the script skips lines, it mightn't find your condition on the first try. 

On top of that, if the script were fairly simple and did 1-2 actions before naturally looping again, the outcome would be sluggy anyway.

Link to comment
Share on other sites

9 hours ago, Script Kid said:

I'm not sure if this will fix the problem but you should't have a variable holding the inventory instance. Just get the inventory instance every time you need to use it. And fishing spots are npcs, not objects.

:???:

Thank you, the inventory was probably breaking it up, works fine now, THANKS!

  • Like 1
Link to comment
Share on other sites

10 hours ago, xakingas said:

Thank you, the inventory was probably breaking it up, works fine now, THANKS!

FYI it was breaking because you're calling getInventory() before the inventory is available. Most API functions should be saved for your onLoop() as they require the game to be loaded / an account logged in to work correctly. 

Link to comment
Share on other sites

On 12/26/2018 at 12:51 PM, extatus said:

Just to clarify, as i posted that in 5 am. :lol:

As Haysae mentioned, the onLoop is already an endless loop.  If your script breaks to ping fluctuation or script not looping perfectly, using >0 return values means artificially recreating slugginess that is completely unnecessary. If the script skips lines, it mightn't find your condition on the first try. 

On top of that, if the script were fairly simple and did 1-2 actions before naturally looping again, the outcome would be sluggy anyway.

Sorry, that is simply not true.

The number returned by the onLoop method is amount of time the script executor will wait before invoking the method again. If this delay is set to 0, it will attempt to run the script as fast as possible, invoking the method as many times per second as your CPU can. Since the server updates the game at the very slow pace of 100 times per minute, having 1 ms or less delay between iterations is unnecessary, extremely inefficient, and can even cause the client to freeze (happened a few minutes ago when I tested running with 0 ms delay).

Most scripting tutorials recommend adding a delay, this one included:

And it was made by @Alek.

Link to comment
Share on other sites

1 hour ago, Script Kid said:

Sorry, that is simply not true.

The number returned by the onLoop method is amount of time the script executor will wait before invoking the method again. If this delay is set to 0, it will attempt to run the script as fast as possible, invoking the method as many times per second as your CPU can. Since the server updates the game at the very slow pace of 100 times per minute, having 1 ms or less delay between iterations is unnecessary, extremely inefficient, and can even cause the client to freeze (happened a few minutes ago when I tested running with 0 ms delay).

Most scripting tutorials recommend adding a delay, this one included:

And it was made by @Alek.

I stand corrected. In that case, you're completely right .

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...