UnrealScript access variable in one class from another?

So there are some similar questions out there but the responses often say that you should use 'new' or 'spawn', but I'm working with the playercontroller don't want to make a new playercontroller. Maybe this isn't the right way to be doing this but I want to view the state of a variable in the playercontroller that will change fairly often from my HUD. Is there a way to do this?

playercontroller class

var bool bYeaNo;

exec function change() {
bYeaNo= !bYeaNo;
}

defaultproperties
{
bYeaNo = false
}


HUD class

event PostRender() {
Super.PostRender();
}

function DrawHUD() {
Super.DrawHUD();
Canvas.SetDrawColor(0, 0, 0);
Canvas.SetPos(25, 25);

if (bYeaNo) { //this is wrong so what would make this work?
Canvas.DrawText("Yea");
} else {
Canvas.DrawText("No");
}
}

• Yes, pass a reference to the instance object you want observed to the class you want to do the observing. – user1430 Nov 27 '13 at 16:15
• I'm aware of how you would do it in theory but I don't know how to actually do that. "Out" is listed as the way to pass by reference but that would only be useful if DrawHUD() took params right? – dlkulp Nov 27 '13 at 19:33

Wasn't quite what I was thinking but this works well and gets the job done. Basically what I do is register the playercontroller with gameinfo which makes it really easy to retrieve values in the hud class.

MyPlayerController class

simulated function PostBeginPlay() {
MyGameInfo(WorldInfo.Game).RegisterController(self);
}

var bool bYeaNo;

exec function change() {
bYeaNo= !bYeaNo;
}

defaultproperties
{
bYeaNo = false
}


MyGameInfo class

function RegisterController(MyPlayerController PC) {
MyController = PC;
}

defaultproperties
{
HUDType=class'MyGame.MyHUD'
PlayerControllerClass=class'MyGame.MyPlayerController'
}


MyHUD class

event PostRender() {
Super.PostRender();
}

function DrawHUD() {
Super.DrawHUD();
Canvas.SetDrawColor(0, 0, 0);
Canvas.SetPos(25, 25);

if (MacroGameInfo(WorldInfo.Game).MyController.bYeaNo) {
Canvas.DrawText("Yea");
} else {
Canvas.DrawText("No");
}
}


Found from willyg302.wordpress.com