We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys, I'm currently making a Memory game. I'm having a problem when I want to go to the next screen (I'm having the main screen, with mouse click I go to the next creen and so on....) everything is fine until I go to a specific screen, click how many cards I want to have and it directly jumps to the game. But there's another screen between them so the problem is that it skips a screen. Here's the code for the buttons screen which skips the next screen
if (isPointOnButton3==true)
{
cardCount=1;
state=4;
} else if (isPointOnButton4==true)
{
cardCount=2;
state=4;
} else if (isPointOnButton5==true)
{
cardCount=3;
state=4;
} else if (isPointOnButton6==true)
{
cardCount=4;
state=4;
}
}
}
And here's the skipped screen
void ZmenRub()
{
if (state==4) //zvolení počtu dvojic
{
fill(0);
background(204);
textFont(myFont2);
text("Zvolte rub karet", 335, 260);
volbaK = loadImage("00cards.png");
volbaK2 = loadImage("001cards.png");
volbaK3 = loadImage("002cards.png");
volbaK4 = loadImage("003cards.png");
volbaK5 = loadImage("004cards.png");
volbaK6 = loadImage("005cards.png");
image(volbaK, 190, 365, 100, 150);
image(volbaK2, 290, 365, 100, 150);
image(volbaK3, 390, 365, 100, 150);
image(volbaK4, 490, 365, 100, 150);
image(volbaK5, 590, 365, 100, 150);
image(volbaK6, 690, 365, 100, 150);
if (isPointOnButton7==true)
{
gcardback = loadImage("00cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
} else if (isPointOnButton8==true)
{
gcardback = loadImage("001cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
} else if (isPointOnButton9==true)
{
gcardback = loadImage("002cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
} else if (isPointOnButton10==true)
{
gcardback = loadImage("003cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
} else if (isPointOnButton11==true)
{
gcardback = loadImage("004cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
} else if (isPointOnButton12==true)
{
gcardback = loadImage("005cards.png");
InicializaceKaret();
file.stop();
file = new SoundFile(this, "menu.mp3");
file.play();
state=5;
}
}
}
I don't know why it skips the screen, the if condition is not wrong. Thanks in advance for your help and tips
Answers
could you post your entire code, please?
in short, it seems not wise to use
loadImage()
outside setup()also, it is suspicious that you use
isPointOnButton1
toisPointOnButton12
.... what are those? Selector of how many Cards you want to have in the game? The actual memory cards of the game with the images? Then you are doing it wrong.what is
InicializaceKaret()
doing?hint:
When ZmenRub() is called from draw() and the state is set to 5 (!) there and then state 5 gets drawn, you'll never see 4 since the screen is updated only at the end of draw() once and not throughout (and draw() runs 60 times per second).
Instead use a timer and set state to 5 later.
Hey thanks for the help. Is it possible to send you the whole package with the images and sounds, cause posting the whole code here is troublesome
i wrote a wrong sentence and corrected it now
correct is:
in short, it seems not wise to use
loadImage()
outside setup()So I just replaced the ifs with a switch
but the result is the same :(
Much better
As I said, the issue is that you set state to 5 in state 4 - thus you jump over state 4
I PM you
Solved