question

steelfox001 avatar image
steelfox001 asked

is Cloud Script have problem with array?

I need find how many times "betNumber=4" in array kosti {random 3 digits from 1 to 6} but i always return = 0;

for debug i add kosti[kosti.length]=howManyTimesGetDice;

In Unity i get return

{"kosti":{"0":4,"1":1,"2":3,"undefined":0}}

undefined??? some problems with array.length?

handlers.helloWorld = function (args, context) {

var kosti ={};

var howManyTimesGetDice;

var betNumber=4;

for (var i=0;i<3;i++){

kosti[i] =Math.trunc(((Math.random() * 6) + 1)); }

howManyTimesGetDice = WinOrLoose(kosti,betNumber);

kosti[kosti.length]=howManyTimesGetDice;

return { kosti };

};

function WinOrLoose (mas,nomer){ /// count how many times nomer in array mas[]

var count=0;

for (var i=0;i<mas.length;i++){

if (nomer==kosti[i]){

count++;

}

}

return count;

}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
steelfox001 avatar image
steelfox001 answered

My Bad :) i try to find mistake many hours but when i posted here i find it! I declare kosti{} but should kosti[];

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.