Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Tutorial] Quiz Game

1234568»

Replies

  • alessignalessign Posts: 48Registered Users @
    It's not exactly clear what you need to achieve. Show some example or code...
  • sxcheemsxcheem Bangalore, IndiaPosts: 4New Users Noob
    One quick qn - is the sample code works for both ipad and iphone or only iphone. I am able to run usinm ipad simulator. But can't test on real device, as I don't have one. So asking. Sorry for the dumb qn. Thanks.
  • prem19902prem19902 Posts: 11New Users *
    Hello there, I am trying load quiz from plist,
    everything is working fine but at the end of quiz the app is crash instead of showing Score.
    i don't have any idea of edit -(void)askQuestion please help me............

    -(void)askQuestion{
    // Unhide all the answer buttons.
    [answerOne setHidden:NO];
    [answerTwo setHidden:NO];
    [answerThree setHidden:NO];
    [answerFour setHidden:NO];
    [quitGame setHidden:NO];


    // Set the game to a "live" question (for timer purposes)
    questionLive = YES;

    // Set the time for the timer
    time = 60.0;

    int index = arc4random()%[indexes count];

    [shuffle addObject:[indexes objectAtIndex:index]];
    NSLog(@shuffle: %@", shuffle);
    [indexes removeObjectAtIndex:index];
    NSLog(@indexes: %@ ", indexes);


    for (int i=0; i<[shuffle count]; i++){

    questionNumber = [[shuffle objectAtIndex:i] intValue] + 1;
    NSLog(@questionNumber: %li , (long)questionNumber);


    }

    if (self.krokquizIndex== 999){
    self.krokquizIndex=0;
    } else if ((self.loadplist.KrokquizCount)>self.krokquizIndex) {
    self.krokquizIndex++;
    } else {
    self.krokquizIndex=0;
    }

    if (self.loadplist.KrokquizCount>=self.krokquizIndex-1) {
    [self.loadplist askQuestion:self.krokquizIndex];
    self.Question.text = self.loadplist.QuestionTitle;



    [self.answerOne setTitle:self.loadplist.Ans1 forState:UIControlStateNormal];
    [self.answerTwo setTitle:self.loadplist.Ans2 forState:UIControlStateNormal];
    [self.answerThree setTitle:self.loadplist.Ans3 forState:UIControlStateNormal];
    [self.answerFour setTitle:self.loadplist.Ans4 forState:UIControlStateNormal];


    //reset fields for next quetion //tako - moved initialization only when there's next question
    self.answerOne.backgroundColor = [UIColor whiteColor];
    self.answerTwo.backgroundColor = [UIColor whiteColor];
    self.answerThree.backgroundColor = [UIColor whiteColor];
    self.answerFour.backgroundColor = [UIColor whiteColor];

    //reset radiobutton for next quetion
    [self.radioButton1 setImage:[UIImage imageNamed:@radioButtonDisabled.png]forState:UIControlStateSelected];
    [self.radioButton2 setImage:[UIImage imageNamed:@radioButtonDisabled.png]forState:UIControlStateSelected];
    [self.radioButton3 setImage:[UIImage imageNamed:@radioButtonDisabled.png]forState:UIControlStateSelected];
    [self.radioButton4 setImage:[UIImage imageNamed:@radioButtonDisabled.png]forState:UIControlStateSelected];

    //show radio button in quiz
    [radioButton1 setHidden:NO];
    [radioButton2 setHidden:NO];
    [radioButton3 setHidden:NO];
    [radioButton4 setHidden:NO];

    // Start the timer for the countdown
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];

    if(myScore <= 0 && myScore >=0){
    Segment.hidden = YES;
    }
    }else {
    self.krokquizIndex=0;
    [self checkScore];
    }
    }
    -(void)loadQuiz{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Krokthree];
    }
  • alessignalessign Posts: 48Registered Users @
    Prem, I have a feeling you didn't read the forum from beginning. It would actually help you understand the developing of this game. Not sure what could be the cause. What is the console saying?

    If you edit the text files, you need to specify new number of lines in viewDidLoad method:
    int length = 90 or implement automatic counting reference for it.
    Mind you, that the tex file can not contain any empty line, otherwise the code will not work properly. Read the forum to understand the process, you'll learn a lot from this topic...
  • prem19902prem19902 Posts: 11New Users *
    No! i read every line of this forum, Unfortunately i forgot to change in viewDidLoad method int length = 90. But in this case, i am loading question from plist
  • alessignalessign Posts: 48Registered Users @
    So what is the console error saying?
  • alessignalessign Posts: 48Registered Users @
    Can you copy the whole text from NSLogs - bottom right window please?
  • prem19902prem19902 Posts: 11New Users *
    NSLogs

    2014-11-16 12:26:14.293 Demo[1500:27687] 6
    2014-11-16 12:26:16.485 Demo[1500:27687] shuffle: (
    2
    )
    2014-11-16 12:26:16.486 Demo[1500:27687] indexes: (
    0,
    1,
    3,
    4,
    5
    )
    2014-11-16 12:26:16.486 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:17.489 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:18.488 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:19.489 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:21.078 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:22.078 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:23.078 Demo[1500:27687] shuffle: (
    2,
    1
    )
    2014-11-16 12:26:23.078 Demo[1500:27687] indexes: (
    0,
    3,
    4,
    5
    )
    2014-11-16 12:26:23.078 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:23.079 Demo[1500:27687] questionNumber: 2
    2014-11-16 12:26:23.080 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:24.081 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:25.369 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:26.368 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:27.369 Demo[1500:27687] shuffle: (
    2,
    1,
    0
    )
    2014-11-16 12:26:27.370 Demo[1500:27687] indexes: (
    3,
    4,
    5
    )
    2014-11-16 12:26:27.370 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:27.371 Demo[1500:27687] questionNumber: 2
    2014-11-16 12:26:27.371 Demo[1500:27687] questionNumber: 1
    2014-11-16 12:26:27.373 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:28.374 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:30.146 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:31.146 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:32.146 Demo[1500:27687] shuffle: (
    2,
    1,
    0,
    3
    )
    2014-11-16 12:26:32.147 Demo[1500:27687] indexes: (
    4,
    5
    )
    2014-11-16 12:26:32.147 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:32.147 Demo[1500:27687] questionNumber: 2
    2014-11-16 12:26:32.148 Demo[1500:27687] questionNumber: 1
    2014-11-16 12:26:32.148 Demo[1500:27687] questionNumber: 4
    2014-11-16 12:26:32.150 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:33.151 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:34.824 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:35.824 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:36.824 Demo[1500:27687] shuffle: (
    2,
    1,
    0,
    3,
    4
    )
    2014-11-16 12:26:36.824 Demo[1500:27687] indexes: (
    5
    )
    2014-11-16 12:26:36.824 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:36.825 Demo[1500:27687] questionNumber: 2
    2014-11-16 12:26:36.825 Demo[1500:27687] questionNumber: 1
    2014-11-16 12:26:36.826 Demo[1500:27687] questionNumber: 4
    2014-11-16 12:26:36.826 Demo[1500:27687] questionNumber: 5
    2014-11-16 12:26:36.827 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:37.828 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:39.650 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:40.650 Demo[1500:27687] Correct Answer: 0
    2014-11-16 12:26:41.651 Demo[1500:27687] shuffle: (
    2,
    1,
    0,
    3,
    4,
    5
    )
    2014-11-16 12:26:41.651 Demo[1500:27687] indexes: (
    )
    2014-11-16 12:26:41.651 Demo[1500:27687] questionNumber: 3
    2014-11-16 12:26:41.652 Demo[1500:27687] questionNumber: 2
    2014-11-16 12:26:41.652 Demo[1500:27687] questionNumber: 1
    2014-11-16 12:26:41.652 Demo[1500:27687] questionNumber: 4
    2014-11-16 12:26:41.653 Demo[1500:27687] questionNumber: 5
    2014-11-16 12:26:41.653 Demo[1500:27687] questionNumber: 6
    2014-11-16 12:26:41.696 Demo[1500:27687] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (6) beyond bounds (6)'
    *** First throw call stack:
    (
    0 CoreFoundation 0x000000010c5f6f35 __exceptionPreprocess + 165
    1 libobjc.A.dylib 0x000000010c28fbb7 objc_exception_throw + 45
    2 CoreFoundation 0x000000010c5f6e6d +[NSException raise:format:] + 205
    3 CoreFoundation 0x000000010c521163 -[__NSCFArray objectAtIndex:] + 163
    4 Demo 0x000000010bd5b47c -[loadplist askQuestion:] + 92
    5 Demo 0x000000010bd56c08 -[play askQuestion] + 904
    6 Demo 0x000000010bd5787a -[play countDown] + 682
    7 Foundation 0x000000010be492b4 __NSFireTimer + 83
    8 CoreFoundation 0x000000010c55ef64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    9 CoreFoundation 0x000000010c55eb25 __CFRunLoopDoTimer + 1045
    10 CoreFoundation 0x000000010c521e5d __CFRunLoopRun + 1901
    11 CoreFoundation 0x000000010c521486 CFRunLoopRunSpecific + 470
    12 GraphicsServices 0x000000010fbc59f0 GSEventRunModal + 161
    13 UIKit 0x000000010c9e3420 UIApplicationMain + 1282
    14 Demo 0x000000010bd5be23 main + 115
    15 libdyld.dylib 0x000000010eb86145 start + 1
    16 ??? 0x0000000000000001 0x0 + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb)
  • alessignalessign Posts: 48Registered Users @
    Hm, that looks like wrong array count or integer for loop function in selecting new q. What is indicating the very first number 6 (no description)? The console is saying 6 beyond bounds. 0, 1,2,3,4,5 are six numbers already, so it looks to me, when you loop one more time (new question), it's actually for the 7th time...but it could also be text missing on that line...try to run the code with number 5 instead of six?
  • prem19902prem19902 Posts: 11New Users *
    edited November 2014
    Thank you so much alessign. Now, working.....
    Post edited by prem19902 on
  • alessignalessign Posts: 48Registered Users @
    Splendid, glad could help...
  • prem19902prem19902 Posts: 11New Users *
    edited November 2014
    Hello alessign Good evening,
    Today i am getting another problem. I am trying to load specific category question when user click specific category button (e.g Biology button click = Biology question load).
    It is loading only Biology question ....

    -(void)loadQuiz{
    CategoryLoaded = [[NSUserDefaults standardUserDefaults] integerForKey:@CategorySaved];

    switch (CategoryLoaded) {
    case 1:
    CategorySelected.text = [NSString stringWithFormat:@Biology];
    [self Biology];
    break;
    case 2:
    CategorySelected.text = [NSString stringWithFormat:@Histology];
    [self histology];
    break;
    case 3:
    CategorySelected.text = [NSString stringWithFormat:@Microbiology];
    [self Microbiology];
    break;
    case 4:
    CategorySelected.text = [NSString stringWithFormat:@Biochemistry];
    [self Biochemistry];
    break;
    case 5:
    CategorySelected.text = [NSString stringWithFormat:@Normalphysiology];
    [self NormalPhysiology];
    break;
    case 6:
    CategorySelected.text = [NSString stringWithFormat:@Pathophysiology];
    [self PathoPhysiology];
    break;

    case 7:
    CategorySelected.text = [NSString stringWithFormat:@Normalanatomy];
    [self NormalAnatomy];
    break;

    case 8:
    CategorySelected.text = [NSString stringWithFormat:@Pathoanatomy];
    [self PathoAnatomy];
    break;

    case 9:
    CategorySelected.text = [NSString stringWithFormat:@Pharmacology];
    [self Pharmacology];
    break;

    default:
    break;
    }
    }

    -(void)Biology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Biology];
    }
    -(void) histology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Histology];

    }
    -(void) Microbiology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Microbiology];
    }
    -(void) Biochemistry{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Biochemistry];
    }
    -(void) NormalPhysiology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Normalphysiology];
    }
    -(void) PathoPhysiology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Pathophysiology];
    }
    -(void) NormalAnatomy{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Normalanatomy];
    }
    -(void) PathoAnatomy{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Pathoanatomy];
    }
    -(void) Pharmacology{
    self.loadplist = [[loadplist alloc] initWithQuiz:@Pharmacology];
    }
  • alessignalessign Posts: 48Registered Users @
    Hm, not sure. Try different approach - check which button was pressed:

    tag all buttons

    biologyBtn.tag = 1;
    histologyBtn.tag = 2;
    etc.

    Implement in loadQuiz:

    NSLog(@Loading Quiz...);

    if ([sender isMemberOfClass:[UIButton class]])
    {
    UIButton *btn = (UIButton *)sender;

    if([btn.tag ==1])
    {
    CategorySelected.text = [NSString stringWithFormat:@Biology];
    [self Biology];
    NSLog(@biology button pressed...);
    }
    else if(btn.tag ==2)
    {
    CategorySelected.text = [NSString stringWithFormat:@Histology];
    [self histology];
    NSLog(@histology button pressed...);
    }
    }
    //
    -(void)Biology{
    NSLog(@biology selected...);
    self.loadplist = [[loadplist alloc] initWithQuiz:@Biology];
    }
    -(void) histology{
    NSLog(@histology selected...);
    self.loadplist = [[loadplist alloc] initWithQuiz:@Histology];
    }

    Theres's no NSLogs in your code, so we can't see how far your script is going...and what action it reaches..then you will perhaps see where it got stuck. You're delete them later...
  • alessignalessign Posts: 48Registered Users @
    I am trying to understand where do you call the button actions from? Is it the UITableview? If so, you possibly need to create an array with names of the plists in exact order and when selected row at index call action that will load quiz from array at the same index in case each row means different quiz:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.loadplist = [[loadplist alloc] initWithQuiz:[yourArray objectAtIndex:indexPath.row];
    NSLog(@Row: %i Quiz: @%";, indexPath.row, [yourArray objectAtIndex:indexPath.row]);
    }
  • emilyhemingemilyheming USAPosts: 7New Users Noob
    Ohh! That's so good of you to share that code. It will be much useful to me may be it resolve my error.
  • dev666999dev666999 Posts: 3,620New Users @ @ @ @ @
    Ohh! That's so good of you to share that code. It will be much useful to me may be it resolve my error.

    Hi @emilyheming... you sound like a spammer.

    You have a spammer name.

    You speak broken English, but your name is Emily Heming?!?


  • prem19902prem19902 Posts: 11New Users *
    Good evening everybody,
    How to use sqlite FMDB framework????
  • shyposhashyposha kharkovPosts: 1New Users Noob
    How to use sqlite FMDB framework????

    Any experienced iOS developer immediately reproach me for using SQLite directly (rather than directly, but through FmDb, but it's like almost directly). He tells you that you need to use CoreData, because it makes all sorts of nishtyakov automatically, such as Undo and Redo. And in it you can draw beautiful shemki, which then nice to show the customer. And in Android, for example, there OrmLite.
  • uvidownloaderuvidownloader Posts: 216Registered Users @ @
    tried downloading the app to try. The link takes me to icloud. I log in. Where do I go for the file ? Email me as well timbojill@gmail.com. Dont come here that happen.
  • uvidownloaderuvidownloader Posts: 216Registered Users @ @
    Hate to be a bother. I tried downloading the app from the second post. When I follow the link it thanks me to icloud.com. Is that suppose to happen. I login as required. Where do I go from there to get the files ?
  • KrishnaozaKrishnaoza AhmedabadPosts: 1New Users Noob
    edited May 2016
    I am not able to download source code. pl help me. send me source code of this.. pl email me krishnaoza.6@gmail.com
    Post edited by Krishnaoza on
  • UIUsUIUs Posts: 169Moderators Admin
    Locking this thread. The OP is apparently no longer supporting it.
1234568»
This discussion has been closed.