Class declaration

  • 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.

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
Sorry about asking so stupid question, but I didn't found any answer yet :

I want to declare in the class "A" a reference to an object of class "B"
and in the same time
declare in the class "B" a reference to an object of class "A"

My problem is basicely I don't know how compile such a thing, because I need something like #include in C++ ( #include A.h )
or juste a declaration of class in java ( class A; )

( I'm using UT2004 engine )
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
Objects exist differently in the Unreal engine vs the other classes. You have scripts and then instances of those scripts.

For example if there are 3 rockets in the game, each rocket is running its own instance of the rocket script all at once, not a singular instance of the rocket script.

Thus in UT2004 it is neccessary to maintain a check list of the objects in the game if you wish to do stuff with them. There are lots and lots of said examples in UT2004 scripts.

Something like this to look for,

Code:
A = Spawn(..); // This sets A as the new spawned object, A will be none of the spawn fails
A.Function(); // Run a function from the instance ofA

I think that is what your meaning.
 

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
yes I know it, but it isn't the problem

I'm sorry it's quite hard to explain :

Code:
class A extends Actor;

var  B  myBreference;

function Open ()
{
myBreference = Spawn(B);
.....
B.function();   // no problem for this

B.Open(self);
}


class B extends Actor; 

var  A  myAreference;   // here is the problem

function Open (A      AOwner)
{
myAreference = A;
.....
A.function();   

}


so if I compile the A class first the compilation of B doesn't work.
But if I compile the class B first the compilation of class A doesn't work.

That's why I need something like #include in C++
 

Angel_Mapper

Goooooooats
Jun 17, 2001
3,532
3
38
Cape Suzette
www.angelmapper.com
[edit] Oh, I know what you're getting at. The line would be:

Code:
class A extends Actor;

var  B  myBreference;

function Open ()
{
myBreference = Spawn(B);
.....
B.function();   // no problem for this

B.Open(self);
}


class B extends Actor; 

[b][u]#exec obj load file=WhateverPackageAIsIn.u[/u][/b]

var  A  myAreference;   // here is the problem

function Open (A      AOwner)
{
myAreference = A;
.....
A.function();   

}

Why aren't they in the same package btw?
 
Last edited:

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
Yes I agree with you, both of our codes must work well at execution.

but my problem is how can i do for the compiling :
ucc error :
"Unrecognized type 'B' " (if i compile class A first)

"Unrecognized type 'A' " (if i compile class B first)


I try the keyword "DependsOn" :

Code:
class B extends Actor
           DependsOn(A);

var  A  myAreference;   // here is the problem

function Open ()
{
    A.function();   
}

but dependsOn is just changing which classe to compile first so it doesn't work. (and the ucc error message is "General protection fault !")
 

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
You're right ! But I don't understand

just say our class "A" is in the AClasses package
and our class "B" is in the BClasses package

if I need the AClasses.u to compile class "B" (and also to create the BClasses.u)
and if I need the BClasses.u to compile class "A" (and also create the AClasses.u) :eek:

for the moment I have nor AClasses.u neither BClasses.u,
what can I do ?
 

RegularX

Master of Dagoth Lies
Feb 2, 2000
1,215
0
0
Chicago, IL
In UnrealScript, I think you have to put them in the same package to solve that. UnrealScript isn't like Java or C++ compiling, it can only follow a very strict order.
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
I think you have to put them in the same package to solve that.
You don't have to do that, but it makes life easier if you do.

Oooh so that is what your doing. You can't make a reference to somethin that doesn't exist first. So what you have to do here is go down a level in terms of reference. Most third party classes are actor based, so use actor as your common denominator.

Second, you obviously can't spawn a class which the compiler doesn't exists yet. However you can use the DynamicLoadObject to find the class at runtime from a string value (string looks like 'Package.Class'). The DynamicLoadObject will 'find' the class your looking for at runtime. You can then spawn from there. There are a few examples of this in the original UT2004 code base. Try Invasion .. from memory they have it.

So, if I am correct try something like this:

Code:
class A extends Actor;

var Actor B;

function PostBeginPlay()
{
  local class<Actor> AClass;

  Super.PostBeginPlay();
  AClass = DynamicLoadObject([i]Syntax[/i]);

  if(AClass != None)
    B = Spawn(AClass);

  if(B != None)
    B.SetOwner(Self);
}
 
Last edited:

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
ok, you're right I don't want to put them in the same package.

but if I use the DLO like this :

Code:
class A extends Actor;

var Actor B;

function PostBeginPlay()
{
  local class<Actor> AClass;

  Super.PostBeginPlay();
  AClass = DynamicLoadObject(Syntax);

  if(AClass != None)
    B = Spawn(AClass);

  if(B != None)
    B.SetOwner(Self);
}


I need to convert my B variable into a A type, like this :
Code:
A(B).DoSomethingFromClassA();
but when I use ucc the compilation will tell me A is undefined
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
Hmm, your right ... that thought didn't occur to me.

Well you can get one way traffic from class B (it belongs in the package after class A), since class B can freely type cast to class A with no problems. I don't think there is a way to type cast from class A to B.

One suggestion is to use comon functions that exist between Actor for example. But that isn't a very good thing to do.

Hmm, unfortunately, in this case I think I agree with RegularX right now in that you may have to put them in the same package. Or derive class B from class A.
 
Last edited:

Bonehed316

New Member
Oct 15, 2001
208
0
0
41
Florida
Visit site
Well, first, you cant have a reference to classB from AClasses package. No worky there. You cant even type cast to ClassB that way, since that too requires a class reference to work. Even being in the same package might not work, since classA cant be compiled without classB, and classB cant be compiled without classA. You would have to be able to compile them both at once (definately in the same package), and hope the compile forgives (defers?) the reference to classA inside classB (since classA isnt compiled if classA depends on classB, classB gets compiled first, but has a reference to classA, which is not compiled because classA depends on classB).

Has anyones head exploded yet?

The point is, you might need a more forgiving compiler (ucc is very strict, and only 2 passes I think) to be able to do this without extending one from another (like Inventory and Actor - Inventory is an Actor, and Actor has a reference to Inventory). But given that Inventory and Actor works, classA and classB might work if they're both in the AClasses package.
 

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
Thank you so much for these answers it's really cool.

Actually it's working well when I put the both classes in the same package.

But I don't want (I can't) put them in the same package :(
( neither classA can't depend on classB )

I don't know much about UCC compiler but I expect it to have precompilation, compilation and link ?
 

Bonehed316

New Member
Oct 15, 2001
208
0
0
41
Florida
Visit site
Can you make a base class for classB? Like just a blank class with function stubs to let the compiler know those functions/variables exist, then have classB extend classBBase in BClasses package? Then have the classB variable in classA be a classBBase? You cant spawn a classB from classA, but you can DLO one and call the functions in classBBase which will actually run the version in classB, if the object is actually a classB (which you can do with DLO). Or you can spawn classB first, and then have classB spawn classA and classB set the classBBase variable inside of classA object to itself, giving classA the reference it needs.
 

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
I'm sorry I'm not a native english speaker so it's a bit hard to understand :)

here is the uml diagram of what I understood

and I actually already have a "Bbase" class but I don't know how it changes the way to compile it
 

Attachments

  • UML copy.jpg
    UML copy.jpg
    19.8 KB · Views: 12
Last edited:

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
ok thanks, I want to keep them in different package just for the cleanliness of the project.
And to have a BBase in the AClasses package isn't very clean either.

It's just amazing unreal script can't do something like this.
I hope there may be a way of doing it using a batch file ??

here is the uml diagram of what I wanted to do :
 

Attachments

  • Uml.jpg
    Uml.jpg
    43.3 KB · Views: 18
Last edited:

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
If you really don't want to put them in the same package then use a base class which is what BoneHed and myself suggested. Then you stub functions which you can alter in the later too clases without the need to typecast at all.

I see no reason as to why you cannot do that.
 

Mucho

Cyber User
Mar 25, 2005
33
0
0
41
Honolulu
thank you very much for those answer, and I you do another architecture which is the easiest way of doing it.

Thanks :D