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 8459603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:22:36+00:00 2026-06-10T13:22:36+00:00

I used to work on macro scripts for windows and this was doable: VAR=0

  • 0

I used to work on macro scripts for windows and this was doable:

VAR=0

Label>LOOP
VAR=VAR+1
ANOTHERVAR%VAR%=8 (all variables up to 30 will be set to 8)
if>VAR>=30 {Goto>BREAK}else{Goto>LOOP}
Label>BREAK
EXIT

The code above would effectively set “ANOTHERVAR1” up to “ANOTHERVAR30” to the value 8.

Now my question is, how can I achieve the same results on objective-c?
I’ve got many variables to set. Right now on XCode i need to set 30 variables. I’ve always set them all one by one but it’s taking up space and my source code is over 10k lines now.

This is what i’ve got :

if (Dedicatedkind==@"Cat"){
_oAttack7.alpha=0;
_oAttack7.enabled=NO;   
}

This basically disables non-required buttons, in this case Dedicatedkind always equals Cat.
I would need to disable buttons 7 to 30.
But I’ve got over 80 different Dedicatedkind. I hope you understand my problem.
I want to be able to disable any number of buttons with less lines of codes than it takes if I was to set them all manually.

Like this :

if (Dedicatedkind==@"Cat"){
_oAttack7.alpha=0;
_oAttack7.enabled=NO;
_oAttack8.alpha=0;
_oAttack8.enabled=NO;
_oAttack9.alpha=0;
_oAttack9.enabled=NO;
And so on, until I reach _oAttack30
}

If it matters at all, this is for the iphone and i’m working with storyboard.

Extra info:

Setting enabled:NO is simply a safety because if condition is met, those buttons turns alpha:0.3 which re-enables them.
Unfortunately my code is too large to post every roots and conditions.
Those buttons are attacks learned by the cat, there’s 30 attacks maximum but the cat only learns 6 of them. Those 24 buttons must be completely invisible while the 6 attacks, even if not learned yet, must be at least partially visible. When learning those attacks, the appropriate buttons turns completely visible. That’s for the cat. In this game, the cat is one of the three basic animals you get to have when starting a new game, therefore has limitations. Bigger, rarer animals may learn more than 6 attacks.

Fortunately, I’ve already done all of that except the 24 attacks/Buttons that must be disabled, which led me to this question!

  • 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-06-10T13:22:37+00:00Added an answer on June 10, 2026 at 1:22 pm

    First, put your buttons into an IBOutletCollection(UIButton). You need to declare a property and make connections in the interface builder.

    Next, create an NSDictionary that maps Dedicatedkind to instances of NSIndexSet. Initialize the dictionary with 80 mappings – one for each kind. With this dictionary and the button array in hand, you would be able to look up an index set by Dedicatedkind, iterate through indexes contained in it, and enable/disable buttons as required in a simple loop. As an added bonus, your long chain of if/then/else will be gone too.

    Header:

    @property (nonatomic, readwrite) IBOutletCollection(UIButton) NSArray *allButtons;
    NSDictionary *buttonIndexByKind;
    

    Designated initializer:

    NSIndexSet *catSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(5, 30)];
    NSIndexSet *dogSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 15)];
    buttonIndexByKind = [NSDictionary dictionaryWithObjectsAndKeys:
        catSet, @"Cat", dogSet, @"Dog", nil
    ];
    

    When you need to enable/disable your buttons:

    NSIndexSet *toDisable = [buttonIndexByKind objectForKey:Dedicatedkind];
    [toDisable enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){
        UIButton *btn = [allButtons objectAtIndex:idx];
        btn.alpha=0;
        btn.enabled=NO;
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this used to work without a hitch but now I get a Socket
This code used to work but doesnt any more. i used a breakpoint, and
I swear this used to work, but it's not in this case. I'm trying
This code used to work. Then, maybe I changed something, somewhere (or if I
This piece of code used to work in MVC 1 but it does not
I want to have a macro dbtest that can be used like this: (dbtest
I used a handy macro with keybindings in Visual Studio to attach to Windows
I've got this workbook I've been trying to get to work via macro code.
Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero
Cocoa used to work on CS3 with the trick of putting a Cocoa bundle

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.