Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:42:49+00:00 2026-05-28T02:42:49+00:00

I have a recursive function which contains some drawing code inside. I was advised

  • 0

I have a recursive function which contains some drawing code inside. I was advised to use setTimeout as my drawing was not being displayed until the end of exection. First I put just the drawing code inside setTimeout but this did not help, however when I put the main recursive loop inside setTimeout the drawing worked perfectly, as shown below.

However I need to use the return value of setTimeout (i.e. state as shown below). How can I get this return value when using setTimeout, or solve this problem in another way.

var doLearning = function(time, observedData, state, domain, sampleAction, selectModel, numSamples, depth, discount, stateQueries) {
    if(stateQueries[0](time, state) === true) {
        console.log("New Round");
        var currentModel = selectModel(observedData, 10, stateQueries);
        var bestAction = sparseSampleMcmc(depth, numSamples, discount, currentModel, state, sampleAction, stateQueries);
        var newStateReward = domain.executeAction(bestAction, stateQueries);
        observedData.push(bestAction, newStateReward[1], newStateReward[0]);
        console.log(time);
        setTimeout(doLearning, 100, time + 1, observedData, newStateReward[0], domain, sampleAction, selectModel, numSamples, depth, discount, stateQueries);
    } else {
        console.log("Game Over");
        return state;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:42:50+00:00Added an answer on May 28, 2026 at 2:42 am

    Make an object with all your vars, like:

    var game = {
         time: ... ,
         observedData: ...., 
         state: .... etc
     }
    

    In doLearning get and modify this object’s properties when necessary:

      var doLearning = function(obj) {
    
           if(obj.state == ....)
               obj.currentModel = whatever...
               obj.bestAction = whatever...
               setTimeout(function() { doLearning(obj) }, 100)
           else
               game over
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some sort of recursive function, but I need to parse a string,
I have the following recursive function which works... up until a point. Then the
I have recursive function which walk nested dict and return needed key's value: def
I have a recursive function which can be written like: void func(TypeName *dataStructure, LL_Node
I have a recursive function fact , which can be called from either an
I have a recursive function reading a table of contents of documents from a
I have a simple recursive function RCompare() that calls a more complex function Compare()
Is it possible to have a PHP function that is both recursive and anonymous?
I have a recursive algorithm which steps through a string, character by character, and
I have a recursive table in which each record has an ID and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.