PDA

View Full Version : Accessing PawnOwner



legacy-Roy_Fokker
08-20-2003, 01:45 PM
i am playing around with TexRotator thing for hud.
and i come up to this problem

I can't Seem to be able to access PawnOwner in HudRotatingTex. But don't understand why (Still new to this whole scripting thing)
I can get the texture to display fine, it just won't rotate

i have 2 classes
HudRotatingTex.uc


class HudRotatingTex extends HudBase;

#exec OBJ LOAD FILE=TestInterface.utx

var int i;

var TexRotator test;

simulated event PostBeginPlay()
{
//-- Scripted Texture = Setup the RotatingTex Image -----------
test = new(None) class'TexRotator';
test.TexRotationType = TR_FixedRotation;
test.UOffset = 128;
test.VOffset = 128;
test.TexCoordCount = TCN_2DCoords;
test.TexCoordProjected = false;
test.Material = Texture'TestInterface.HUD.RotatingTexture';
}
simulated event Destroyed()
{
test = none;
}

simulated function DrawRotatingTex(Canvas c)
{
local color tempColor;
local byte tempstyle;

tempColor = c.DrawColor; //storing the values
tempstyle= c.Style;

c.DrawColor=WhiteColor;
c.Style=ERenderStyle.STY_Additive;

//-------- Draw the RotatingTex ---------------------
c.SetPos(0,0);
test.Rotation.Yaw = i;
c.DrawTile(test, 256, 128, 0.0, 0.0, 256, 256);
c.DrawText(i);
//--------- Done drawing ----------------------------

c.DrawColor = tempColor;//restore values
c.Style = tempstyle;

rotateTexture();
}

simulated function rotateTexture()
{
i = PawnOwner.Rotation.Yaw; //-- This doesn't Work WHY WHY WHY???????
}


defaultproperties
{
i= 0;
}


HudDisplayTex.uc


class HudDisplayTex extends HudBase;

var HudRotatingTex objRotatingTex;

simulated function postbeginplay()
{
objRotatingTex = spawn(class'HudRotatingTex');
objRotatingTex.postbeginplay();
}

simulated function destroyed()
{
objRotatingTex.destroyed();
}

simulated function DrawHud(canvas c)
{
super.DrawHud(c);
objRotatingTex.DrawRotatingTex(c);
c.DrawText(PawnOwner.Rotation.Yaw); //--- This Displays Fine
}

legacy-Lews
08-20-2003, 04:35 PM
Instead of:



i = PawnOwner.Rotation.Yaw;


Try:



if(PawnOwner.Controller != None)
{
i = (PawnOwner.Controller.GetViewRotation()).Yaw);
}

legacy-Roy_Fokker
08-20-2003, 06:43 PM
Nope doesn't work.

the texture's rotation value doesn't change and i still get access none error when the rotateTexture function reaches that if statement (more specifically that line )

legacy-Doc_EDo
08-20-2003, 07:20 PM
Maybe the owner isnt referenced?
objRotatingTex = spawn(class'HudRotatingTex');

class('HudRotatingTex', PlayerOwner) ?

put some

if (PlayerOwner!=none)
log("No player owner");
arround to see if it's ever referenced.

Are you sure this
test.TexRotationType = TR_FixedRotation; doesnt prevent the rotation?

legacy-Roy_Fokker
08-20-2003, 09:03 PM
yes, if you make HudRotatingTex as default hud gui you will see that it work

reason i have it as fixed is because i don't want it to move unless the player moves (which is updated drawrotatingtex)

legacy-[BIO]Tech
08-21-2003, 09:43 AM
Originally posted by Doc_EDo put some

if (PlayerOwner!=none)
log("No player owner");
arround to see if it's ever referenced.


Note: PlayerOwner!=none should be PlayerOwner==none

If you want to check for unowned pawns. Prob just an oversight in syntax, but I thought I'd mention it.

legacy-Roy_Fokker
08-21-2003, 11:18 AM
Well i found a work around solution to the problem i was having

its a sort of a hack,

i changed the following lines
In HudRotatingTex.uc

simulated function DrawRotatingTex(Canvas c, Pawn PawnOwner)
rotateTexture(PawnOwner);


simulated function rotateTexture(Pawn PawnOwner)

and in HudDisplayTex.uc

objRotatingTex.DrawRotatingTex(c, PawnOwner);


As i said i think this is a hack/ work around the problem. If anyone can tell me why HudRotatingTex is not able to access PawnOwner i would be grateful

legacy-Mychaeel
08-21-2003, 11:23 AM
HudRotatingTex is derived from HudBase. PawnOwner is defined in HudBDeathMatch, however. So there.

legacy-Roy_Fokker
08-21-2003, 11:38 AM
i thought PawnOwner was defined in HUD

legacy-segall
08-21-2003, 04:58 PM
It is.

The reason your code doesn't work is that the PawnOwner variable in HudRotatingTex is never set to anything, because it's not your active Hud. The active Hud is HudDisplayTex and its PawnOwner is set properly by UT, as you can see. There is only ever one active Hud.

So the lesson is to only derive one HUD class. It makes sense to put all HUD related code in one file, because you can only have one HUD at any point in time (right?). If you still want to separate the code in different files, I suggest deriving your HudRotatingTex directly off Object, because it doesn't need to know anything about the Hud. Then, pass in the desired rotation using function parameters.