Professional Documents
Culture Documents
Functions
https://roderickvella.wordpress.com
Mission Objectives
Welcome to your 6th mission. In this
mission we are going to learn how to
use functions and variable scopes
Functions
my_function()
{
return 5;
}
Functions
my_function()
{
return 5;
}
Functions
Functions
Functions
self. has to be
used to declare a
global variable.
self = an alias to
the entity that
called the script. In
this case the player
who called the
script.
}
changeValue()
{
self.global_variable = 1;
}
Step 1
startEarthQuake();
Line 140
Step 2
Step 1
playerName = self.name;
Line 148
startEarthQuake(earthQu
akeDuration)
Line 138
startEarthQuake(5);
Line 143
startEarthQuake(10);
Line 148
startEarthQuake(earthQu
akeDuration)
Line 152
Earthquake( 0.3,
earthQuakeDuration,
self.origin, 850 );
Mission 6 Task 1
Amend the previous code. The
startEarthQuake() function should now
accept 2 parameters. earthQuakeDuration
and earthQuakeScale.
Step 1
jumpHeightValue =
changeJumpSettings(1001);
Function
changeJumpSettings() is
called with an argument of 1001.
The return value that this function
returns is storred inside
jumpHeightValue
Line 137
changeJumpSettings(maxPoss
ibleJumpHeight)
Line 139
myRandomHeight =
RandomInt(maxPossibleJumpH
eight);
Variable myRandomHeight is
storing a random number
between 0 and 1000 (both
inclusive)
Line 140
self
setclientDvar("jump_height
", myRandomHeight);
return myRandomHeight;
Line 133
self iPrintlnBold("Jump
Height set to: " +
jumpHeightValue);
Step 2
Mission 6 Task 2
As you can see in Mission 6 Prog 3 video, the
player is dying on fall when the jumping height is
set too high.
Update the program so that it wont allow the
player to die when he falls back to the ground.
Hint: Use and amend the following code:
self setclientDvar("bg_fallDamageMinHeight", 1);