UE3 - UT3 Some quick questions on Unreal Script...

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

inferyes

Spaced In
Aug 16, 2009
504
0
0
My first (and only) scripting language is something called "HSC" that's based of of Lisp. I'm trying to learn Unreal Script now but I'm completely at a loss as to how it works. If you guys could translate some functions from Lisp to Uscript it would really help me understand how things are structured in Uscript.


// How do I create a command that continually checks a variable and then changes a value based on that.

(script continuous "checkfunction"
(if ( > var_short 4) //checks to see if this short is greater than 4
(begin (set var_boolean true) ) //if it's greater than 4 it sets this boolean true
(begin (set var_boolean false) ) //if it's less than 4 it sets that boolean false
)
(sleep 1) //after the check is complete the script sleeps for 1 game tick {1/30th of a second} and then starts over.
)

// How do I write commands that sleep until a certain amount of time has passed of a event occurs?

(script startup "waitfor"
(sleep_until (volume_test_objects "trig_volume" (players) ) ) //script stops and sleeps until a player to enter the trigger volume. then after a player has entered the volume it continues.
(object_create "blahblahblah") //creates a object afterwords
)

Additionally, can someone link me a tutorial on adding a key that when pressed(and held) sets a boolean true and when unpressed sets a boolean false? I've looked through a bunch of stuff on the UDN but none of it has helped me much.

Thanks.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
The programming paradigms UnrealScript uses are: imperative, object-oriented and event-driven. That's fundamentally different from LISP, which is a functional language.

Except for state code, UnrealScript code cannot (and must not) intentionally create delays. Instead, a timer must be set up that will call another function after the specified time has passed.

The closest thing to your first code above would be:
Code:
function checkfunction()
{
  if (var_short > 4)
    var_boolean = true;
  else
    var_boolean = false;
  // this is a function, but in state code you could use: Sleep(1);
}

Your second piece of code is an example of event-driven programming. Usually this would be scripted in Kismet with a Touch event node instead, but at the UnrealScript level you need a special class for the "trig_volume" object, where you override the Touch event function:
Code:
function Touch(Actor Other)
{
  // your code here.
}
Creating objects depends on the type of object to create. If it extends the Actor class, it is "spawned" in the level via the Spawn function, otherwise it is created with the New operator.

I recommend browsing UnrealWiki: UnrealScript and related articles to learn the language. Download the UT3 UnrealScript sources and browse the various classes, preferably using a tool such as UnCodeX.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Alright. So how do I make a function that runs every game tick? I don't really understand how timers work.

And also how do you make a function run when a button is pushed. Like how would I make it so when ever someone clicks RMB it does a loginternal?
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
I've written my first mutator but the way I have it set up it runs 1 time at start and changes a couple of values in the UTPawn class.

Which mutator should I look at for looping and continuous scripts?


edit-

Also I was wondering. In older game engines I've worked with, scripts are locked to run every tick and ticks are locked to 30 ticks a second. So scripts run 30 times a second unless you specify them to run a different rate. Is unreal locked to run a specific tick rate or does it run faster depending one the hardware you use?
 
Last edited:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
Sorry can't go into specifics as I'm not familiar with UE3. What you need is a Timer (activated according to a duration defined by the programmer), either inside a Mutator or a custom-made Actor. Either that or use the Tick() probe function for finer timing if it's still available.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
:D

I figured out the Set Timer command and I got a loop working. But I have a question about it. What does the Bool do in SetTimer(<time>,<bool>,<func>)? And also can I do SetTimer(tick(1),<bool>,<func>) to make it run every tick?

edit-
I looked up key binding and input but It's not really explained at all. I'm simply trying to bind a key and once I've got that working I want to find a way to check when the key is pressed. Once I've gotten those 2 things figured out I can write this mutator I want to do. I've got all the math figured out for it.

exec function SetBind(Z,am_sprint);
{
loginternal("key is bound!");
}
 
Last edited:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
What does the Bool do in SetTimer(<time>,<bool>,<func>)?

