Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5956859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:19:04+00:00 2026-05-22T18:19:04+00:00

So far I have the code – (void)CreatenewBlock:(int)blockCountToSpawn { for (int i=0; i !=

  • 0

So far I have the code

- (void)CreatenewBlock:(int)blockCountToSpawn
{
    for (int i=0; i != blockCountToSpawn; i++) 
    {
        theBlockxCord = arc4random() % 4;
        theBlockyCord = arc4random() % 4;
        NSLog(@"New Block with Cords (%i, %i)",theBlockxCord, theBlockyCord);
    }

}

This loops until it reaches the anount of blockCountToSpawn
This works exactly how I want it to but I want to set theBlockxCord to a new variable each time. So the end result would be something like:

theBlockxCordOfBlock1=2
theBlockxCordOfBlock2=4
theBlockxCordOfBlock3=1
theBlockxCordOfBlock4=3

Instead of theBlockXCord being overwritten each time.

For bonus points, Is there a single way to call of them maybe in an array so I don’t have to keep doing this:

if (theBlockxCordOfBlock1 == 2 || theBlockxCordOfBlock3 == 2 ..etc)
{
   do stuff..
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:19:05+00:00Added an answer on May 22, 2026 at 6:19 pm

    You can use C arrays or an NSMutableArray. You will have to convert the ints to NSNumbers before you can add it to the array.

    - (void)CreatenewBlock:(int)blockCountToSpawn
    {
        NSMutableArray *blockXCoord = [NSMutableArray array]; // Retain it as needed.
        NSMutableArray *blockYCoord = [NSMutableArray array];
        for (int i=0; i != blockCountToSpawn; i++) 
        {
            [blockXCoord addObject:[NSNumber numberWithInt:(arc4random() % 4)];
            [blockYCoord addObject:[NSNumber numberWithInt:(arc4random() % 4)];
        }
    
        ...
    }
    

    if you want to search for 2 then do this

    if ( [blockXCoord indexOfObject:[NSNumber numberWithInt:2]] != NSNotFound ) {
        ... do stuff
    }
    

    or

    if ( [blockXCoord containsObject:[NSNumber numberWithInt:2]] ) {
        ... do stuff
    }
    

    EDIT

    for ( int i = 0; i < [blockXCoord count]; i++ ) {
        NSPoint point = NSMakePoint([[blockXCoord objectAtIndex:i] intValue],[[blockYCoord objectAtIndex:i] intValue]);
    
        ... do something with the point.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I have this code int w = (int)((450-150)*random()+150); This generates a number
So far i have got the code below which works lovely when trying an
I have code blindness, it's like snowblindness, just wth far too much code. I
I have this code so far which perfectly but relies on there being a
So far I have managed to write some code that should print the source
I'm a total newb to LINQ. Here is the code I have so far:
This is what I have as far as code, it is in the first
How far is the code for best functionallity? I have two ComboBox, so the
I have thos piece of code: Math&&Math.random?Math.floor(Math.random()*10000000000000):Date.getTime(); And as far as i know &&
According to what I have found so far, I can use the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.