Pergunta

I'm trying to build something that will only fire a command once per keyboard input (as opposed to every frame like QC does natively). In order to do so, I'm trying to listen in on the keyboard inputs (via Freeboard) and compare the current input versus a previous version.

What seems to be happening is the previous version is getting wiped every time the patch executes, so my conditional to compare strings is failing every time. Here's some code to make it a bit clearer:

- (BOOL)execute:(id <QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary *)arguments
{   
  self.outputPrevious=previousCharacter;
  if ([self.inputCharacter caseInsensitiveCompare:previousCharacter]){  
      self.outputText=@"SAME";
  }
  else {
      self.outputText=@"CHANGE";
  }
  previousCharacter = [NSString stringWithString:self.inputCharacter];
  [previousCharacter retain];
  return YES;
}

where self.outputText is the text that tells me the result of the if, self.outputPrevious is telling me what the previous character input was, and self.inputCharacter is the current keyboard input.

previousCharacter is defined in the header and instantiated in -init, so it shouldn't be being reset every time.

I've tried pretty much everything with this, so if you have any ideas or insights, that would be awesome. Thanks!

Foi útil?

Solução

Figured it out eventually. Full solution can be found here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top