www.webdeveloper.com
Results 1 to 2 of 2

Thread: Array returned from a function : Can't make it work.

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Location
    France
    Posts
    23

    Array returned from a function : Can't make it work.

    Hello,

    I have an array created in a function. But i can't use the array out of the function. In the code here, the two "alert boxes" give an undefined error for the array "fighters".

    I tried to put the "new array() line in the external as in the internal function, without make any difference. Can somebody help me, here ?

    => The array exist and contain the datas in the most internal function.

    Code:
    	fighters = new Array();
    	var db = openDatabase('furfight', '1.0', 'Fighting text game', 100 * 1024 * 1024);
    	db.transaction(function (tx)
    		{
    			
    		
    		// debug data :
    		j1="Wolf";
    		j2="Cat";
    		j3="Rabbit";
    		// debug data end.
    
    
    		tx.executeSql('SELECT * FROM race where name IN (?,?,?)', [j1,j2,j3], function (tx, data)
    			{
    			for(var i = 0; i < data.rows.length; i++)
    				{
    				fighters[i] = new Array(data.rows.item(i).name,data.rows.item(i).strength,data.rows.item(i).agility,data.rows.item(i).dexterity,data.rows.item(i).stamina,data.rows.item(i).size);
    					
    				}
    			
    			return fighters;
    
    			});
    			alert("1 "+fighters[0][0]);
    			return fighters;
    			
    			
    		});
    			alert("2 "+fighters[0][0]);

  2. #2
    Join Date
    Mar 2012
    Location
    France
    Posts
    23
    Okay, don't sweat, it's again the asynchronous JS implementation of SQL... Gr

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles