I have a problem with my code, I'm trying to make my script spawn a different every time I click the mouse, but I get an error with my switch because I use a random to choose a different number each time. I get this error every time I try to run the script and I can't find the error.
Cannot switch on a value of type float. Only convertible int values, strings or enum variables are permitted
Some of the tags and names of variables is in danish as I'm danish.
int posX = 100;
int posX2 = 1820;
int dirX = 1;
int dirX2 = 1;
boolean drawforest = true;
int height = 1080;
int width = 1920;
//img = loadImage("BlueMorpho.png");
PImage img;
int storrelse = 15;
int storrelse2 = storrelse + 2;
float skift = random(0,2);
//setup()-metoden køres én gang, når sketchen startes
void drawBackground()
{
color e = color(135, 206, 235);
fill(e);
rect(960, 270, 1920, 560);
}
void setup()
{
size(1920, 1080);
rectMode(CENTER);
drawBackground();
color f = color(1, 142, 14);
fill(f);
rect(960, 820, 1920, 540);
//noLoop();
}
//draw()-metoden kører i et loop, indtil den stoppes
void draw()
{
switch(skift)
{
case 0:
img = loadImage("BlueMorpho.png");
break;
case 1:
img = loadImage("BlueMorpho2.png");
break;
default:
img = loadImage("BlueMorpho3.png");
break;
}
if (drawforest)
{
drawForest();
drawforest = false;
}
drawBackground();
drawCloud();
drawCloud2();
posX = posX+1;
posX2 = posX2-1;
if (posX>width-20 || posX<20)
{
dirX=-dirX;
}
if (posX2>width-20 || posX<20)
{
dirX2=-dirX2;
}
}
void drawForest()
{
for (int i = 0; i < 12; i++)
{
drawTree(random(55, 1865), 635 + 30*i);
}
}
void drawTree(float xx, float yy)
{
color c = color(139, 69, 19);
fill(c);
//noStroke();
rect(xx, yy+30, 50, 100);
color d = color(000, random(25, 100), 000);
fill(d);
//noStroke();
ellipse(xx, yy-30, 125, 100);
color g = color(100, 0, 0);
fill(g);
ellipse(random(xx-50, xx+50), random(yy-50, yy+18), 10, 10);
}
void drawCloud()
{
color h = color(255, 255, 255);
fill(h);
ellipse(posX, 150, 100, 50);
//posX += random(50,1920);
noStroke();
}
void drawCloud2()
{
color h = color(0, 0, 0);
fill(h);
ellipse(posX2, 200, 100, 50);
//posX += random(50,1920);
}
void tegnSommerfugl(float xx, float yy)
{
image(img, xx, yy, width/storrelse2, height/storrelse);
}
void mouseClicked()
{
tegnSommerfugl(mouseX,mouseY);
}