# Array isn't loading any values

**URL:** <https://discourse.processing.org/t/array-isnt-loading-any-values/15368>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 10, 2019, 2:33am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368 "2019-11-10T02:33:41Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 2:33am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/1 "2019-11-10T02:33:41Z")

</div>

```auto
**//(Dice game, roll two dice 36 times and store each value, then after you determine how many times 12 showed in that array, but the array 1-36 is all filled with 0's, and it prints that shows 12 0 times. New to coding)//**
float sum = 12;
int i=1;
int sumNumber = 0;
float[] diceRolls = new float[36];
int tValue = (1/36);
float dice1 = random(1,6);
float dice2 = random(1,6);
int eValue;
void setup(){
printArray(diceRolls);
print(sumNumber);
}
void roll()
{
  for (float diceRolls=0;diceRolls<=36;diceRolls++) {
    diceRolls = dice1 + dice2;
  }
}

void sumCounter()
{
  for (float diceRolls=0;diceRolls<=36;diceRolls++) {
  if (diceRolls == 12)
  {
    sumNumber = sumNumber + 1;
  }
  eValue = sumNumber/36;
  }
}
void winLoss() {
  if (eValue > tValue)
    {
    print ("You win!");
    }
    else
    {
    print ("You Lose!");
    }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 2:46am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/2 "2019-11-10T02:46:38Z")

</div>

hi @bs.17

-a- is that the spec of a homework assignment?

-b- please format your code  
use the

```auto
</> menu button 

```

and paste your code inside.

* * *

also i not understand your program flow

- global variables
- void setup(){}
- void draw(){}

* * *

for me it looks like you print from setup a declared but empty array??

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 2:51am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/3 "2019-11-10T02:51:54Z")

</div>

thanks for getting back ive been struggling @kll . yes for my ap computer science principles class  
–ok so you roll two dice and store them in a array(i named it diceRolls) its length shouldnt be longer then 36, void roll() is supposed to randomize dice 1 and dice 2 then put them in the array (length 36), then we were given a number mine was 12, program is supposed to go over that whole array and increase the variable sumNumber by 1 everytime 12 appears on that list

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 10, 2019, 2:55am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/4 "2019-11-10T02:55:03Z")

</div>

[https://processing.org/tutorials/arrays/](https://processing.org/tutorials/arrays/)  
[https://processing.org/reference/Array.html](https://processing.org/reference/Array.html)

🙂

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 3:05am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/5 "2019-11-10T03:05:17Z")

</div>

sorry, coding does not work that way.

you have 3 functions

```auto
void roll(){}
void sumCounter(){}
void winLoss(){}

```

and i can not see where they are called.  
and that means you did not test them ( or not even write them? )

what is called by processing is the

```auto
void setup() {}

```

and that should run  
( if you would not have that bad documentation line )

and prints a empty array.

* * *

basic of a dice is a random number ( 1 …6 )  
so you study  
[https://processing.org/reference/random\_.html](https://processing.org/reference/random_.html)  
and make it a function for a single dice roll  
with a print on the result  
and call that from the setup(){}  
function.

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 3:08am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/6 "2019-11-10T03:08:56Z")

</div>

sorry again beginner so Im still trying to figure out everything. what do you mean by I didn’t call them? could you please be more specific and point out @kll

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 3:17am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/7 "2019-11-10T03:17:57Z")

</div>

```auto
float dice1 = random(1,6); 
float dice2 = random(1,6);

```

this 2 variables ( from the variable declaration )  
would give you 2 fix float numbers from 1 … 5  
that you not want.

```auto
int dice1,dice2;

void setup() {
 dice1 = rollDice();
 dice2 = rollDice();
 println(dice1,dice2);
}

int rollDice() {
  return (int)random(1,7);
}

```

start from this.

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 3:30am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/8 "2019-11-10T03:30:50Z")

</div>

okay so now it prints the random values of dice 1 and dice 2, but my main question was how am I supposed to store them in the list? i tried doing diceRolls = dice1 + dice2 and shouldnt that store them? thing is though its not @kll

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 3:33am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/9 "2019-11-10T03:33:14Z")

</div>

this is due tmrw night and kinda freaking out

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 3:35am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/10 "2019-11-10T03:35:58Z")

</div>

did you read about the array? @glv linked you?  
now you store the dice1 and dice2 values to array.  
you have the roll function where you add the two numbers,  
but store to array not work this way,  
nevertheless you would not even find out until you  
call the roll() after the println of our little randomtestprogram

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 3:45am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/11 "2019-11-10T03:45:42Z")

</div>

I read about it but doesnt help much, it assigns variables to each place in the array. i cant determine my variables because they r random. i tried playing around with what the article said yet still no progress its still only doing println(dice1,dice2); and thats it every other thing is empty, this is my first time with arrays so the struggle is real ive been on this since 5est @kll

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 3:53am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/12 "2019-11-10T03:53:16Z")

</div>

but that is what you need to do,  
make int array ( not float - - unless you have a dice what show 3.54 )  
and store the sum of 2 dice rolls into each ?cell?

show me the actual code where you combine a array (? for loop over index?)  
with my above

```auto
rollDice()

