Platform Builder Forums
Help and Support => Tutorials => Topic started by: TingThing on October 07, 2018, 10:55:07 PM
-
For those of you who have learned how to use commands and conditionals, you may wonder what possibilities are out there for custom variables. Here are a few things that custom variables can do for you.
Custom variables store numbers which can be checked later. This can be useful for a number of different things. Basically, it's like your own personal save storage for Platform Builder.
For instance, maybe you have a special coin and a special heart. You want to tell the player what these items do the first three times you collect them in a game. After that, the player should remember what they do and you don't need to remind the player anymore. You could do something like this:
In the startup command prompt of the title screen:
game var myCoins = 0
game var myHearts = 0
[size=78%]For your coin:[/size]
money + 10
if myCoins < 3
{
+You found a golden coin! This is worth $10.
myCoins += 1
}
For your heart:
health + 3
if myHearts < 3
{
+You found a golden heart! This restores your health by three.
myHearts + 1
}
[/size]Another example would be if you have a mini obstacle course in one of your levels, and you only want to give the player one attempt to complete the obstacle course whenever you enter the level.[size=78%]
if course var obstacle course = 0
{
// Start the obstacle course
obstacle course = 1
}
else
+You have already tried the obstacle course. Try again later!
Here is another example. What if you had a custom enemy, and you wanted that enemy to kill itself the third time that it landed on the ground after jumping? Well, you will need to create a variable which records how many times the enemy lands on the ground. This will need to be a local variable because you might have multiple enemies of the same kind that all jump at different moments.
In the "create" command prompt of your custom enemy
local var times landed = 0
In the "land" command prompt of your custom enemy
times landed += 1
if times landed = 3
kill enemy
Feel free to comment your own ideas for others to see :)
-
What do the two // mean?
-
Oh, it's a note.
-
Oh, it's a note.
Yeah. It's actually not necessary in the Command Prompt, since anything unrecognized by the CP is just skipped anyway. But I still do it so that I can see the line is meant to be a note.
-
Very well explained, thank to this post, people will understand variables better.
-
How do game variables work?
I still have some doubts:
They reset when the player dies?
You can add a value to them in death command prompt?
I need answers...
-
Hmm... I wish I knew... I never have programmed. So, I can't tell you.
-
Game variables are variables that never reset. They stay the same for the entire game. They do not reset when the player dies. You can change them in the death command prompt.
There is/was an error saving game variables. I forgot if that has already been fixed, or if it is one of the bugs that is getting fixed in the next update.
-
It still needs to be fixed, also, it has some bugs with savegames when you change the game. For example, In my game, I did an attempt counter, but if you resume when you have the counter, but the game was saved when no, strangely some variables fail. I don't know how to explain it.
-
By the way, I realized another thing variables can be used for! Another thing we can use variables for is for game progression. If you wanted to make a game like Mario Galaxy, or Sunshine without creating new areas, you can always spawn items and blocks and stuff to make the game progress without duplicating areas as much. Like in sunshine, pintas keep on appearing in different places, and saying different things. And the area changed some as well. So, we can do stuff like that with variables.
-
By the way, I realized another thing variables can be used for! Another thing we can use variables for is for game progression. If you wanted to make a game like Mario Galaxy, or Sunshine without creating new areas, you can always spawn items and blocks and stuff to make the game progress without duplicating areas as much. Like in sunshine, pintas keep on appearing in different places, and saying different things. And the area changed some as well. So, we can do stuff like that with variables.
Good! Any other ideas by others can be poster here as well.
-
You should let people know in your post that comments might contain info on variable ideas.
-
You should let people know in your post that comments might contain info on variable ideas.
Good idea.
-
I don't understand your latest edit to the main post. That bit about keys being pressed.
-
I don't understand your latest edit to the main post. That bit about keys being pressed.
It's just a formula you can use for a single key press. This way the command will run one just the one time when you press down the key, rather than run continuously as you hold the key down. A variable is used to make it run only once, and that variable is reset whenever the key is no longer held down.
I would like to add key press conditionals to Platform Builder, but it would be a little tricky since looping commands are not run every single step of the game. This serves as a workaround.
-
Ah. That makes more sense.