slider inside window function not inside onGui

I have an OnGUI function with a window in it that works fine. I want to have a slider inside the window so I am putting it inside the function WindowFunction (windowID : int) that the window calls to, but it won’t budge at all. I am using hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0); with a predefined variable of hSliderValue called before the function and the OnGUI. I put the same code in the OnGUI and it works, but not in the window call function.
How can I get them to work together?
thanks

You should post your code here! Anyway, the variable hSliderValue must be a member variable, which means that it must be declared outside any function. Inside OnGUI, don’t use the keyword var before hSliderValue, or a temporary local variable with this name will be created (temporary variables only exist inside the function, being destroyed upon return). The code should be something like this:

// declare the variable outside any function:
var hSliderValue: float = 0;

function OnGUI(){
  // don't use "var" before the variable!
  hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0);
}

If this doesn’t solve your problem, edit your question and post your script.

I suppose if this won’t work I could use a variable for the position and have it check where the window is and change it relative to that, but I was hoping for a more elegant solution.
Here is my code.

var position : int = 200;

var hScrollbarValue : float;

private var hSliderValue : float = 4.1; 

function OnGUI () 

{

var windowRect = GUI.Window(0, Rect((Screen.width / 2) - (windowWidth / 2), 

                                   position, 

                                   windowWidth, 

                                   windowHeight), 
WindowFunction, "Menu");

}

function WindowFunction (windowID : int) {

	hScrollbarValue = GUI.HorizontalScrollbar (Rect (125, 125, 200, 30), hScrollbarValue, 1.0, 0.0, 10.0);

	hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0);

}

was trying to get a scrollbar to work too since it’s more the style I want, but same issue.

edit:
Using what I said here using a variable for the position and sliding the window in and out with the buttons and sliders at the same time worked, but the buttons and sliders were behind the windwo so I needed one in the called function just to make it look good. That doubles the amount of buttons but is doable. My issue got fixed and it works properly now since I deleted buttons in another script in the OnGUI section. Apparently they were were conflicting each other for some reason. No idea why, there was nothing in the script that would suggest that.