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 7569491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:10:44+00:00 2026-05-30T15:10:44+00:00

I have problems when a I call a function that calls the other function

  • 0

I have problems when a I call a function that calls the other function that keep calling back until a puzzle is solved or find no moves.

The thing is that I need to call a function twice but with different values.

I tried storing the values, but as soon as I call the second function wchich calls back, it overrides the values.

the most important pieces of code are here:

function splitways(){
    var strsp,aa=dir,bb=xy;
    if(nextRock()){
        if(xy!=start){
            strsp=(aa+""+bb+""+dir+""+xy)*1;
            if(!(strsp in arr)){
                arr[strsp]=strsp;
                caller(dir,xy);
            }
        }else{
            count++;
        }
    }
}

function caller(num,pos){
    var aa=num,bb=pos;
    splitways();
    //--
    dir=aa;
    xy=bb;
    //--
    dir==1?dir=4:dir--;
    splitways();
}

Notes, splitways() changes the values of dir and xy, that is why I tried to change them back and then modifing them before the second call to splitways(). But with the first call everything is erased.

I tried everything I can for 2 hours… The best shot I had was to cache them on var aa=num,bb=pos; but that didn’t work.

Any ideas are appreciated

  • 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-30T15:10:45+00:00Added an answer on May 30, 2026 at 3:10 pm

    Although I’m not entirely sure what you are trying to do with your code, I think you have some of your logic mixed up:

    On the first call (I assume you are calling splitways() first), you set “aa=dir” (lets only pay attention to this). When “caller()”, it takes the global variable “dir”, obviously. Now, in “caller()”, you set “aa=num” which translates to “aa=dir”. You call splitways again, which then does the exact same thing: “aa=dir”. This continues constantly (AKA: until caller() is stopped being called). However, as it goes back through the execution stack, you have, in “caller()”, “dir=aa”. Now, you already did “aa=num”, so “dir=aa” does absolutely nothing since you haven’t changed the value of “dir” anywhere that has executed yet.

    Eventually, the LATEST “caller()” call will execute the “dir==1?dir=4:dir–” line, but when that function finishes and the execution returns to the SECOND TO LAST “caller()” call, it resets “dir=aa”, so dir is never actually changed until the VERY last call (the first “caller()” execution that happened).

    If that made absolutely no sense, good. There has got to be a better way for you to do what you are trying to do. Maybe I can help with that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that sets a timer, and calls itself back upon expiration
The problem is the following. We have lots of ajax call via $.ajax function.
I have problems filling a temporary table with the resultset from a procedure call
I have problems with dealing with widows within a multicols environment, that is, I
I keep on having these same two problems. I have been trying to use
In C, I have a function that implements both the encryption and decryption routines
I have a stand-alone svg file that displays without problems. It includes some inline
I have a function that removes all of the options from a drop down
I have a jquery game that my members keep finding ways to win. It's
I have created an IHttpAsyncHandler that I'm trying to call using AJAX, with jQuery.

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.