www.webdeveloper.com
Results 1 to 2 of 2

Thread: Values "randomly" lost in a function passing

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

    Values "randomly" lost in a function passing

    Hello.

    I have these lines :

    function damages(i,fighter,damage2,damage3)
    {
    text.innerHTML += "<br>********** "+fighter[0][5]+ " : vie "+damage2[fighter[0][0]]+" -- fatigue "+damage3[fighter[0][0]];
    text.innerHTML += "<br>********** "+fighter[1][5]+ " : vie "+damage2[fighter[1][0]]+" -- fatigue "+damage3[fighter[1][0]];
    text.innerHTML += "<br>********** "+fighter[2][5]+ " : vie "+damage2[fighter[2][0]]+" -- fatigue "+damage3[fighter[2][0]];

    db.transaction(function (tx)
    {
    text.innerHTML += "<br>********** "+fighter[0][5]+ " : vie "+damage2[fighter[0][0]]+" -- fatigue "+damage3[fighter[0][0]];
    text.innerHTML += "<br>********** "+fighter[1][5]+ " : vie "+damage2[fighter[1][0]]+" -- fatigue "+damage3[fighter[1][0]];
    text.innerHTML += "<br>********** "+fighter[2][5]+ " : vie "+damage2[fighter[2][0]]+" -- fatigue "+damage3[fighter[2][0]];
    The two "text.innerHTML" bloc are the same.

    But the results are not the same :


    ********** Cat : vie 2 -- fatigue 3
    ********** Wolf : vie 3 -- fatigue 5
    ********** Rabbit : vie 0 -- fatigue 2
    ..

    ********** Cat : vie 2 -- fatigue 3
    ********** Wolf : vie 0 -- fatigue 0
    ********** Rabbit : vie 0 -- fatigue 0
    I mean... what ? Why some values are lost and not the others ?
    --
    Friendly yours, D.Durand

    My pet project : http://ratsodie.blogspot.fr/, a civ game in javascript

  2. #2
    Join Date
    Mar 2012
    Location
    France
    Posts
    23
    Okay. Then i've done some research, and added "(i,fighter,damage2,damage3)" to the internal function, like that :

    function damages(i,fighter,damage2,damage3)
    {
    text.innerHTML += "<br>********** "+fighter[0][5]+ " : vie "+damage2[fighter[0][0]]+" -- fatigue "+damage3[fighter[0][0]];
    text.innerHTML += "<br>********** "+fighter[1][5]+ " : vie "+damage2[fighter[1][0]]+" -- fatigue "+damage3[fighter[1][0]];
    text.innerHTML += "<br>********** "+fighter[2][5]+ " : vie "+damage2[fighter[2][0]]+" -- fatigue "+damage3[fighter[2][0]];

    db.transaction(function (tx)
    {
    text.innerHTML += "<br>********** "+fighter[0][5]+ " : vie "+damage2[fighter[0][0]]+" -- fatigue "+damage3[fighter[0][0]];
    text.innerHTML += "<br>********** "+fighter[1][5]+ " : vie "+damage2[fighter[1][0]]+" -- fatigue "+damage3[fighter[1][0]];
    text.innerHTML += "<br>********** "+fighter[2][5]+ " : vie "+damage2[fighter[2][0]]+" -- fatigue "+damage3[fighter[2][0]];

    })(i,fighter,damage2,damage3);
    };

    The funny thing is : Now, that work, BUT apparently it's the bad thing to do (the browser say i call as a function something that is NOT a function. Yes, but why it's work now, then ?).
    --
    Friendly yours, D.Durand

    My pet project : http://ratsodie.blogspot.fr/, a civ game in javascript

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