Search Results

Search found 34 results on 2 pages for 'arc4random'.

Page 1/2 | 1 2  | Next Page >

  • Iphone SDK, arc4random CGPointmake?

    - by Harry
    I have tried using integers to store the number like so: playPin = 35 + arc4random() % 118; playY = -50 - arc4random() %100; if (CGRectIntersectsRect(pin.frame, refreshpin.frame)){ pin.center = CGPointMake(playPin, playY); pinend.center = CGPointMake(pin.center.x, pin.center.y+58); } Then using them, when needed, but... its random the first time, then it just keeps repeating itself. then i tried this: if (CGRectIntersectsRect(pin.frame, refreshpin.frame)){ pin.center = CGPointMake(35 + arc4random() % 118, -50 - arc4random() %100); pinend.center = CGPointMake(pin.center.x, pin.center.y+58); } And this also doesn't work, you cant even see the items i want to display! Any ideas? Thanks. Harry.

    Read the article

  • How to get arc4Sin() output into label/NSString

    - by Moshe
    I'm trying to take the output of arc4sin and put it into a label. (EDIT: You can ignore this and just post sample code, if this is too irrelevant.) I've tried: // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; NSString *number = [[NSString alloc] stringWithFormat: @"%@", arc4random() % 9]; label.text = number; } I've created an IBOutlet for "label" and connected it. What's wrong here?

    Read the article

  • Crash when using Cocos2d

    - by ipodfreak0313
    Sorry about the poor question title, it's just that this seems to big for a title. So here's the dirt: I am making a game (obviously) and I want the enemies to shoot (not necessarily at the player). I want the shoot method to be in the Enemies file, so as not to clutter up my HelloWorldLayer.m file even more. Here's what I'm using right now: HelloWorldLayer.m -(void)addEnemy:(BigAndStrongEnemy *)enemy { enemy = nil; if((arc4random() % 4) == 3) { enemy = [BigAndStrongEnemy enemy]; } else { enemy = [SmallAndFastEnemy enemy]; } if(buffDude.position.y > character.position.y || buffDude.position.y < (character.position.y + 10)) { } int rand = arc4random() % 320; if((arc4random() % 2 == 1)) { [enemy setPosition:ccp(0,rand)]; }else{ [enemy setPosition:ccp(480,rand)]; } [self animateEnemy:enemy]; [self addChild:enemy]; } -(void)animateEnemy:(BigAndStrongEnemy *)enemy2 { float randX = arc4random() % 480; float randY = arc4random() % 320; int rand = arc4random() % 320; CGPoint moveToPoint = CGPointMake(randX, (randY - rand)); [enemies addObject:enemy2]; action = [CCSequence actions: [CCMoveBy actionWithDuration:1 position:ccpMult(ccpNormalize(ccpSub(moveToPoint, enemy2.position)), 75)], [CCMoveBy actionWithDuration:3 position:ccp(buffDude.position.x,buffDude.position.y)], nil]; CCCallFuncO *a = [CCCallFuncO actionWithTarget:self selector:(@selector(shoot:)) object:enemy2]; CCSequence *s = [CCSequence actions:action,a, nil]; CCRepeatForever *repeat = [CCRepeatForever actionWithAction:s]; [enemy2 runAction:repeat]; } And here's the Shoot info from the Enemies class: Enemies.m: -(void)shoot:(id)sender { self = (BigAndStrongEnemy *)sender; [self shoot]; } -(void)spriteMoveFinished:(id)sender { CCSprite *b = (CCSprite *)sender; [self removeChild:b cleanup:YES]; } -(void)shoot { self = [CCSprite spriteWithFile:@"bigAndStrongEnemy.gif"]; CCSprite *b = [CCSprite spriteWithFile:@"bullet.gif"]; b.position = ccp(self.position.x,self.position.y); b.tag = 2; [self addChild:b]; [bullets addObject:b]; CGSize winSize = [[CCDirector sharedDirector] winSize]; CGPoint point = CGPointMake((winSize.width - (winSize.width - self.position.x)),0); [b runAction:[CCSequence actions: [CCMoveBy actionWithDuration:0.5 position:point], [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]]; } Every time the 3 seconds goes by, the app crashes, and goes to the breakpoint in the CCCallFuncO file. I haven't touched it, is the thing. I am completely confused. Any help is greatly appreciated.

    Read the article

  • Falling CCSprites

    - by Coder404
    Im trying to make ccsprites fall from the top of the screen. Im planning to use a touch delegate to determine when they fall. How could I make CCSprites fall from the screen in a way like this: -(void)addTarget { Monster *target = nil; if ((arc4random() % 2) == 0) { target = [WeakAndFastMonster monster]; } else { target = [StrongAndSlowMonster monster]; } // Determine where to spawn the target along the Y axis CGSize winSize = [[CCDirector sharedDirector] winSize]; int minY = target.contentSize.height/2; int maxY = winSize.height - target.contentSize.height/2; int rangeY = maxY - minY; int actualY = (arc4random() % rangeY) + minY; // Create the target slightly off-screen along the right edge, // and along a random position along the Y axis as calculated above target.position = ccp(winSize.width + (target.contentSize.width/2), actualY); [self addChild:target z:1]; // Determine speed of the target int minDuration = target.minMoveDuration; //2.0; int maxDuration = target.maxMoveDuration; //4.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2, actualY)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; // Add to targets array target.tag = 1; [_targets addObject:target]; } This code makes CCSprites move from the right side of the screen to the left. How could I change this to make the CCSprites to move from the top of the screen to the bottom?

    Read the article

  • How can I efficiently select several unique random numbers from 1 to 50, excluding x?

    - by Cocorico
    I have 2 numbers which are between 0 and 49. Let's call them x and y. Now I want to get a couple of other numbers which are not x or y, but are also between 0 and 49 (I am using Objective C but this is more of a general theory question I think?). Method I thought of is: int a; int b; int c; do { a = arc4random() % 49; } while ((a == x) || (a == y)); do { b = arc4random() % 49; } while ((b == x) || (b == y) || (b == a)); do { c = arc4random() % 49; } while ((c == x) || (c == y) || (c == a) || (c == b)); But it seem kind of bad to me, I don't know, I am just trying to learn to be a better programmer, what would be the most elegant way to do this for best practices?

    Read the article

  • Best way to get a random number from 1 to 50 which ISN'T x

    - by Cocorico
    Hi guys! So this is probably programming 101 stuff, but I have a problem: I have 2 numbers which are between 0 and 49. Let's call them x and y. Now I want to get a couple of other numbers which are not x or y, but are also between 0 and 49 (I am using Objective C but this is more of a general theory question I think?). Method I thought of is: int a; int b; int c; do { a = arc4random() % 49; } while ((a == x) || (a == y)); do { b = arc4random() % 49; } while ((b == x) || (b == y) || (b == a)); do { c = arc4random() % 49; } while ((c == x) || (c == y) || (c == a) || (c == b)); But it seem kind of bad to me, I don't know, I am just trying to learn to be a better programmer, what would be the most elegant sweet way to do this for best practices? Thanks!

    Read the article

  • App crashes often in a for-loop

    - by Flocked
    Hello, my app crashes often in this for-loop: for (int a = 0; a <= 20; a++) { int b = arc4random() % [newsStories count]; NSString * foo = [[NSString alloc]initWithString:[[newsStories objectAtIndex: arc4random() % b]objectForKey:@"title"]]; foo = [foo stringByReplacingOccurrencesOfString:@"’" withString:@""]; foo = [[foo componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@" "]; foo = [foo stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; textView.text = [textView.text stringByAppendingString:[NSString stringWithFormat:@"%@ ", foo]]; } The code changes a NSString from a NSDictionary and adds it into a textView. Sometimes it first crashes in the second time using the for-loop. What did I wrong?

    Read the article

  • Youtube video embed in WebView and MoviePlayer control

    - by Tronic
    hi, i embed a youtube video into a webview. the problem is: when i pop the current view (which includes the webview) from navigation controller, the the movie itself stops, but the audio is continues running. when i push the view controller on the navigation controller again, i can play the movie newly, but the old audio is still there. my webview code ids_ = [NSArray arrayWithObjects:@"2b84g38Z_60",@"3URx0tM-rMc",@"HZpi-2HVhq0",@"Hhns0DRPI44",@"hRuoxRQ4Q3k",@"lkMXwNBGRA8",@"tXGc6wWIFJo",@"uzGdEn8aW-Q",@"ZAoEBdt8C5M",@"vn8EJqt2BvQ",@"7Z_qRbjG6Ck",@"JspRcxGUijs"@"lM2lcVOh5YU",@"2b84g38Z_60",nil]; int numIds_ = [ids_ count]; NSLog(@"%d", arc4random()%numIds_); NSString *youTubeVideoHTML = [[NSString alloc] initWithFormat:@"<html><head></head><body style=\"margin:0;background-color:#000;\"><iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"365\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe></body></html>", [ids_ objectAtIndex:arc4random()%numIds_]]; NSLog(youTubeVideoHTML); [youtubeView loadHTMLString:youTubeVideoHTML baseURL:nil]; thanks in advance

    Read the article

  • How to create array with unique sprites? in cocos2d iphone

    - by prakash s
    I write the code like this. This displays only one sprite (red colour bubble) with number of times and moving down, but actually I want to display different sprites (different colour bubble) every time and moving down. I also add no of .png images in resource folder of my project. Here I used only 3.png, but I need to display all *.png images (different colour bubbles) in my project but I don't know how to get this. Please help me Thank you. Here is the code: -(void)addTarget { CCSprite *target = [CCSprite spriteWithFile:@"3.png" rect:CGRectMake(0, 0, 256, 256)]; CGSize winSize = [[CCDirector sharedDirector] winSize]; int minY = target.contentSize.height/2; int maxY = winSize.height - target.contentSize.height/2; int rangeY = maxY - minY; int actualY = (arc4random() % rangeY) + minY; // Create the target slightly off-screen along the right edge, // and along a random position along the Y axis as calculated above target.position = ccp(winSize.width + (target.contentSize.width/2), actualY); [self addChild:target]; // Determine speed of the target int minDuration = 4.0; int maxDuration = 12.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2,actualY)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; // Add to targets array target.tag = 2; [_targets addObject:target]; } -(void)gameLogic:(ccTime)dt { [self addTarget]; } -(id) init { if( (self=[super initWithColor:ccc4(255,255,255,255)] )) { // Enable touch events self.isTouchEnabled = YES; // Initialize arrays _targets = [[NSMutableArray alloc] init]; _projectiles = [[NSMutableArray alloc] init]; // Get the dimensions of the window for calculation purposes CGSize winSize = [[CCDirector sharedDirector] winSize]; [self schedule:@selector(gameLogic:) interval:1.0]; [self schedule:@selector(update:)]; } return self; } - (void)update:(ccTime)dt { NSMutableArray *projectilesToDelete = [[NSMutableArray alloc] init]; for (CCSprite *projectile in _projectiles) { CGRect projectileRect = CGRectMake(projectile.position.x - (projectile.contentSize.width/2), projectile.position.y - (projectile.contentSize.height/2), projectile.contentSize.width, projectile.contentSize.height); NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init]; for (CCSprite *target in _targets) { CGRect targetRect = CGRectMake(target.position.x - (target.contentSize.width/2), target.position.y - (target.contentSize.height/2), target.contentSize.width, target.contentSize.height); if (CGRectIntersectsRect(projectileRect, targetRect)) { [targetsToDelete addObject:target]; } } for (CCSprite *target in targetsToDelete) { [_targets removeObject:target]; [self removeChild:target cleanup:YES]; _projectilesDestroyed++; if (_projectilesDestroyed > 30) { //GameOverScene *gameOverScene = [GameOverScene node]; // [gameOverScene.layer.label setString:@"You Win!"]; // [[CCDirector sharedDirector] replaceScene:gameOverScene]; } } if (targetsToDelete.count > 0) { [projectilesToDelete addObject:projectile]; } [targetsToDelete release]; } for (CCSprite *projectile in projectilesToDelete) { [_projectiles removeObject:projectile]; [self removeChild:projectile cleanup:YES]; } [projectilesToDelete release]; }

    Read the article

  • iPhone:How to make an integer array and store values in Obj-C?

    - by user187532
    Hi, I want to know a simple thing, which i couldn't get it is that i want to store 10 values in an integer array dynamically and then i have to check that stored values and compared with the current values whether it is same or not in some other condition. Initially i tried same like C array, int temp[10], but seems to be that is not possible to set and get method, then i tried NSNumber like below, In AppDelagate file, NSMutableArray *reqID; @property (nonatomic,readwrite) NSMutableArray * reqID; @synthesize reqID; ........................ ........................ ........................ In Some other file, int rd = (1+arc4random() % [arr count]); [myDelagate.reqID addObject:[NSNumber numberWithUnsignedInteger:rd]]; then i need to check, for (int i=0; i<10; i++) { NSUInteger anInt = [[amyDelagate.reqID objectAtIndex:i] unsignedIntegerValue]; if ( anInt==rd ) { rd = (1+arc4random() % [arr count]); break; } } [myDelagate.reqID addObject:[NSNumber numberWithUnsignedInteger:rd]]; But it doesn' work as expected, i.e array value doesn't give proper value. i don't know how to use integer array in Obj-C and handle it to access later etc. Could someone please explian me?

    Read the article

  • Animate multiple UIView in a cicle

    - by Giovanni
    Hi all, i'm creating a card game on iphone. My problem is that i want to animate the cards at the beginning of the game making the cards animate from a point to another point in a deck. I move my cards that are UIView, in afor cicle. this is what i do With this code, alla tha cards move together, i need to move the cards separately one after another CGPoint point; // Create the deck of playing cards for (int i = 0; i < 28; i++) { CardView *aCardView = [self.mazzo objectAtIndex:i]; point.x = -100; point.y = 200; aCardView.center = point; aCardView.zPosition = i; [self.viewGioco addSubview:aCardView]; [aCardView release]; //Here i call the method to position the card [aCardView positionCard]; } in the card view there are this methods -(void)positionCard{ [self performSelector:@selector(_positionCard) withObject:nil afterDelay:0.0]; } -(void)_positionCard{ [UIView beginAnimations:@"posizionacarta" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDuration:0.3f]; CGPoint point; point.x = 280 + ((arc4random() % 2) - 1); point.y = 240 + ((arc4random() % 2) - 1); self.center = point; [UIView commitAnimations]; [self setNeedsLayout]; }

    Read the article

  • Box2d Cocos2d circle crash on contact with ground

    - by Oliver Cooper
    this is my first question here so sorry if I do something wrong or this is too long. I have been reading this tutorial by Ray Wenderlich, I have modified it so it is flatter and gradually goes down hill. Basically I have a ball roll down a bumpy hill, but at the moment the ball only drops from about 100 pixels above. When ever the touch the app crashes (the app is a Mac Cocos2d Box2d app). The ball code is this: CGSize winSize = [CCDirector sharedDirector].winSize; self.oeva = [CCSprite spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:@"Ball.png"]rect:CGRectMake(0, 0, 64, 64)]; _oeva.position = CGPointMake(68, winSize.height/2); [self addChild:_oeva z:1]; b2BodyDef oevaBodyDef; oevaBodyDef.type = b2_dynamicBody; oevaBodyDef.position.Set(68/PTM_RATIO, (winSize.height/2)/PTM_RATIO); // oevaBodyDef.userData = _oeva; _oevaBody = world->CreateBody(&oevaBodyDef); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(60/PTM_RATIO, 400/PTM_RATIO); bodyDef.userData = _oeva; b2Body *body = world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. b2CircleShape dynamicBox; dynamicBox.m_radius = 70/PTM_RATIO;//These are mid points for our 1m box // Define the dynamic body fixture. b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); That works fine. This is the terrain code, this also works fine: -(void)generateTerrainWithWorld: (b2World *) inputWorld: (int) hillSize;{ b2BodyDef bd; bd.position.Set(0, 0); body = inputWorld->CreateBody(&bd); b2PolygonShape shape; b2FixtureDef fixtureDef; currentSlope = 0; CGSize winSize = [CCDirector sharedDirector].winSize; float xf = 0; float yf = (arc4random() % 10)+winSize.height/3; int x = 200; for(int i = 0; i < maxHillPoints; ++i) { hillPoints[i] = CGPointMake(xf, yf); xf = xf+ (arc4random() % x/2)+x/2; yf = ((arc4random() % 30)+winSize.height/3)-currentSlope; currentSlope +=10; } int hSegments; for (int i=0; i<maxHillPoints-1; i++) { CGPoint p0 = hillPoints[i-1]; CGPoint p1 = hillPoints[i]; hSegments = floorf((p1.x-p0.x)/cosineSegmentWidth); float dx = (p1.x - p0.x) / hSegments; float da = M_PI / hSegments; float ymid = (p0.y + p1.y) / 2; float ampl = (p0.y - p1.y) / 2; CGPoint pt0, pt1; pt0 = p0; for (int j = 0; j < hSegments+1; ++j) { pt1.x = p0.x + j*dx; pt1.y = ymid + ampl * cosf(da*j); fullHillPoints[fullHillPointsCount++] = pt1; pt0 = pt1; } } b2Vec2 p1v, p2v; for (int i=0; i<fullHillPointsCount-1; i++) { p1v = b2Vec2(fullHillPoints[i].x/PTM_RATIO,fullHillPoints[i].y/PTM_RATIO); p2v = b2Vec2(fullHillPoints[i+1].x/PTM_RATIO,fullHillPoints[i+1].y/PTM_RATIO); shape.SetAsEdge(p1v, p2v); body->CreateFixture(&shape, 0); } } However when ever the two collide the app crashes. The crash error is: Thread 6 CVDisplayLink: Program received signal: "SIGABRT" The error occurs on line 96 of b2ContactSolver.cpp: b2Assert(kNormal > b2_epsilon); The error log is: Assertion failed: (kNormal 1.19209290e-7F), function b2ContactSolver, file /Users/coooli01/Documents/Xcode Projects/Cocos2d/Hill Slide/Hill Slide/libs/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 96. Sorry if I rambled on for too long, i've been stuck on this for ages.

    Read the article

  • Releasing the keyboard stops shake events. Why?

    - by Moshe
    1) How do I make a UITextField resign the keyboard and hide it? The keyboard is in a dynamically created subview whose superview looks for shake events. Resigning first responder seems to break the shake event handler. 2) how do you make the view holding the keyboard transparent, like see through glass? I have seen this done before. This part has been taken care of thanks guys. As always, code samples are appreciated. I've added my own to help explain the problem. EDIT: Basically, - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; gets called in my main view controller to handle shaking. When a user taps on the "edit" icon (a pen, in the bottom of the screen - not the traditional UINavigationBar edit button), the main view adds a subview to itself and animates it on to the screen using a custom animation. This subview contains a UINavigationController which holds a UITableView. The UITableView, when a cell is tapped on, loads a subview into itself. This second subview is the culprit. For some reason, a UITextField in this second subview is causing problems. When a user taps on the view, the main view will not respond to shakes unless the UITextField is active (in editing mode?). Additional info: My Motion Event Handler: - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"%@", [event description]); SystemSoundID SoundID; NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"shake" ofType:@"aif"]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID); AudioServicesPlayAlertSound(SoundID); [self genRandom:TRUE]; } The genRandom: Method: /* Generate random label and apply it */ -(void)genRandom:(BOOL)deviceWasShaken{ if(deviceWasShaken == TRUE){ decisionText.text = [NSString stringWithFormat: (@"%@", [shakeReplies objectAtIndex:(arc4random() % [shakeReplies count])])]; }else{ SystemSoundID SoundID; NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"string" ofType:@"aif"]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID); AudioServicesPlayAlertSound(SoundID); decisionText.text = [NSString stringWithFormat: (@"%@", [pokeReplies objectAtIndex:(arc4random() % [pokeReplies count])])]; } } shakeReplies and pokeReplies are both NSArrays of strings. One is used for when a certain part of the screen is poked and one is for when the device is shaken. The app will randomly choose a string from the NSArray and display onscreen. For those of you who work graphically, here is a diagram of the view hierarchy: Root View -> UINavigationController -> UITableView -> Edit View -> Problem UITextfield

    Read the article

  • Random Number Generator

    - by skinni
    - (IBAction)randomnum{ int randomNumber1 = 1+ arc4random() %(49); label1.text = [NSString stringWithFormat:@"d", randomNumber]; Local declaration of randomNumber hides instance variable. How can i get round this warning? thanks

    Read the article

  • how to stop the array of sprite in cocos2d?

    - by prakash s
    I am devoloping the bubble shooter game in cocos2d how to stop the sprite movement at the center of the game scene in my game bec i want to shoot the bubble after stopping the movenent at certain position here is my code -(void)addTarget { CGSize winSize = [[CCDirector sharedDirector] winSize]; NSMutableArray * movableSprites = [[NSMutableArray alloc] init]; NSArray *images = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png",@"5.png", @"6.png", @"7.png",@"8.png" ,nil]; for(int i = 0; i < images.count; ++i) { int index = (arc4random() % 8)+1; NSString *image = [NSString stringWithFormat:@"%d.png", index]; CCSprite*target = [CCSprite spriteWithFile:image]; // generate random number based on size of array (array size is larger than 10) float offsetFraction = ((float)(i+1))/(images.count+1); //target.position = ccp(winSize.width*offsetFraction, winSize.height/2); target.position = ccp(350*offsetFraction, 460); [self addChild:target]; [movableSprites addObject:target]; id actionMove = [CCMoveTo actionWithDuration:10 position:ccp(350*offsetFraction, 100)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; } here bubbles are moving from top to bottom but after 5 rows my bubble movement should be stop so please help me to get that logic

    Read the article

  • iOS - UISlider - How to make a slider to auto-move [closed]

    - by drodri420
    its me again. Coming back with another noobish question: This time its , can you make a UISlider move by itself??? I've implemented this on the .m ///This right here makes a slider move 1point from 1 to 100, once it reaches 100 it goes backwards and so on... - (IBAction)moveSlider:(UISlider *)sender { int flag=0, counter=1; while(flag == 0) { counter = counter + (.25 * round); if(counter == 100) { flag = 1; } if(counter < 100 && counter > 1) { slider.value = counter; } } while(flag == 1) { counter = counter - (.25 * round); if(counter == 1) { flag = 0; } if(counter < 100 && counter > 1) { slider.value = counter; } } } And Implemented this on another action: -(void)startNewRound { round+=1; targetValue = 1 + (arc4random() % 100); self.slider.value = currentValue; [self moveSlider:slider]; } I think I lost it along the way and Im just typing pure nonsense but If anyone could point me in the right direction on to which is it that Im doing wrong??

    Read the article

  • Incorrect decrement of the reference count

    - by idober
    I have the following problem: In one flow of the execution I use alloc, and on the other flow, alloc is not needed. At the end of the if statement, in any case, I release the object. When I do 'build and Analize' I get an error: 'Incorrect decrement of the reference count of an object is not owned by the caller'. How to solve that? UIImage *image; int RandomIndex = arc4random() % 10; if (RandomIndex<5) { image = [[UIImage alloc] initWithContentsOfFile:@"dd"]; } else { image = [UIImage imageNamed:@"dd"]; } UIImageView *imageLabel =[[UIImageView alloc] initWithImage:image]; [image release]; [imageLabel release];

    Read the article

  • take out objects from randomizer obj c

    - by David Pollak
    hello everyone, I'm a new "developer" trying to build some iPhone app I'm making an app which gets text from a list of objects in a NSArray and then randomizes them and display one in a TextView, here's the code: - (IBAction)azione{ NSArray *myArray= [NSArray arrayWithObjects: @"Pasta",@"Pizza",@"Wait",@"Go", nil]; int length = [myArray count]; int chosen = arc4random() % length; testo.text = [myArray objectAtIndex: chosen]; } what I want to do now, is when I open the app and get a random object, to take it out from the list, so that it won't be picked again ex. I open the appI get "Pizza"Do the action againI don't get "Pizza" anymore, only "Pasta" "Wait" and "Go" What should I do ? Which code should I use ? Thanks for answers

    Read the article

  • Line breaks in "NSString"s returned from PList don't work.

    - by Moshe
    I've seen this post: http://stackoverflow.com/questions/2035567/nsstring-newline-escape-in-plist but I'd like to know if there's a way to pragmatically render \n line breaks. I'm currently using: decisionText.text = [NSString stringWithFormat: (@"%@", [replies objectAtIndex:(arc4random() % [replies count])])]; Which randomly grabs a String from the replies array. The array was loaded from a plist like so: replies = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"AdviceList" ofType:@"plist"]]; What am I missing? The answer can't be to manually enter line breaks. That's not programming! (Sounds like word processing to me.)

    Read the article

  • Getting random objects from an array, and if the objects are the same, get a new object.

    - by XcodeDev
    Hi, I have made a jokes application, where the user generates a joke and the joke will display in a UILabel. However I am trying to randomise the jokes show, but I do not want to show the same joke twice. Please could you tell me how I could do this. I am using the code below to try and do that, but it seems that it is not working. - (IBAction)generateNewJoke { if (i < [jokeArray count]) { i++; [userDefaults setInteger:[userDefaults integerForKey:kNewIndex] forKey:kOldIndex]; int oldnumber = [userDefaults integerForKey:kOldIndex]; int newnumber = [userDefaults integerForKey:kNewIndex]; [answerLabel setText:@""]; [userDefaults setInteger:i forKey:kNewIndex]; if (oldnumber == newnumber) { NSLog(@"they are the same"); [userDefaults setInteger:arc4random()%[jokeArray count] forKey:kNewIndex]; } [jokeLabel setText:[jokeArray objectAtIndex:[userDefaults integerForKey:kNewIndex]]]; } }

    Read the article

  • Selecting random numbers iphone sdk

    - by harekam_taj
    Hey, I want to select 10 random numbers from 1 to 35. I am trying to do the following, but I get some repeated numbers int totalNumberCnt = 1; while (totalNumberCnt < 11) { int randomNumber1 = 1 + arc4random() % 35; NSString *numberString = [NSString stringWithFormat: @"%d",randomNumber1]; NSLog(numberString); [firstNumber addObject:numberString]; [secondNumber addObject:numberString]; totalNumberCnt++; } Thank you for your help.

    Read the article

  • Generating random numbers in C

    - by moonstruckhorrors
    While searching for Tutorials on generating random numbers in C I found This Topic When I try to use the rand() function with parameters, I always get the random number generated 0. When I try to use the rand() function with parameters, I always get the value 41. And whenever I try to use arc4random() and random() functions, I get a LNK2019 error. Here's what I'm doing: #include <stdlib.h> int main() { int x; x = rand(6); printf("%d", x); } This code always generate 41. Where am I going wrong?? P.S. : I'm running Windows XP SP3 and using VS2010 Command Prompt as compiler. P.P.S. : Took me 15 minutes to learn how to format properly.

    Read the article

  • Playing animations in sequence in objecive c

    - by Ohmnastrum
    I'm trying to play animations in sequence but i'm having issues playing them as a for loop iterates through the list of objects in an array. it will move through the array but it won't play each one it just plays the last... -(void) startGame { gramma.animationDuration = 0.5; // Repeat forever gramma.animationRepeatCount = 1; int r = arc4random() % 4; [colorChoices addObject:[NSNumber numberWithInt:r]]; int anInt = [[colorChoices objectAtIndex:0] integerValue]; NSLog(@"%d", anInt); for (int i = 0; i < colorChoices.count; i++) { [self StrikeFrog:[[colorChoices objectAtIndex:i] integerValue]]; //NSLog(@"%d", [[colorChoices objectAtIndex:i] integerValue]); sleep(1); } } it moves through the whole cycle really fast and sleep isn't doing anything to allow it to play each animation... any suggestions?

    Read the article

  • Adding an integer onto an array

    - by Ohmnastrum
    I'm trying to add random numbers onto the end of this array when ever I call this function. I've narrowed it down to just this so far. when ever I check to see if anything is in the array it says 0. So now i'm quite stumped. I'm thinking that MutableArray releases the contents of it before I ever get to use them. problem is I don't know what to use. A button calls the function and pretty much everything else is taken care of its just this portion inside the function. NSMutableArray * choices; -(void) doSomething { int r = arc4random() % 4; //The problem... [choices addObject:[NSNumber numberWithInt:r]]; int anInt = [[choices objectAtIndex:1] integerValue]; NSLog(@"%d", anInt); //I'm getting nothing no matter what I do. //some type of loop that goes through the array and displays each element //after it gets added }

    Read the article

1 2  | Next Page >