Sign in to follow this  
BrandonSnider

Anyone Here Know Anything About UnrealScript?

Recommended Posts

BrandonSnider    102
Hello guys.

I've only made a few posts here while I was (well, I'm still in the process of practicing) learning C++.

I have since made the jump to using the Unreal Development Kit for my game projects. So far the Syntax is very similar to C++ which is helpful; however, I'm having a little problem

Note: The reason I havn't posted to the Unreal Forums is that my account is currently not active and i am waiting in a Moderator Queue to allow me onto the forums.

So I was wondering if anyone here knows Unreal Script and would be willing to answer a question I have.


In C++ class functions and members can be accessed by the member operator '.'

This seems to not be the case with unreal script.

I'm trying to figure out how to call class member functions and access class members in Unrealscript for use with my HUD.

Anyone know how accessing other classes works in Unreal Script?

Share this post


Link to post
Share on other sites
shadowisadog    3217
[quote name='bls61793' timestamp='1310495674' post='4834430']
Hello guys.

I've only made a few posts here while I was (well, I'm still in the process of practicing) learning C++.

I have since made the jump to using the Unreal Development Kit for my game projects. So far the Syntax is very similar to C++ which is helpful; however, I'm having a little problem

Note: The reason I havn't posted to the Unreal Forums is that my account is currently not active and i am waiting in a Moderator Queue to allow me onto the forums.

So I was wondering if anyone here knows Unreal Script and would be willing to answer a question I have.


In C++ class functions and members can be accessed by the member operator '.'

This seems to not be the case with unreal script.

I'm trying to figure out how to call class member functions and access class members in Unrealscript for use with my HUD.

Anyone know how accessing other classes works in Unreal Script?
[/quote]

Have you taken a look at the Development\Src\UTGame folder? Normally one would advise not looking at source code when learning to do something, however in the circumstance where you are working in an existing engine and trying to make things work in that engine, looking at existing code in my opinion is very valuable (The same constraints they have to make to work with the Unreal engine are probably the same constraints you will have).

Also the '.' operator is used in that manner in Unreal Script.

For instance from UTPlayerController, line 837 (roughly):

[code]
reliable server function ServerProcessSpeechRecognition(SpeechRecognizedWord ReplicatedWords[3])
{
local array<SpeechRecognizedWord> Words;
local int i;
local UTGame Game;

Game = UTGame(WorldInfo.Game);
if (Game != None)
{
for (i = 0; i < 3; i++)
{
if (ReplicatedWords[i].WordText != "")
{
Words[Words.length] = ReplicatedWords[i];
}
}

Game.ProcessSpeechRecognition(self, Words);
}
}
[/code]

Main thing to note is that variables (in this case local variables) must be declared and initialized on two separate lines (as far as I know). Also you need to typecast to the appropriate type containing your methods. such as convertedInstance = MyClass(instanceToConvert) ect. Here we see Game = UTGame(WorldInfo.Game) .

Share this post


Link to post
Share on other sites
BrandonSnider    102
[quote name='shadowisadog' timestamp='1310496411' post='4834440']
[quote name='bls61793' timestamp='1310495674' post='4834430']
Hello guys.

I've only made a few posts here while I was (well, I'm still in the process of practicing) learning C++.

I have since made the jump to using the Unreal Development Kit for my game projects. So far the Syntax is very similar to C++ which is helpful; however, I'm having a little problem

Note: The reason I havn't posted to the Unreal Forums is that my account is currently not active and i am waiting in a Moderator Queue to allow me onto the forums.

So I was wondering if anyone here knows Unreal Script and would be willing to answer a question I have.


In C++ class functions and members can be accessed by the member operator '.'

This seems to not be the case with unreal script.

I'm trying to figure out how to call class member functions and access class members in Unrealscript for use with my HUD.

Anyone know how accessing other classes works in Unreal Script?
[/quote]

Have you taken a look at the Development\Src\UTGame folder? Normally one would advise not looking at source code when learning to do something, however in the circumstance where you are working in an existing engine and trying to make things work in that engine, looking at existing code in my opinion is very valuable (The same constraints they have to make to work with the Unreal engine are probably the same constraints you will have).

Also the '.' operator is used in that manner in Unreal Script.

For instance from UTPlayerController, line 837 (roughly):

