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

TingThing

  • Admin and Developer
  • Level 19: Gerby
  • *
  • Posts: 988
  • 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 file 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:


For your coin:
Code: [Select]
money + 10
if game var coins < 3
{
+You found a golden coin! This is worth $10.
game coins 1 + 1
}


For your heart:
Code: [Select]
health + 3
if game var hearts < 3
{
+You found a golden heart! This restores your health by three.
game var hearts + 1
}

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.

Code: [Select]
if course var 1 = 0
{
// Start the obstacle course
course var 1 = 1
}
else
+You have already tried the obstacle course. Try again later!

Here's a more complicated example. Maybe one of your areas has a race track. After you finish the goal, you talk to an NPC, and the NPC rewards you if you finished the race in under 15 seconds. Here's what you could do:

When the race begins, start a timeline that's at least 1 minute in length.
When you finish the race, you can save the timeline position to a variable. However, the timeline position is in 1/10 seconds, so the timeline position is actually 10 times larger than the number of seconds. To get the number of seconds, you will need to divide the variable by 10. So...


Code: [Select]
area var my time = [timeline 1 position]
area var my time / 10

Then when you talk to the NPC, you run the command:

Code: [Select]
if area var my time < 15
{
//reward the character
}
else
+You weren't fast enough! Try again next time.


Platform Builder has conditionals for if a direction or action key is pressed down. But what if you want to run stuff only the moment that a key is being pressed down, and not continuously? Again, variables can come in handy. In a looping command prompt, you could try something like this:

Code: [Select]

if key != jump
var pressed = 0
if key = jump & var pressed = 0
{
var pressed = 1
//key press code
}

Feel free to comment your own ideas for others to see :)
« Last Edit: December 22, 2018, 03:19:49 AM by TingThing »

TingThing

  • Admin and Developer
  • Level 19: Gerby
  • *
  • Posts: 988
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #1 on: October 07, 2018, 10:57:37 PM »
Note: 6.1.1 actually doesn't support timeline position to be put in brackets, but I'll include that in the next patch.

Christian Game Maker

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • 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:44:14 PM »
What do the two // mean?

Christian Game Maker

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #3 on: October 07, 2018, 11:49:34 PM »
Oh, it's a note.

TingThing

  • Admin and Developer
  • Level 19: Gerby
  • *
  • Posts: 988
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #4 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 20: Nobom
  • *
  • Posts: 1497
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #5 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 20: Nobom
  • *
  • Posts: 1497
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #6 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

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #7 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 19: Gerby
  • *
  • Posts: 988
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #8 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 20: Nobom
  • *
  • Posts: 1497
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Variables in Platform Builder
« Reply #9 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

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #10 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 19: Gerby
  • *
  • Posts: 988
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #11 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

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #12 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 19: Gerby
  • *
  • Posts: 988
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Variables in Platform Builder
« Reply #13 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

  • Currently developing Project ASM (The Adventures Of Super Mike) And manager of platformbuilderfansite.weebly.com!
  • Master Builder
  • *
  • Posts: 3483
  • The way of the Cross leads home.
    • View Profile
    • The Adventures of Super Mike Website (ASM)
Re: Variables in Platform Builder
« Reply #14 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.