0
\$\begingroup\$

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");
  }
}
\$\endgroup\$
  • \$\begingroup\$ Yes, pass a reference to the instance object you want observed to the class you want to do the observing. \$\endgroup\$ – user1430 Nov 27 '13 at 16:15
  • \$\begingroup\$ 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? \$\endgroup\$ – dlkulp Nov 27 '13 at 19:33
0
\$\begingroup\$

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

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.