# NSSlider is confusing me.



## Untitled (Jul 15, 2004)

I have a screen saver that has a NSSlider in the configure sheet. This slider is attached to my screenSaver view via an action and an outlet.

```
@interface MYfnsView : ScreenSaverView 
{
	IBOutlet id _theSliderOfDoom;
	@private
		int _sliderOfDoomValue;
           int _anotherIntVar;
}
- (IBAction)sliderAction:(id)sender;
@end 

@implementation MYfnsView
- (IBAction) sliderAction:(id)sender
{	
	_sliderOfDoomValue = [_theSliderOfDoom intValue];
	_anotherIntVar = _sliderOfDoomValue;
	NSLog(@"Dbug_statement:%d", _anotherIntVar);
}
@end
```

When this code is run, 0 is always printed to the console. What I find interestng is if I output the value of _sliderOfDoomValue, it prints the value that the slider was "declicked" at. 
These variables are not used anywhere else. What is going on here? Thanks!


----------



## kainjow (Jul 16, 2004)

NSSliders use double/float values, so try calling doubleValue instead of intValue and then type cast it to an int:


```
- (IBAction) sliderAction:(id)sender
{       
        _sliderOfDoomValue = (int)[_theSliderOfDoom doubleValue];
        _anotherIntVar = _sliderOfDoomValue;
        NSLog(@"Dbug_statement:%d", _anotherIntVar);
}
@end
```

From Apple's documentation:



> To read the sliders value, as represented by the knobs current position, use an NSControl get method, such as floatValue;. To set the sliders value, use an NSControl set method, such as setFloatValue:.


----------



## Untitled (Jul 17, 2004)

Using casting, the value of the slider is sucessfully output in the sliderAction method. Progress! Thanks.
Unfortunately, when I print this variable out using NSLog when the sheet that this button is located on is closed, it prints 0. 
Do you know what is going on here? It is a global variable and it is only used in the sliderAction and closeSheet methods as shown.


```
- (IBAction)closeSheet:(id)sender
{
	NSLog(@"Dbug_statement2:%d", _anotherIntVar); // always prints 0!
	
	[_configureSheet orderOut:nil];	
	[NSApp endSheet:_configureSheet];	
}
```


----------



## Untitled (Jul 30, 2004)

Alright! figured it out. Apparently I had to connect the NSSlider not only my view, but also to the first responder...


----------

