This site requires JavaScript, please enable it in your browser!
Greenfoot back
angelol
angelol wrote ...

2016/8/18

Why Greenfoot.delay() is not working?

angelol angelol

2016/8/18

#
Well, I´m programming a memorama game, when a pair of cards are clicked, the comparison is automatically, and it can´t appreciate both images of cards because they are flipped (when are not equal) or dissapear (if both are equal). So I read the documentation and found Greenfoot.delay(). I tested it and worked the first time (yesterday) both cards stay freeze two seconds before being flipped, but I opened my project today and Greenfoot.delay() don´t worked, and i wondering why stops working?. Or, exists any other way to pause the game or freeze the cards before being flipped? this is how I´m using the method
1
2
3
4
5
6
7
8
9
10
11
12
//For example when both cards are equal
else if(duanvaloron==valoron && ( (unu=="a" && duan=="b") || (unu=="b" && duan=="a") ) ){
                Greenfoot.delay(150);
                malenigi(); //cards dissapear
 //resetting my counters
                duanvaloron=0;
                valoron=0;
                kontisto=0;
                unu="";
                duan="";
                posto++;
            }
danpost danpost

2016/8/18

#
It may be that your 'else' condition never evaluates to 'true'. This is because of the String comparisons which will always be false. The literal "a", for example, is equivalent to 'new String("a")' and that newly created String object is not the same object as what could possibly be referenced in 'unu' or 'duan'. Use the 'equals' method to compare the contents of the String objects instead of comparing the objects themselves:, similar to the following:
1
if ("a".equals(unu) && "b".equals(duan))
You need to login to post a reply.