Scripts

4 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.38
List Price:  €64.93
You save:  €18.55
£39.89
List Price:  £55.85
You save:  £15.96
CA$68.39
List Price:  CA$95.75
You save:  CA$27.36
A$75.62
List Price:  A$105.88
You save:  A$30.25
S$67.65
List Price:  S$94.72
You save:  S$27.06
HK$390.63
List Price:  HK$546.91
You save:  HK$156.28
CHF 45.32
List Price:  CHF 63.46
You save:  CHF 18.13
NOK kr540.83
List Price:  NOK kr757.20
You save:  NOK kr216.37
DKK kr346.01
List Price:  DKK kr484.44
You save:  DKK kr138.43
NZ$83.08
List Price:  NZ$116.32
You save:  NZ$33.23
د.إ183.61
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,489.47
List Price:  ৳7,685.71
You save:  ৳2,196.23
₹4,174.70
List Price:  ₹5,844.92
You save:  ₹1,670.21
RM236.90
List Price:  RM331.68
You save:  RM94.78
₦70,962.30
List Price:  ₦99,352.90
You save:  ₦28,390.60
₨13,872.15
List Price:  ₨19,422.12
You save:  ₨5,549.97
฿1,835.14
List Price:  ฿2,569.35
You save:  ฿734.20
₺1,612.71
List Price:  ₺2,257.93
You save:  ₺645.21
B$257.06
List Price:  B$359.91
You save:  B$102.84
R919.21
List Price:  R1,286.96
You save:  R367.75
Лв90.71
List Price:  Лв127.01
You save:  Лв36.29
₩68,279.30
List Price:  ₩95,596.49
You save:  ₩27,317.18
₪186.20
List Price:  ₪260.69
You save:  ₪74.49
₱2,872.25
List Price:  ₱4,021.38
You save:  ₱1,149.12
¥7,785.79
List Price:  ¥10,900.73
You save:  ¥3,114.94
MX$837.71
List Price:  MX$1,172.87
You save:  MX$335.15
QR181.98
List Price:  QR254.79
You save:  QR72.81
P681.01
List Price:  P953.47
You save:  P272.46
KSh6,621.46
List Price:  KSh9,270.57
You save:  KSh2,649.11
E£2,369.41
List Price:  E£3,317.36
You save:  E£947.95
ብር2,858.54
List Price:  ብር4,002.19
You save:  ብር1,143.64
Kz41,809.30
List Price:  Kz58,536.37
You save:  Kz16,727.06
CLP$46,240.75
List Price:  CLP$64,740.75
You save:  CLP$18,500
CN¥361.16
List Price:  CN¥505.65
You save:  CN¥144.49
RD$2,895.12
List Price:  RD$4,053.41
You save:  RD$1,158.28
DA6,726.94
List Price:  DA9,418.25
You save:  DA2,691.31
FJ$113.51
List Price:  FJ$158.92
You save:  FJ$45.41
Q388.49
List Price:  Q543.91
You save:  Q155.42
GY$10,421.54
List Price:  GY$14,591
You save:  GY$4,169.45
ISK kr6,972.10
List Price:  ISK kr9,761.50
You save:  ISK kr2,789.40
DH500.60
List Price:  DH700.89
You save:  DH200.28
L887.29
List Price:  L1,242.28
You save:  L354.98
ден2,857.41
List Price:  ден4,000.60
You save:  ден1,143.19
MOP$400.79
List Price:  MOP$561.14
You save:  MOP$160.35
N$921.79
List Price:  N$1,290.58
You save:  N$368.79
C$1,832.69
List Price:  C$2,565.92
You save:  C$733.22
रु6,654.99
List Price:  रु9,317.52
You save:  रु2,662.52
S/185.34
List Price:  S/259.50
You save:  S/74.15
K193.05
List Price:  K270.29
You save:  K77.23
SAR187.48
List Price:  SAR262.49
You save:  SAR75.01
ZK1,362.81
List Price:  ZK1,908.05
You save:  ZK545.23
L230.78
List Price:  L323.12
You save:  L92.33
Kč1,156.66
List Price:  Kč1,619.42
You save:  Kč462.75
Ft17,987.75
List Price:  Ft25,184.29
You save:  Ft7,196.54
SEK kr541.71
List Price:  SEK kr758.43
You save:  SEK kr216.72
ARS$44,114.95
List Price:  ARS$61,764.46
You save:  ARS$17,649.51
Bs345.50
List Price:  Bs483.72
You save:  Bs138.22
COP$194,137.21
List Price:  COP$271,807.63
You save:  COP$77,670.42
₡25,482.48
List Price:  ₡35,677.52
You save:  ₡10,195.03
L1,227.34
List Price:  L1,718.38
You save:  L491.03
₲374,060
List Price:  ₲523,713.94
You save:  ₲149,653.93
$U1,921.90
List Price:  $U2,690.81
You save:  $U768.91
zł199.36
List Price:  zł279.12
You save:  zł79.76
Already have an account? Log In

