How to store player's life into a variable

Find detailed help from the AAO community, or write your own tutorials.

Modérateur: EN - Forum Moderators

How to store player's life into a variable 

Message par sfcpfc » Sam Oct 27, 2012 6:41 pm

How to store player's life into a variable and generate a code

In this guide, you'll learn to, as the title says, store the player life into a variable. That is very useful, you can use it for lots of purposes. Here, I will explain how to generate a "Save Code", so the player will recive a code and he can resume the game where he left it, and with his life points.


Sorry for my bad english, I'm spanish, so if you find any grammatical error, please, report it.
:gumshoe:

Example Trial

If you want to see how it's done, reply to this thread and I will add you as contributor. (But it's explained in the guide :p)

How to store the player life into a variable

Spoiler : How to store the player life into a variable :
So, let's begin. You have to create 6 frames with "1ms" of Waiting time and these actions:

-Set the game over redirection
-Define a variable's value
-Reduce player's life points
-Define a variable's value
-Reduce player's life points
-Proceed directly to another frame.

Like this:
Image

On the second frame you created (Frame nº8 in the image) you have to put this:
Image

Reduce the player's life by one point on the third and the fifth frames you created (Frames nº9 and 11 in the image)

On the fourth frame you created (Frame nº10 in the image) you have to put this:
Image
(Make sure you checked the expression box)

Then, in the last frame (Frame nº12 in the image) put the redirection to the fourth frame you created (Frame nº10 in the image).

Last thing: point the first frame's redirection (Frame nº7 in the image) to any other frame on your trial. You can create two new frames and point the redirection to the first of them, like this:
Image

I don't know why, but there's a bug: Frame nº13 in the image will skip inmediately altough there's no wait time set. So, I put the D to conceal this. I also returned the player's life in this frame. This is how it's done:
Image
(Again, make sure that you check the expression box)

You can use [#var:life] if you want to show the player his life points.

Yeah! That's all, you have the player's life points in a variable.

Tip: The generation process it's pretty slow, so you can increase the speed by putting a "10" instead of "1" in the frames nº 8, 9, 10 and 11. That will make the process 10 times faster, but make sure that your penalties are only round numbers (You can set penalties like 10 pts, 20 pts, 50 pts, etc, but no like 15 pts, 25 pts, 47 pts, etc.)

How to generate a "Save Code"

That's pretty useful if you want to create a Save System (or a password system for a trial divided in parts) so the player can save the game and recive a code. Then, when he enters the code, he can resume the game, and he'll recive the same life points as before. Why? Because the number of life points are hidden (or encrypted) in this code, so the player won't modify it.
Spoiler : First: Encrypting the code :
First, we need to create an "Encryption Key". It's a key that can encrypt and decrypt the code. You need to use the same key to encrypt and decrypt it; if you use different keys, the life points will be different.

Image

In the example trial, the encryption key is * 2 + 23092. The life points will be multiplied by 2 and increased by 23092

So, if the life points are 20, the code will be encripted thus:
life * 2 + 23092
20 * 2 + 23092
40 + 23092
23132

I recommend to multiply per 2 or 3 and add a 5 or 6 digit number. It's more secure if it's not a round number (like in the example).

So, all you have to do is creating a frame with a wait time of "1ms" and the "Define a variable's value" action. Then, check the expression box and type:
life [your encryption key]

Then, show the code by using the [#var:code] effect.

Now, you have to create the code insertion system.
Spoiler : Second: Decrypting the code :
To create the code insertion, decryption, and verification system (xD) you have to create this frame structure:

Image

In the first frame (nº19) set the action to "Ask Player for a Variable's value". The variable name is "code". The type is "Integer number", and the password mode... Turn on if you want, but I personally don't like it.

In frame nº20, put your decryption key. It's the same of your encryption key, but you have to substract instead of add, and divise instead of multiply.
Image

We have (code - 23092) / 2. Why the parenthesis? Because we want the sum to be done first. If we don't put any parenthesis, the division will be done first. Again, make sure you checked the expression box.

The code is now decrypted. But, what if the code is false? If the code is real, his value will be between 1 and 120. If the decrypted code is 150, is obvious that is false. So, we must to tell the AAO's expression engine that checks if the code is true:

Image

We can't see in the image very well, the expression is (code > 0) & (code < 121). So if the code is higher than 0 and lower than 121 (Between 1 and 120) the game will redirect to the Frame to go if success.

In frame 23, set the redirection to any frame you want, but I recommend to redirect to the "Enter code" screen. And last, in frame 25, you have to put that:

Image

With this, player life is restored. And, YEAH! We're done.

Hope you liked, thanks for reading! :)
Image
Avatar de l’utilisateur
sfcpfc
 
Message(s) : 1056
Inscription : Ven Juil 27, 2012 3:43 pm
Genre: Masculin
Langues parlées: Spanish, English and French

Re: How to store player's life into a variable 

Message par diegomr24 » Mar Jan 01, 2013 2:27 pm

Thanks.
Can you write this in the Spanish section?
For people who don´t speak English.

(Is very strange speak in English with a Spanish person).
Avatar de l’utilisateur
diegomr24
 
Message(s) : 1441
Inscription : Jeu Avr 26, 2012 8:46 pm
Genre: Masculin
Langues parlées: Español e Ingles


Retour vers Tutorials

Qui est en ligne ?

Utilisateur(s) parcourant ce forum : Aucun utilisateur inscrit et 1 invité