objective c - Is it possible to manually traverse nested if statements? -
binary trees confusing me inactivity, thought i'd try simpler (if messier) approach.
example...
if (a) { // wait button press before checking next 'if' if (aa) { } else if (ab) { } } else if (b) { else }
et cetera.
how force app wait button press before asking if 'aa' returns true? (and on , forth.)
switches seem cleaner alternative, if has answer method instead, i'd happy give go. it's same problem, though. can't figure out how progress step step rather @ once.
here's different approach, using state or control variable view, determine should next given button presses.
// pseudo-code based on example -(ibaction) buttonpress1 if (a) { self.setstate = statea; } else if (b) { else self.setstate = stateb; } -(ibaction) buttonpress2 if (self.state == statea) { if (a) { } else if (b) { } }
hope helps, if not, ask away in comments.
[edit]
ok, after explained da/me/me2 reference you're looking for.
what you're maybe going want do, store dialogue in plist, load nsdictionary. (read on nsdictionary)
each nsdictionary should this:
key = value
@"prompt" = @"hi name bob" @"mean" = nsdictionary object next convo choice mean @"nice" = nsdictionary object next convo choice nice
const bool nice = yes; const bool mean = !nice; nsdictionary *convo = //loaded initial starting point plist file - (ibaction) playerchosemean:(id)sender { [self sayconvo:convo withchoice:mean]; } - (ibaction) playerchosenice:(id)sender { [self sayconvo:convo withchoice:nice]; } - (void) sayconvo:(nsdictionary)convo withchoice:(bool)b { nslog(@"npc says: %@", [convo valueforkey:@"prompt"]); if(b) { convo = (nsdictionary*)[convo valueforkey:@"nice"]; } else { convo = (nsdictionary*)[convo valueforkey:@"mean"]; } if (convo == [nsnull null] || convo == nil) continue; //else continue }
here's example nsdictionary graph should started.
nsdictionary *intro = [nsdictionary dictionarywithcapacity:3]; nsdictionary *nice = [nsdictionary dictionarywithcapacity:3]; nsdictionary *nicenice = [nsdictionary dictionarywithcapacity:3]; nsdictionary *nicegoodbye = [nsdictionary dictionarywithcapacity:3]; nsdictionary *mean = [nsdictionary dictionarywithcapacity:3]; nsdictionary *meangoodbye = [nsdictionary dictionarywithcapacity:3]; [intro addvalue:@"hi there!" forkey:prompt]; [intro addvalue:nice forkey:@"nice"]; [intro addvalue:mean forkey:@"mean"]; [nice addvalue:@"that nice" forkey:prompt]; [nice addvalue:nicenice forkey:@"nice"]; [nice addvalue:mean forkey:@"mean"]; [nicenice addvalue:@"awww" forkey:prompt]; [nicenice addvalue:nicegoodbye forkey:@"nice"]; [nicenice addvalue:mean forkey:@"mean"]; [nicegoodbye addvalue:@"you super nice, here's bonus being nice" forkey:prompt]; [nicegoodbye addvalue:[nsnull null] forkey:@"nice"]; [nicegoodbye addvalue:[nsnull null] forkey:@"mean"]; [mean addvalue:@"that mean" forkey:prompt]; [mean addvalue:nice forkey:@"nice"]; [mean addvalue:meangoodbye forkey:@"mean"]; [meangoodbye addvalue:@"you're jerk! goodbye!" forkey:prompt]; [meangoodbye addvalue:[nsnull null] forkey:@"nice"]; [meangoodbye addvalue:[nsnull null] forkey:@"mean"];
take @ excellent example on over gamedeve.se
Comments
Post a Comment