[code]
reliable server function ServerProcessSpeechRecognition(SpeechRecognizedWord ReplicatedWords[3])
{
local array<SpeechRecognizedWord> Words;
local int i;
local UTGame Game;

Game = UTGame(WorldInfo.Game);
if (Game != None)
{
for (i = 0; i < 3; i++)
{
if (ReplicatedWords[i].WordText != "")
{
Words[Words.length] = ReplicatedWords[i];
}
}

Game.ProcessSpeechRecognition(self, Words);
}
}
[/code]

Main thing to note is that variables (in this case local variables) must be declared and initialized on two separate lines (as far as I know). Also you need to typecast to the appropriate type containing your methods. such as convertedInstance = MyClass(instanceToConvert) ect. Here we see Game = UTGame(WorldInfo.Game) .
[/quote]


Well I have seen many people typecasting variables from other classes but I'm not exactly sure how it works.

Basically speaking, why can't (using my example)
[code]
TestGamePawn.getwaterlevel();[/code]

why would this not call the function 'getwaterlevel()' from the TestGamePawn class?

EDIT: Comparing it to C++ shouldn't it work like this:

[code]
//Class Declaration
class TestGamePawn
{
int charwaterlevel;
Public:

int getwaterlevel()
{
return charwaterlevel;
}

}

//Main
int main()
{
int i;
//Calling the class function via member operator.
i =TestGamePawn.getwaterlevel();
}
[/code]

Share this post


Link to post
Share on other sites
gsamour    140
Your sample C++ code is wrong... you call functions from instances of Classes...

so something like

TestGamePawn pawn;
pawn.getwaterlevel();

you could also do:

TestGamePawn* pPawn = new TestGamePawn();
pPawn->getwaterlevel();

OR you make the function "static" and in that case you would use:


TestGamePawn::getwaterlevel() instead of TestGamePawn.getwaterlevel()



EDIT: corrected wording about static function

Share this post


Link to post
Share on other sites
gsamour    140
The same principle applies to UnrealScript...

notice how inside the function it does this:

[color="#1C2837"][size="2"][color="#000088"][color="#000088"]local[/color][/color][color="#000000"] [/color][color="#660066"][color="#660066"]UTGame[/color][/color][color="#000000"] [/color][color="#660066"][color="#660066"]Game[/color][/color][color="#666600"][color="#666600"];[/color][/color][/size][/color]


it's declaring an instance of the UTGame class... and it calls functions using the Game variable. It doesn't call functions using the UTGame class.


EDIT: correction...

[size="2"][color="#000088"][color=#000000][size=3]
[color=#1C2837][size=2][color="#000088"][color="#000088"]local[/color][/color][color="#000000"] [/color][color="#660066"][color="#660066"]UTGame[/color][/color][color="#000000"] [/color][color="#660066"][color="#660066"]Game[/color][/color][color="#666600"][color="#666600"];[/color][/color][/size][/color]
[color=#1C2837][size=2][color="#666600"][color="#666600"][color=#1C2837][size=2][color=#660066]Game[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#660066]UTGame[/color][color=#666600]([/color][color=#660066]WorldInfo[/color][color=#666600].[/color][color=#660066]Game[/color][color=#666600]);[/color][/size][/color][/color][/color][/size][/color][/size][/color][/color][/size]
[size="2"][color="#000088"]
[/color][/size]
[size="2"][color="#000088"][color=#000000][size=3]the first line declares a pointer or reference variable to a UTGame class... it doesn't hold a true instance yet... the second line tells it which instance to use.[/size][/color][/color][/size]

Share this post


Link to post
Share on other sites
wildpins    40
Unreal Script is more related to Java coding styles than C++. It says so, and is also provable when you actually learn Java. Now that doesn't mean you won't get confused because it is not Java, but you should be able to pick up the difference.

Wiki Description

[url="http://en.wikipedia.org/wiki/UnrealScript"]http://en.wikipedia....ki/UnrealScript[/url]

Gears of War War Weapon.u

[url="http://pastebin.com/hD6F35Wt"]http://pastebin.com/hD6F35Wt[/url]

Any real questions can be asked on the Unreal Forums Here [url="http://forums.epicgames.com/forumdisplay.php?f=366"]http://forums.epicga...splay.php?f=366[/url]

You will never call native unless you own a license to the Unreal Engine 3. So you don't need to worry about that until later.


Also, to help you out, you can search for unreal tournament 3 mods and mutators and look at their sources to figure out how they did something.

Like people who are successful say "Don't try to reinvent the wheel".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this