So I am close to finishing my new and improved dice rolling program, for gaming. I have a couple of questions to help me wrap it up.
1) This code works when I enter a value into an NSTextField it then passes the value to an int variable
But then I type in the the value and hit return the box is still highlighted like it wants to be typed in again?
2) Jim helped me with this earlier and I get most of it except for the menuItem. I tried to read up on it today but I don't quite get it. I swapped out some of his code to fit mine.
Everytime it runs through the iteration it get the value of the dice and assigns it to the NSNumber 'side'. Then an NSString 'title' is created from the number. The title is then added to my popUpButton. the rest of it I don't quite get?
It runs fine and I can see the different titles in the popUpButton. What I don't understand is how I can retrieve the int value for the selection?
So my code would be like
How can I retrieve the value and assign it to my variable diceSelection? All of the rest of my code seems to work fine.
Thanks!
1) This code works when I enter a value into an NSTextField it then passes the value to an int variable
Code:
setMinOpenEnderRange = [setOpenEndRangeValue intValue];
2) Jim helped me with this earlier and I get most of it except for the menuItem. I tried to read up on it today but I don't quite get it. I swapped out some of his code to fit mine.
Code:
-(void)awakeFromNib
{
[self addSidedDiceSelection:100];
[self addSidedDiceSelection:20];
[self addSidedDiceSelection:10];
[self addSidedDiceSelection:8];
[self addSidedDiceSelection:6];
[self addSidedDiceSelection:4];
[self addSidedDiceSelection:2];
}
- (void)addSidedDiceSelection:(int)numberOfSides
{
NSNumber *side = [NSNumber numberWithInt: numberOfSides];
NSString *title = [NSString stringWithFormat: @"d%@", side];
[dieNumberPopUpDisply addItemWithTitle: title];
NSMenuItem *menuItem = [sidedDiceSelection lastItem];
[menuItem setRepresentedObject: side];
//dieNumSelection = [menuItem];
[menuItem setAction: @selector(selectDice:)];
[menuItem setTarget: self];
}
It runs fine and I can see the different titles in the popUpButton. What I don't understand is how I can retrieve the int value for the selection?
So my code would be like
Code:
dieRoll = arc4random() % diceSelection + 1;
How can I retrieve the value and assign it to my variable diceSelection? All of the rest of my code seems to work fine.
Thanks!