0

This is probably a noobish question that has been answered before, but I can't seem to find a solution online (Google is not being friendly). My question is, relating to Cocos2d, how would I pass 2 parameters using a self method. An Example of my Code

-(void)Random {
    [self AiCharacter:theEvilOne];
    [self AiCharacter:theEvilTwo];
}

-(void)AiCharacter(CCSprite*)EvilCharacter {
    //stuff
}

But I want to do something like the following

-(void)Random {
    num = 1
    [self AiCharacter:theEvilOne, Num];
    num = 2
    [self AiCharacter:theEvilTwo, Num];
}

 -(void)AiCharacter:(CCSprite*)EvilCharacter (NSInteger*)num { //This line is what seems to be incorrectly formatted/syntactically incorrect. 
    //stuff
}

To give you some more info into what I am doing is that I have an multi-dimensional array of values relating to my separate AI Characters and have the num value to differentiate the rows pertaining to each sprite.

Tibor Udvari
  • 2,932
  • 3
  • 23
  • 39
DragerX
  • 5
  • 3
  • Do you come from a C# background? Objective C naming convention is lower camel case for method names. – Tibor Udvari Apr 07 '14 at 09:11
  • Tibor Udvari thanks for the reply, I have only been programming (as in no experience in any language) for less than 2 weeks, I am a school student doing this for a major project. Thanks for the information I'll try use it in the future :) – DragerX Apr 07 '14 at 09:26

4 Answers4

2

The ":" defines a parameter in a method signature. This is how to write it :

-(void)AiCharacter:(CCSprite*)EvilCharacter num:(NSInteger*)num {
}

You can check this post for more information How do I pass multiple parameters in Objective-C?

Community
  • 1
  • 1
streem
  • 9,044
  • 5
  • 30
  • 41
  • Thanks for the reply :). This got me in the right direction but I was confused with how to actually call the method with self still. I would upvote but don't have enough rep – DragerX Apr 07 '14 at 09:31
0

Try this

-(void)Random {
   num = 1
   [self AiCharacter:theEvilOne: Num];
   num = 2
   [self AiCharacter:theEvilTwo: Num];
 }

-(void)AiCharacter:(CCSprite*)EvilCharacter :  (NSInteger*)num {
  //This line is what seems to be incorrectly formatted/syntactically incorrect.
  //stuff
 }
Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
0

See the method calling way carefully especially the colons and the parameters... or else you will encounter a crash

               -(void)Random {
                    num = 1
                   [self AiCharacter:theEvilOne number:num];
                   num = 2
                   [self AiCharacter:theEvilTwo number:num];
                }

          -(void)AiCharacter:(CCSprite*)EvilCharacter number:(NSInteger)num {

                }
SaffronState
  • 329
  • 1
  • 12
-1
 Try this

-(void)Random {

CGPoint point=ccp(1.0,2.0);
[self AiCharacter:theEvilOne: point];

}

-(void)AiCharacter:(CCSprite*)EvilCharacter :(CGPoint)point { 

float x=point.x;
float y=point.y;

}
KARTHIK RA
  • 469
  • 2
  • 8
  • Thanks for replying, I accepted the other guy as the best answer because his solution was using the same variables as mine and he answered quicker. Thanks anyway – DragerX Apr 07 '14 at 09:32