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

2012/4/21

...what am I doing wrong? :(

1
2
danpost danpost

2012/4/22

#
Right click on an Option object and click on the 'Show static fields' button and check the order of the options. If they are not in the order they were read in, then maybe sort() had something to do with it.
Omniscience Omniscience

2012/4/22

#
Thanks! Used the constructor in the Question class, and it matches up with the options! Last of all, how do get the options to be placed in the correct positions? Thanks danpost- I'm indebted to you once again. i.e. Option One (169, 251); Option Two (342,251); Option Three (169, 320); Option Four (342, 320); EDIT: Whoops, didn't realise you would have replied to me so quickly! The sort algorithm merely swops the rows of the array. This shouldn't affect the Options at all. Hmmm... I'm onto it, if you don't hear from me, it means I fixed it!
Omniscience Omniscience

2012/4/22

#
Okay, so now everything is working just fine! There is a small detail that I'd like to be able to store: the number questions the player has correctly answered. I've made a vain attempt, but it doesn't do a thing. I think maybe the whole duplicate arrays of data thing is going on again or something. Here's what I've tried:
int correctlyAnswered = 0; 
String userAnswer;
String submittedA = Greenfoot.isKeyDown("a");
String submittedB = Greenfoot.isKeyDown("b");
String submittedC = Greenfoot.isKeyDown("c");
String submittedD = Greenfoot.isKeyDown("d");

if ((submittedA || submittedB || submittedC || submittedD) = true) {
    if (submittedA = true) {
    userAnswer = "a"; 
        if (userAnswer == data[instance][5] {
        correctlyAnswered++;
    }
 if (submittedB = true) {
    userAnswer = "b"; 
        if (userAnswer == data[instance][5] {
        correctlyAnswered++;
    }
 if (submittedC = true) {
    userAnswer = "c"; 
        if (userAnswer == data[instance][5] {
        correctlyAnswered++;
    }
 if (submittedD = true) {
    userAnswer = "d"; 
        if (userAnswer == data[instance][5] {
        correctlyAnswered++;
    }
danpost danpost

2012/4/23

#
One thing is: you are storing the possible submitted responses in String variables, and then trying to ask if they hold a value of 'true'. Another thing: you are using 'Greenfoot.isKeyDown(String key)' to catch the response; using 'Greenfoot.getKey()' would be more appropriate in this case. One other thing (and I hope and pray that this is not what it looks like): the first line is not in a method, is it? (it should be a world variable -- and possibly static). Anyways, for getting the keystrokes:
String key = Greenfoot.getKey();
if (key == null) return;
if (key.equals(data[instance][5])) correctlyAnswered++;
You need to login to post a reply.
1
2