![]() |
|
|
#1 |
[UT2K4]Accessing variables from other classes
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');
.....
}
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
}
any help is appreciated. thanks
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers) |
|
|
|
|
|
|
#2 |
|
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
|
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 by Mychaeel; 5th Apr 2004 at 07:51 AM. |
|
|
|
|
|
#3 |
|
Hey Michaeel,
thanks a lot for the reply. it works great !
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers) |
|
|
|
|
|
|
#4 |
|
Registered User
Join Date: Apr. 1st, 2004
Posts: 35
|
Your profile pic freaks me out :S
|
|
|
|
|
|
#5 |
|
hehe, i know.
it's was my high-school graduation pic. i don't have teh mustache anymore though =)
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers) |
|
|
|
|
|
|
#6 |
|
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
}
|
|
|
|
|
|
|
#7 |
|
thanks solid snake.
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers) |
|
|
|
|
|
|
#8 |
|
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.
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers) |
|
|
|
|
|
|
#9 |
|
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. |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|