Transcript

Here for implementing score indicators, we need to use something called scripts. So in this lecture, we'll be learning what scripts are and how they work. A script is like a custom event where you can put your actions, and then you can run that script execute all the actions inside it. This is best demonstrated with an actual example. So I'll open Game Maker with a new project. I have two objects here with their own sprites, I placed them in the room.

They're just empty objects with no actions or events. Now I want to make it so that when I click on an instance, it gets bigger. So for that, I can use the set instance scale action. And I'm going to do that for both of these objects. So that's an easy problem to solve. I can add that action in both of these objects in the appropriate event.

But what if I want to change what happens when you click on these objects? Then I have to go in and change both of these objects one by one. And it's not a big deal if I have only two objects to modify, but What if I have 10 different objects that have to run basically the same actions. In that case, it'll be too tedious to modify all of them one by one. So we need a way to control all of these similar actions in one place. And this is where scripts come in.

As I said previously, you can create a script, put actions inside it and run that script. And if you want, then you can have multiple objects running the same actions. So you can easily make any changes to those actions without having to modify all of those objects one by one. So I'll go to scripts and create one. I'll name it change size. So this is our script right here, it looks the same as a regular event.

You can add your actions from here, so also at scale and add the circumstance correction. Using this action, you can change the horizontal and vertical scale of the instance. I want to increase the scale when the script is run. So I'll take relative for both horizontal and vertical. Now here we need to write a value that will be added to the scale. So for example, I can write 0.1 here so the scale will go By 0.1, but instead of a value Alright, argument zero in both of these fields, an argument is a value that is specified when you run a script.

Argument zero is the first argument. So whatever value is specified in the first argument will be used here. So now we can run the script with an argument in any object. So I'll open the first object. Here we'll add the mouse left pressed event. This controls when you click on the instance.

So in the actions also script and add the execute script action. Using this action, you can run a script and specify an argument value. So for the script as larger in size and in the argument 0.1. So this value will be used in the script to increase the scale of the instance. Now we'll open the second object and add the same event and action here. And now we'll run the game.

I can click on the instances and your scale goes up. So the script is working. Now, because of this argument, the scale of this object goes up by 0.1. So we'll change it to 0.4. And run the game again, I click on the instances, now you can see that the second object gets bigger faster than the first object. This happens because this object scale goes up by 0.4.

While the first socket scale goes up by 0.1. This is why scripts are so useful. You can run the same actions in multiple places, but make them work differently based on the argument values. And now you can also expand the script by adding more actions. So let's make the instances fade away when you click on them. In the actions all search alpha, I'll add the circumstance alpha action.

This is the opacity or transparency of the instance. I'll take relative since I want to modify its value, and in the value all type argument one. So this is the second argument. Now I'll open the first object. In the script action, I click on the plus sign. This allows you to specify another argument for the script, which in our case will be added to the alpha.

So to use the alpha and enter minus 0.1. Now I'll open the second object and do the same. And now around the game. Now, when I click on an instance, its alpha also goes down. So that's how scripts basically work. They can be used in many ways, and they just make life easier.

So now let's move on to the next lecture. We will work on score indicators

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.