Saturday, March 31, 2012

Unreal Development Kit–Chapter 2– Book Note

In previous Article:Unreal Development Kit–Basic 1– Book Note

Now that's beging:Chapter 2

In Chapter 2 , some are basic knowledge about programming,something

like how to declare variable, int ,float,arry..., it vary basic so i skip it,

but some are different from other language.therefor i write something that i think it is important.

Enum:

enum ObjectState
{
Hit,
Idle,
Attack
};
var ObjectState currentState;
function PostBeginPlay()
{
currentState = ObjectState.Idle;
}



 


Dynamic Array:


As like other language,it start from 0 ,And how do i declare it:

var array<int> firstArray;

function PostBeginPlay()
{
firstArray[3]=9;

`log(firstArray[3])
// The result is '9'
`log(firstArray[firstArray.length]);
// The resule of length is '4'
}

 


In C# ,yout can use Array.Copy,but How do i copy an array in unreal

Class AlexGame extends Actor
placeable;

var int TestArray[3];
var array<int>CopyArray;
var int i;

function PostBeginPlay()
{
`log("As usually Hello Epic");
TestArray[0]=1;
TestArray[1]=2;

CopyArray[CopyArray.length] = TestArray[CopyArray.length-1];
CopyArray[CopyArray.length] = TestArray[CopyArray.length-1];
for( i = 0; i < CopyArray.length;i++)
{
`log("COPY ARRAY" @ CopyArray[i]);
}
}

 


And i found a problem that if i use

for( var int i = 0; i < CopyArray.length;i++)
{
`log("COPY ARRAY" @ CopyArray[i]);
}

 


my udk will crash,so i declare it at global variable.And work Success.i dont know what’s the problem.if some one know the reason.Maybe you can tell me.


Struct

struct SmallBox
{
var int Chocolates;
var int Cookies;
};

struct Treasure
{
var SmallBox tinyBox;
var string treasureName;
};
var Treasure theTreasure;

function PostBeginPlay()
{
theTreasure.tresureName = "Candy Box";
theTreasure.tinyBox.Chocolates=2;
}

 


And defaultproperties can do what:


You can set Initialize value at defaultProperties

var int defaultValue;

defaultproperties
{
defaultValue=100;
}

 


How do i modify a value at Editor,In Unity3D,we can declare variable in public.


In Unreal we can

var() int EditableInt;

image


and operator,arithmetic, comparisons,flow control,if/else,swich…than i skip it.


Remerber Script have Goto, as usually,we should not use it.


Vector


SetLocation is a unreal API we can use it to set object’s position.


Location is Actor position.it already declare by system.

function PostBeginPlay()
{
//Vect(X,Y,Z);
SetLocation(Location + vect(0,0,64));
}

 


Because i use it in  PostBeginPlay method so it will happen when you calling the script.


it also provide how to  calculate distane between two Vector and calculate distance from the world origin.


Distance from the world origin to object position

var int Distance;

function PostBeginPlay()
{
Distance = VSize(Location);
}


 


two object’s distance

function PostBeginPlay()
{
Distance = VSize(Vector1 - vector2);
}

 


Rotation


Rotation is Actor Rotation.it already declare by system.

function PostBeginPlay()
{
//rot(Pitch,Yaw,Roll)
//360 degree = 65535, 90degree= 16384
SetRotation(Rotation + rot(0,0,4000));
}

here is my script:https://skydrive.live.com/redir.aspx?cid=f5d92c03d299f24f&resid=F5D92C03D299F24F!143&parid=F5D92C03D299F24F!117&authkey=!ADf95ErMIcayrTc


And Chapter 2 is done.

No comments:

Post a Comment