This is the doc from the UDK:
Code:
/**
* Sets a timer to call the given function at a set
* interval. Defaults to calling the 'Timer' event if
* no function is specified. If InRate is set to
* 0.f it will effectively disable the previous timer.
*
* NOTE: Functions with parameters are not supported!
*
* @param InRate the amount of time to pass between firing
* @param inbLoop whether to keep firing or only fire once
* @param inTimerFunc the name of the function to call when the timer fires
*/
native(280) final function SetTimer(float InRate, optional bool inbLoop, optional Name inTimerFunc='Timer', optional Object inObj);

And also can I do SetTimer(tick(1),<bool>,<func>) to make it run every tick?

The Timer actually calls Tick(). It's probable that the timer will have trouble firing reliably below a certain number of ticks due to the way engine ressources are handled. Note that the span of time between each tick is very short (see below) so it's best to only use it in special cases.

The following post has an example of a class that uses Tick():
http://www.ubertastic.com/index.php?topic=2789.0

From the original uscript guide:
http://chimeric.beyondunreal.com/tutorials/beginners_guide1.html
The Tick() function is called every game tick, generally as much as possible, so use it to perform actions continously or check for certain conditions. NOTE: Be careful not to put too much code into a Tick() function because it is very easy to overload the game and cause noticeable lag if too much is going on. Use the Destroy() function to destroy this instance of the class when you no longer want it to be in play.

http://www.pages.drexel.edu/~pjd37/Gaming_Overview/GamingOverview_6.ppt
Most engines use Ticks
smallest unit of time in which all actors in a level are updated. A tick typically takes between 1/100th to 1/10th of a second.
limited only by CPU power; the faster machine, the lower the tick duration is.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Alright. So I should probably lock my script to update between 20 and 30 times a second and not every tick.

This still doesn't solve my problem with input though. How would I check to see when the player pushes the jump key?
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
Note sure. The trick that was often used in UT1 was to give a player a custom Inventory item and intercept commands that way.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Alright so I finished my first mutator. I just need to change the name and description in the Menus. If I'm correct you do this through a ini file (just like with custom maps) but I don't know what the setup for a mutator ini file is. Can somone give me a link to a example?
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
The compiler should have generated "UTYourPackageName.ini" in the MyDocs\MyGames\UT3\UTGame\Config folder with an entry for your mutator. Technically that's a standard "PerObjectConfig" section, so you can look up all possible settings in the UTUIDataProvider_Mutator class.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Yeah I extend UTMutator and then I have a second class that modifys the UTPawn.

Code:
class UTMutator_Gaylo extends UTMutator;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	WorldInfo.Game.DefaultPawnClass = class'Gaylo3Mutator.UTPawn_Gaylo';

}

defaultproperties
{
	GroupNames[0] = "PLAYERMOD"
}

Code:
class UTPawn_Gaylo extends UTPawn;

var Int RegenPerSecond;
var Int GayloMaxHealth;
var Int GayloMaxShield;
var int StuntedRegenTime;
var int StuntedRechargeTime;
var int RechargePerSecond;
var int BigFatZero;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	SetTimer(0.2,true);
}

function Timer()
{
	HealthMax=GayloMaxHealth;
	SuperHealthMax=GayloMaxHealth;
	VestArmor=BigFatZero;
	ThighpadArmor=BigFatZero;
	HelmetArmor=BigFatZero;

	if (!IsInPain() && WorldInfo.TimeSeconds - LastPainSound >= StuntedRegenTime && Health < HealthMax )
	{
		Health = Min( Health + RegenPerSecond, HealthMax );
	}
	if (!IsInPain() && WorldInfo.TimeSeconds - LastPainSound >= StuntedRechargeTime && ShieldBeltArmor < GayloMaxHealth)
	{   
		ShieldBeltArmor = Min( ShieldBeltArmor + RechargePerSecond, GayloMaxHealth);
	}
	if (Health > HealthMax)
	{
		loginternal("I have to much health! Please fix this!");
		Health=GayloMaxHealth;
	}
	if (ShieldBeltArmor > GayloMaxHealth)
	{
		loginternal("I have to much armor! Please fix this!");
		ShieldBeltArmor=GayloMaxHealth;
	}
}

defaultproperties
{
	RegenPerSecond=1;
	RechargePerSecond=1;
	GayloMaxHealth=75;
	StuntedRegenTime=8;
	StuntedRechargeTime=4;
	BigFatZero=0;
}
 
Last edited: