Author Topic: Variables in Platform Builder  (Read 4307 times)

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Variables in Platform Builder
« 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:
Code: [Select]
game var myCoins = 0
game var myHearts = 0


[size=78%]For your coin:[/size]
Code: [Select]
money + 10
if myCoins < 3
{
+You found a golden coin! This is worth $10.
myCoins += 1
}

For your heart:
Code: [Select]
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%]

Code: [Select]
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
Code: [Select]
local var times landed = 0

In the "land" command prompt of your custom enemy
Code: [Select]
times landed += 1
if times landed = 3
kill enemy
Feel free to comment your own ideas for others to see :)
« Last Edit: August 17, 2020, 02:01:20 AM by TingThing »

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #1 on: October 07, 2018, 11:44:14 PM »
What do the two // mean?

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #2 on: October 07, 2018, 11:49:34 PM »
Oh, it's a note.

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #3 on: October 08, 2018, 02:40:08 AM »
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.

Antikore

  • YouTuber, Gamer and the developer of Castle Chamber.
  • Level 21: Magmus
  • *
  • Posts: 1609
  • Total likes: 54
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #4 on: October 09, 2018, 02:16:03 PM »
Very well explained, thank to this post, people will understand variables better.
Sorry because my English is not very good because I'm Spanish ;) :P

Antikore

  • YouTuber, Gamer and the developer of Castle Chamber.
  • Level 21: Magmus
  • *
  • Posts: 1609
  • Total likes: 54
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #5 on: October 19, 2018, 03:13:32 PM »
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...
Sorry because my English is not very good because I'm Spanish ;) :P

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #6 on: October 19, 2018, 07:15:05 PM »
Hmm... I wish I knew... I never have programmed. So, I can't tell you.

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #7 on: October 20, 2018, 05:13:37 PM »
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.

Antikore

  • YouTuber, Gamer and the developer of Castle Chamber.
  • Level 21: Magmus
  • *
  • Posts: 1609
  • Total likes: 54
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #8 on: October 20, 2018, 08:10:41 PM »
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.
Sorry because my English is not very good because I'm Spanish ;) :P

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #9 on: November 02, 2018, 10:13:47 PM »
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.

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #10 on: November 03, 2018, 07:42:44 PM »
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.

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #11 on: November 04, 2018, 12:12:31 AM »
You should let people know in your post that comments might contain info on variable ideas.

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #12 on: December 08, 2018, 04:34:04 PM »
You should let people know in your post that comments might contain info on variable ideas.


Good idea.

Christian Game Maker (CGM)

  • Christian, videogame dev hobbyist. Servant of Jesus Christ.
  • Master Builder
  • *
  • Posts: 3686
  • Total likes: 21
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #13 on: December 24, 2018, 01:44:09 AM »
I don't understand your latest edit to the main post. That bit about keys being pressed.

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1081
  • Total likes: 65
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #14 on: December 24, 2018, 07:42:51 AM »
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.