```

function.

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 3:56am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/13 "2019-11-10T03:56:47Z")

</div>

```auto
float sum = 12;
int i=1;
int sumNumber = 0;
int[] diceRolls = new int[36];
int tValue = (1/36);
int dice1,dice2;
int eValue;
void setup(){
dice1 = rollDice();
dice2 = rollDice();
println(dice1,dice2);
printArray(diceRolls);
print(sumNumber);
}
int rollDice() {
  return (int)random(1,6);
}
void roll()
{
  for (int diceRolls=0;diceRolls<=36;diceRolls++) {
    diceRolls = dice1 + dice2;
  }
}

void sumCounter()
{
  for (int diceRolls=0;diceRolls<=36;diceRolls++) {
  if (diceRolls == 12)
  {
    sumNumber = sumNumber + 1;
  }
  eValue = sumNumber/36;
  }
}
//@kll 

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 4:01am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/14 "2019-11-10T04:01:00Z")

</div>

-a- you not copy my 5 line code?  
you not read random(1,6) means 6 is EXCLUDED

-b- you not call the roll function?  
so you not even see that it not works???

```auto
int dice1, dice2;
int[] diceRolls = new int[36];

void setup() {
  roll();
}

int rollDice() {
  return (int)random(1, 7);
}

void roll() {
  for (int i =0; i < 36; i++) {
    dice1 = rollDice();
    dice2 = rollDice();
    int sum = dice1 + dice2;
    diceRolls[i] = sum;
    println(i, dice1, dice2,"sum ", sum);
  }
}

```

---

<div class="post-metadata">

**Author:** ![bs.17](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bs.17](https://discourse.processing.org/u/bs.17)\
**Post date:** [November 10, 2019, 4:07am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/15 "2019-11-10T04:07:14Z")

</div>

@kll thanks man, I see where I made a mistake I will study this! thanks for having patience really appreciated 🥰🥰

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 10, 2019, 4:18am UTC](https://discourse.processing.org/t/array-isnt-loading-any-values/15368/16 "2019-11-10T04:18:45Z")

</div>

not related:

> **just for fun**
>
> ```auto
> // v 0.1 use mousePressed and mouseReleased
> // v 0.2 give speed to slow down rotation
> // v 0.3 and rotate 5 times ( not use mouseReleased )
> String rev = " v0.3";
> int x=100, y=x, w=50, h=w, grid=3, many=grid*grid, diam=30;
> int dice = 0;
> int[][] points = {
> {0, 0, 0, 0, 0, 0, 0, 0, 0}, // none
> {0, 0, 0, 0, 1, 0, 0, 0, 0}, //1
> {0, 0, 1, 0, 0, 0, 1, 0, 0}, //2
> {0, 0, 1, 0, 1, 0, 1, 0, 0}, //3
> {1, 0, 1, 0, 0, 0, 1, 0, 1}, //4
> {1, 0, 1, 0, 1, 0, 1, 0, 1}, //5
> {1, 0, 1, 1, 0, 1, 1, 0, 1}, //6
> {1, 1, 1, 1, 1, 1, 1, 1, 1} //all used as dice = 7 rolling
> };
> PShape squircle;
> float speed, slower = 0.0001, ang = 0; // animation: dice rolling
> int roll = 5; // roll limit
> 
> void setup() {
> size(300, 300);
> surface.setTitle("myDice"+rev);
> println("mouse click makes the magic");
> noStroke();                                      
> my_squircle(1, 90, 90); // generate the dice shape
> }
> 
> void draw() {
> background(200, 200, 0);
> draw_dice();
> }
> 
> void mousePressed() {
> dice = 7;
> ang = 0;
> speed = 0.10;
> }
> 
> // __________________________________________________________ DICE
> void draw_dice() {
> if ( dice == 7 ) { // dice rolling
> translate(width/2, height/2);
> speed -= slower; // v0.2 slow down rotation
> if ( speed < 0 ) speed = 0; // avoid rolling back
> ang += speed;
> rotate(ang);
> if ( speed == 0 || ang > roll * TWO_PI ) { // v 0.3 roll limit 
> dice = int(random(1, 7));
> println("new dice: "+dice);
> }
> translate(-width/2, -height/2);
> }
> shape(squircle, width/2, height/2); // shape first
> for (int i = 0; i < many; i++) {
> fill(180, 180, 180); // same dice squircle border, 190 would be invisible
> if ( points[dice][i] == 1 ) fill(200, 0, 0);
> ellipse(x+(i%grid)*w, y+(floor(i/grid))*h, diam, diam);
> }
> }
> 
> // __________________________________________________________ SQUIRCLE
> void my_squircle(float r, float wx, float wy) {
> float x1, y1;
> squircle = createShape();
> squircle.beginShape();
> squircle.stroke(180, 180, 180);
> squircle.strokeWeight(5);
> squircle.fill(190, 190, 190);
> for (float t = 0; t < TWO_PI; t += TWO_PI/160) { // 160 vertex points is too much
> x1 = pow(abs(cos(t)), 0.5) * r*wx * sign(cos(t));
> y1 = pow(abs(sin(t)), 0.5) * r*wy * sign(sin(t));
> squircle.vertex(x1, y1);
> }
> squircle.endShape(CLOSE);
> }
> 
> float sign(float input) {
> if (input < 0) return -1.0;
> if (input > 0) return 1.0;
> return 0.0;
> }
> 
> ```

and processing should be FUN
