Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: 2D pole  (Read 4623 times)

0 Members and 1 Guest are viewing this topic.

Siky

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 41
    • View Profile
2D pole
« on: May 31, 2007, 06:24:45 PM »

Můžete mi někdo poradit proč mi nechodí to dvoudimenzionální pole array1?

Code: [Select]
var array1 = new Array();

function napln_data()
{
var temp1;
var array2 = new Array();
for (var j=0; j<3; j=j+1)
{
  for (var i=0; i<3; i=i+1)
  {
    array2[i] = 10*i+j;
    Game.LOG(array2[i]);
  }
  temp1.array = array2;
  array1[j] = temp1;
}

}

function vypis_data()
{
var t;
var t2;
for (var j=0; j<3; j=j+1)
{
  t = array1[j];
  for (var i=0; i<3; i=i+1)
  {
    t2 = t.array;
    Game.LOG(t2[i]);
  }
}

Po volání:
Code: [Select]
napln_data();
Game.LOG("----------");
vypis_data();

to vypíše:
Code: [Select]
19:16: 0
19:16: 10
19:16: 20
19:16: 1
19:16: 11
19:16: 21
19:16: 2
19:16: 12
19:16: 22
19:16: ----------
19:16: 2
19:16: 12
19:16: 22
19:16: 2
19:16: 12
19:16: 22
19:16: 2
19:16: 12
19:16: 22

Mělo by to přeci vypsat ta samá data, ne?
dík za radu
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: 2D pole
« Reply #1 on: May 31, 2007, 06:55:57 PM »

Protoze array2 je porad tentyz objekt, jenom ho plnis trikrat, takze v nem zustanou ty posledni hodnoty.
Zrejme jsi mel na mysli spis tohle:

Code: [Select]
function napln_data()
{
  var temp1; 
  for (var j=0; j<3; j=j+1)
  {
    var array2 = new Array();
    for (var i=0; i<3; i=i+1)
    {
      array2[i] = 10*i+j;
      Game.LOG(array2[i]);
    }
    temp1.array = array2;
    array1[j] = temp1;
  }
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Siky

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 41
    • View Profile
Re: 2D pole
« Reply #2 on: May 31, 2007, 07:01:33 PM »

Jo, to je přesně ono, to jsem přehlédl. Díky
Logged
 

Page created in 0.03 seconds with 18 queries.