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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:15:27+00:00 2026-05-26T01:15:27+00:00

I’m trying to combine a few similar functions into a single functions, which need

  • 0

I’m trying to combine a few similar functions into a single functions, which need to make calls to different arrays / variables, but I’m not quite getting it right. Here’s my code:

var initialPreloadArray = ['scenes/icons_orange.png','scenes/icons_blue.png','scenes/icons_green.png','site/pedestal_h.png']; //These must be loaded before we advance from the intro screen
var initialPreloadCounter = 0;
var secondaryPreloadArray = ['site/restart-black.png','site/back_black.png','interludes/city.png','interludes/town.png','interludes/country.png']; //These must be loaded before we can advance from the initial decision scene
var secondaryPreloadCounter = 0;
var vehiclesPreloadArray = ['vehicles/vehicles.png','site/close.png']; //These must be loaded before we can display the vehicles
var vehiclesPreloadCounter = 0;
var arrName; //Store the variable name of the array for the stage of preloading we're in
var arrCounter; //Stores the variable name of the counter for the stage of preloading we're in

function setPreloadStage(preloadStage){
    if (preloadStage == initial){
        arrName = initialPreloadArray;
        arrCounter = initialPreloadCounter;
    } else if (preloadStage == 'secondary'){
        arrName = secondaryPreloadArray;
        arrCounter = secondaryPreloadCounter;
    } else if (preloadStage == 'vehicles'){
        arrName = vehiclesPreloadArray;
        arrCounter = vehiclesPreloadCounter;
    }
    preloadImages(preloadStage);
}



//Recurse through scene xml and populate scene array
function preloadImages(preloadStage) {
    console.log(arrName[arrCounter]);
    var img = new Image();
    img.src = 'images/' + arrName[arrCounter];
    if(!img.complete){
        jQuery(img).bind('error load onreadystatechange', imageComplete(preloadStage));
    } else {
        imageComplete(preloadStage);
    }

    //$j.preloadCssImages({statusTextEl: '#textStatus', statusBarEl: '#status'});
}

function imageComplete(preloadStage){
    arrCounter++;
    var preloadLength = arrName.length-1;
    if (arrName && preloadLength && arrName[arrCounter]) {
        if (preloadLength == arrCounter){
            if (preloadStage == 'initial'){
                initialImagesLoaded();
            } else if (preloadStage == 'secondary'){
                secondaryImagesLoaded();
            } else if (preloadStage == 'vehicles'){
                vehiclesLoaded();
            }
        }
        preloadImages(preloadStage);
    }
}

Anybody have an idea what I’m doing wrong?

  • 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-26T01:15:27+00:00Added an answer on May 26, 2026 at 1:15 am

    I suggest that you should use an array to manage state.

    define an array holding your stages, like this:

    var stages = [
      { 
         label : 'initial', 
         imgs : [ 'img/whoobee.png', ...more here...], 
         doneSoFar: 0, 
         allDone: function(){} 
      }, 
      { label : 'secondary', imgs : .....}, 
      { label : 'whatever', imgs :  ....}
    ];
    

    NB: You will need to set the “allDone” fn for each stage appropriately.

    Then a fn that kicks off one stage:

    function kickoffPreloadOneStage(stage) {
       console.log ("preloading stage " + stage.label);
       preloadNextImage(stage);
    }   
    
    function preloadNextImage(stage) {
        var img = new Image();      
        img.src = 'images/' + stage.imgs[stage.doneSoFar];      
        if(!img.complete){      
            jQuery(img).bind('error load onreadystatechange', function() {
                 imageComplete(preloadStage);
            });      
        } 
        else {      
            imageComplete(preloadStage);      
        } 
    }
    
    function imageComplete(stage){       
        stage.doneSoFar++;       
        var preloadLength = stage.imgs.length-1;       
        if (stage.doneSoFar == preloadLength) {
            stage.allDone(); // call the allDone function. may want to pass stage back
        }
        else {
            preloadNextImage(stage);       
        }       
    }  
    

    To do all stages, use code like this:

    var i;
    for(i=0; i < stages.length; i++) {
        kickoffPreloadOneStage(stages[i]);
    }
    

    You can also go OO, defining those functions as members of a Stage() class, but ….what I suggested is a reasonable simplification without getting too complicated.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.