[UT2K4]Accessing variables from other classes

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

eLy

New Member
Mar 18, 2003
169
0
0
Visit site
This has been driving me crazy for a while, and i know it's possibile.
I'm trying to access a global variable from another class, i got the code from http://wiki.beyondunreal.com/wiki/Typecasting
But when i log the variable, it always returns 0.00

here's the variable i want to call.

Code:
class MyShockProjectile extends ShockProjectile;

var float MyVar;

function SuperExplosion()
{
             MyVar = 10
             log("test: "$myVar);        // returns 10
	Spawn(class'MyShockCombo');
.....
}

and this is where i want to call it:

Code:
class MyShockCombo extends ShockCombo;

var class<actor> ConvertMe;

simulated event PostBeginPlay()
{
          local float x;
          ConvertMe = class'MyShockProjectile';
          x = class<MyShockProjectile>(ConvertMe).Default.MyVar;

......
          
          log(x);      // returns 0.00
}

i just don't get it.
any help is appreciated.
thanks
 

Mychaeel

New Member
You're setting an instance variable and reading its default value. Setting a variable of an object naturally doesn't affect the class's defaults.

If you want to set the default value, use "Default.MyVar = 10" -- but you should really know why you want that before you do it, because it defies a whole bunch of OOP concepts.
 
Last edited:

eLy

New Member
Mar 18, 2003
169
0
0
Visit site
hehe, i know.
it's was my high-school graduation pic.
i don't have teh mustache anymore though =)
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
Well another way to do this is:

Code:
class MyShockProjectile extends ShockProjectile;

var float MyVar;

function SuperExplosion()
{
  MyVar = 10
  Spawn(class'MyShockCombo',,Self);
}

Code:
class MyShockCombo extends ShockCombo;

var class<actor> ConvertMe;

simulated event PostBeginPlay()
{
  local float x;
  x = MyShockProjectile(Owner).MyVar; // this returns the MyVar set in the object
  x = class'MyShockProjectile'.default.MyVar; // this returns the MyVar default property from class MyShockProjectile
}
 

eLy

New Member
Mar 18, 2003
169
0
0
Visit site
hmm,
when i use:
Spawn(class'MyShockCombo',,Self);
i get:
-Error call to spawn type mismatch in parameter 3


Spawn(class'MyShockCombo',Self); works though.
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
I probably got the syntax wrong. I was pretty sure at the time that the syntax for Spawn in UT2003 was function Spawn(class,name,owner,location, rotation[/i] ...) ... well that's all I can remember of the top of my head.

The Self part in Spawn is just to define who 'owns' the actor.