News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 5th Apr 2004, 07:09 AM   #1
eLy
Registered User
 
eLy's Avatar
 
Join Date: Mar. 18th, 2003
Posts: 169
blah blah blah... [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');
.....
}
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
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers)
eLy is offline   Reply With Quote
Old 5th Apr 2004, 07:50 AM   #2
Mychaeel
 
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.
Mychaeel is offline   Reply With Quote
Old 5th Apr 2004, 08:09 AM   #3
eLy
Registered User
 
eLy's Avatar
 
Join Date: Mar. 18th, 2003
Posts: 169
Hey Michaeel,

thanks a lot for the reply. it works great !
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers)
eLy is offline   Reply With Quote
Old 5th Apr 2004, 10:10 AM   #4
Zer0Zer0
Registered User
 
Join Date: Apr. 1st, 2004
Posts: 35
Your profile pic freaks me out :S
Zer0Zer0 is offline   Reply With Quote
Old 5th Apr 2004, 03:08 PM   #5
eLy
Registered User
 
eLy's Avatar
 
Join Date: Mar. 18th, 2003
Posts: 169
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)
eLy is offline   Reply With Quote
Old 5th Apr 2004, 10:16 PM   #6
[SAS]Solid Snake
Registered User
 
[SAS]Solid Snake's Avatar
 
Join Date: Jun. 7th, 2002
Location: New Zealand
Posts: 2,633
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
}
__________________
I make the impossible possible ... ... ... to some extent.

Digital Confectioners
[SAS]Solid Snake is offline   Reply With Quote
Old 6th Apr 2004, 11:34 AM   #7
eLy
Registered User
 
eLy's Avatar
 
Join Date: Mar. 18th, 2003
Posts: 169
thanks solid snake.
__________________
My UT Tribute (12min/160MB): http://eLy.ch.vu (disable popup blockers)
eLy is offline   Reply With Quote
Old 6th Apr 2004, 08:05 PM   #8
eLy
Registered User
 
eLy's Avatar
 
Join Date: Mar. 18th, 2003
Posts: 169
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)
eLy is offline   Reply With Quote
Old 6th Apr 2004, 08:25 PM   #9
[SAS]Solid Snake
Registered User
 
[SAS]Solid Snake's Avatar
 
Join Date: Jun. 7th, 2002
Location: New Zealand
Posts: 2,633
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.
__________________
I make the impossible possible ... ... ... to some extent.

Digital Confectioners
[SAS]Solid Snake is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer