Jump to content

Looping too Soon


FratbroWilliam

Recommended Posts

# Looping too Soon -- probably common sense

Running a ConditionalSleep until the Player is idle.
(ie. not moving AND not animating)

Logical flow should be:
loop(){
    takeAction()
    waitForIdle()
}

I noticed that the player seemed to be repeatedly clicking to takeAction() rather than actually waiting until the Action stopped, and thus they were idle, before again taking action.
It seemed to happen more frequently when the player had only just arrived at the destination area where the action was to take place.
Threw in some appropriate log() lines to help measure time between actions and began tweaking my conditionalSleeps.
Discover that conditional sleep tests execute *immediately* and then sleep until true, rather than sleeping once before checking; the script was simply executing faster than the player could begin to takeAction.
So I modified the loop.

loop(){
    takeAction()
    sleep(someTime)
    waitForIdle()
}

By adding a short sleep before testing for idle I greatly reduced the amount of excessive clicking which was occurring, however it leaves something to be desired and I am going to be building around it for a bit.
I can theorize a few ways to manually go about getting a script in sync with the game's tick-cycle, however I feel like there's likely something simple in the API which I am overlooking.
sleep(600); // ie. sleep for a gameTick, thus you are within the next gameTick (or however many tick you need) when you have started your action
Sleeping until the next game tick should be sufficient in most cases, especially low-risk ones; but knowledge is power so I will update as I learn more. As a stickler I'd prefer for my conditionalSleep to start being tested ASAP (after the player has actually begun their action), The next tick starts 1 to 600 ms from <now> and I'd prefer to know as precisely as possible, my theories for manual measurement would suffer in high-latency situations; guess it's time to read a lot of documentation.
 

Link to comment
Share on other sites

When you click something and you wait for an idle you have to know that you are actually idle at the moment of the clicking... so the waitforidle is already true
Takes a sec to start moving after clicking.

Instead of waiting for an idle you should wait for something else, for example amount of item you are picking up increasing in your inventory ^^

Edited by Khaleesi
Link to comment
Share on other sites

Mmm, that would be one way of doing it, thank you!

Additionally, something fruitful in the API (specifically regarding waiting until the next gameTick) might be:

 

gameTick = Client.getCurrentTick();

then conditional sleep until (gameTick < Client.getCurrentTick())

and could be adjustable for any number of ticks to have passed, i think; going to play around with it more after work. Idk what margin of error clientTicks can stray from the server itself yet, probably going to need to offset by ping to account for latency as well as do something to account for Processing related variance (frame drops, for any reason not directly related to the Network)

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...