Announcement

Collapse
No announcement yet.

Variable Discussion - What can we do with variables?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Variable Discussion - What can we do with variables?

    A guy at GameFAQs was asking about variables on the RPG Maker 3 board. From what I could gather, he knew next to nothing about them. I took it upon myself to attempt to disseminate my knowledge in a way that someone with no programming experience can wrap his mind around and grab onto. Much to my surprise, he said that my explanation was very helpful (I hadn't thought that it would be).

    I'm posting this here because GameFAQs eventually purges old messages, and who knows... It may be a helpful variable resource to someone. As always, I'm just trying to help.

    ~*~*~

    A variable is one of the most basic things in programming. Being able to manipulate variables enables us to create video games.

    A variable is a "thing" that holds a number. It can be any number that you (the programmer) choose. All variables start with a value of zero. A variable's value can mean anything that you want it to. The value of the variable is what the computer is interpreting. The programming that we (the programmers) do with variables enables us to communicate with the computer in such a way that we and the computer are on the same page. The computer is interpreting what we've programmed and is acting on it, and we are giving the numbers a meaning.

    So, Shared Variable 01 has a value of 0 (zero) at the start of the game. This value of zero can mean anything that you want it to mean. Let's explore some examples.

    The player needs to collect five emeralds and trade them to a merchant for a useful weapon. We would use a variable here that tells the computer how many emeralds the player has collected. Make a treasure item and name it "Emerald". Now create five separate events and place them on the map. Each event where we find an emerald gives the player the treasure item and increases the variable by 1. The computer is tracking how many of these emeralds the player has collected. The merchant should use a Val Condition Branch that checks the value of the variable to see if it equals 5. If it equals 5, then the merchant can offer to trade a weapon for the five emeralds we've collected.

    Another example: A townsperson says that a dragon has been attacking the village. The player needs to find this dragon and defeat him. For this situation, we would use a variable.

    If Variable = 0 then [dragon hasn't been defeated yet]
    If Variable = 1 then [player defeated the dragon]

    The values I'm assigning to the variable here mean something to me, and they also mean something to the computer. I'm communicating with the computer to achieve my desired result. So when you talk to the townsperson, he should have a Val Condition Branch that checks the value of the variable. If it = 0, then he should tell you that the dragon has been attacking the town. If it = 1, then he should congratulate you for defeating the dragon.

    Edit: Logically, the event where we defeat the dragon should increase the variable by 1 or modify it so it =1.

    These are simple examples. You can take it much further than this, and add whatever you want. You can add any number of other conditions and meanings for variable values.

    Use a different shared variable for each thing that you're keeping track of in your game. Internal variables work the same way, except that they are associated with specific objects (characters, events, and things). You can use shared or internal variables. Doesn't matter.

    What's important to understand is that at any given time during the game, each variable has a value that means something. The value (number) that the variable holds is what the computer is interpreting (what it means to the computer). The meaning that you give the variable is how you are interpreting it. You and the computer are working as a team, each interpreting the variable in a different way but achieving the same desired result with it.

    Increasing a variable's value adds to it. Decreasing it subtracts an amount from it. Modifying a variable sets the variable's value to that number regardless of what it was before. i.e. Shared Variable 01 = 5. I modify it so it = 10. It now = 10.

    "Shared Variable 01" is the designation of which variable it is. It's the variable's name.

    ~*~*~

    I'll give you something more to ponder.

    Computers work with numbers. That's how they operate. It's the "language" that computers understand. They interpret numbers and give the numbers meaning for us, the users. Right now, as you read this, your computer is interpreting numbers and using them. It uses numbers to create the graphical display of this webpage.

    When I type the letter "W" on my keyboard, the computer is rapidly interpreting the keypress of the "W" key, understanding what it means, and using numbers to generate a graphical representation of the letter "W" on my screen. It looks like a "W" to me, but to the computer it has a completely different meaning. The letter "W" is composed of numbers that the computer understands. It interprets the letter "W" as a bunch of numbers. We interpret it as the letter "W".

    Your PS2 works the same way. It interprets numbers and uses them to generate the graphical display, text, animation, music, everything that goes on in a video game. The PS2's CPU (computer) speaks in a language of numbers. That's what it understands. The trick for any programmer is to understand how the computer thinks and what it understands. It understands numbers.

    We give all those numbers a meaning. The graphical display is full of numbers that designate color, texture, and everything you see onscreen. It means something to us because it's been programmed to do that. The computer is speaking in its native language, and the programming is translating it into images that we understand.

    Variables work the same way. The computer interprets a variable in its native language of numbers. We give the numbers a meaning.

    Understand that you need to communicate with the computer in terms that both you and the computer can understand. The computer doesn't understand our language or the way we think. It understands numbers. The trick for any programmer is to learn the computer's language and use it to communicate with the computer. Then you can achieve whatever results you desire.

    A variable is a way that you are communicating with the computer. It's a number, and you can use it any way you want and give it whatever meaning you want.

    #2
    Re: Variable Discussion - What can we do with variables?

    I understood what variables are for, but can't you use mode-switching also?
    I mean, when the dragon is killed, modify to mode number 2. When the last emerald is taken, the same. I am not using variables in my game. Should I?
    Game in progress: "Cards of Destiny"!
    How many of you have tried Game Maker, for PC?

    Comment


      #3
      Re: Variable Discussion - What can we do with variables?

      A good mix is best. You see, when the dragon is killed, you switch the dragons and townspersons mode to 2. BUT no other event knows the dragon was killed. With a variable, one change can impact multiple events, while with modes you have to switch each mode each time. With the emerald example- you would have to switch modes for EACH AND EVERY EMERALD unless it was linear or something.

      Comment


        #4
        Re: Variable Discussion - What can we do with variables?

        Thank you, I'll take that into account.
        Game in progress: "Cards of Destiny"!
        How many of you have tried Game Maker, for PC?

        Comment


          #5
          Re: Variable Discussion - What can we do with variables?

          Iv only had the game for 3 days, but understand most of the games tools. The only tool I don't know how to use is the "Variables" system. Shared, Internal, I don't understand any of it. Is there a more simple explanation on it? Actually, I don't understand how to make events stop happening every time I step on them too. Any help?
          "Kill him, you know you want too." - Quote from Ravage, my main Antagonists in my story (RPGM3)Battle-Axe Dragon.

          Comment


            #6
            Re: Variable Discussion - What can we do with variables?

            First of all, welcome to the Pavilion, Battle-Axe Dragon.

            It's nice to see this thread again. Crythania put some work into his the first post, I'm sure.

            Variables can be a challenge to figure out at first. If you type the word "varialbles" (yes, with the extra "L") in the search feature at the top, you will several threads that may be helpful.

            Also, to make events stop happening after you touch them the first time, you can:
            -turn the display of the event off (at the end of the event code) OR
            -create a second mode for the event (and swith to mode 2 at the end of the event code in the first mode) OR
            -use variables (which is something I know you're still figuring out)
            Last edited by Pagerron; 11-18-2007, 11:35 PM.
            " I am the way, the truth, and the life. No one comes to the Father but by me. " - Jesus

            Comment


              #7
              Re: Variable Discussion - What can we do with variables?

              Thanks, I will.
              "Kill him, you know you want too." - Quote from Ravage, my main Antagonists in my story (RPGM3)Battle-Axe Dragon.

              Comment


                #8
                Re: Variable Discussion - What can we do with variables?

                Internal Variables are variables assigned to an object to make things easier to organize(also gives you a lot more variables to store things with), lets say you made 3 characters, named A, B, and C...lets say for some odd reason you have to play all 3 characters through a specific level one at a time...Once you beat the level with player A, you can set Internal Variable 01->Char. A->"1", meaning that character completed the level.

                And the same goes for the other 2 characters, each having their internal variable 01 switched to "1"

                This is more organized then using External variables(Which are universal variables, i.e. doesnt really have to be linked to anything object specific), where you would have to use Ext. Variable 01, 02, and 03, and have to keep track of what variables are which.

                I think this is what they are used for(this is what I use them for anyways)
                Last edited by JPS; 11-18-2007, 11:51 PM.

                Here I come Pav, like the Kool-Aid man barging into a funeral! Oh yeah!

                Comment


                  #9
                  Re: Variable Discussion - What can we do with variables?

                  Originally posted by Battle-Axe Dragon View Post
                  Iv only had the game for 3 days, but understand most of the games tools. The only tool I don't know how to use is the "Variables" system. Shared, Internal, I don't understand any of it. Is there a more simple explanation on it? Actually, I don't understand how to make events stop happening every time I step on them too. Any help?
                  Well I was in your situation once and I know exactly how you feel. I'll try to explain it how it made most sence to me. I use the variables to track what events have been played.

                  When you start your game you have your opening storyteller.(In most cases)Just say right after that you have an auto event in the middle of a town. Let's say you want it to trigger if it has a veriable of 1. In the event layout if you hit L1 you can set how the event is triggered. Button/touch/auto. Right below that is three open spaces. If you click on it, it will bring up the event condision screen. Hit the none button then select the Value=Specified value. The you can choose to use either shared var's or internal var's. Honestly it does't matter at all. Let's just choose variable 1. Where it says 123... you can leave it at 0 because that's how we want the event to be triggered. At the end of the event make sure to put a increace shared var. cammand in. Set it to increase it by just one.

                  Next lets say there is an event at the inn. Do the same thing except where it says 123... put 1. At the end you would put increase it by 1 again. That way the next event would be triggered only if the var is at 2.

                  This way if you go to the event that is set at 2 before the one set at 1 it won't play. This forces the player to follow the intended path.

                  This is just a very basic way to use variables to track something. Perhaps one of the easiest. Trust me once you do it a few times you'll get the hang of it. Then they'll be like nothing to use. They're just confusing at first because no matter how you explain it you have to use a lot of numbers. Well if you need more help just say something.

                  All most forgot to welcome you. I hope you like it here.
                  Last edited by Lausen; 11-19-2007, 12:03 AM.

                  Comment


                    #10
                    Re: Variable Discussion - What can we do with variables?

                    Yeah once you get used to how variables work a whole world of possibilities will open if you can use them right.

                    And with RPGM3 you'll need as much of the world of possibilities as you can find...

                    Here I come Pav, like the Kool-Aid man barging into a funeral! Oh yeah!

                    Comment


                      #11
                      Re: Variable Discussion - What can we do with variables?

                      I tried making a mission (sorta) to get a character for your party. He's really starving,so you need to go find him food in a dungeon (get from 1st boss) bringing this to him will make him ask if he can have it and if you say yes then a storyteller will start, then he joins you. I got all of this except that even if I don't have the food, he still asks me if he can have what I actually don't have on me at that moment. I can say yes to him too and it all still happens as if I gave him food. What am I doing wrong? Do I have to resort to Variables for this one?
                      "Kill him, you know you want too." - Quote from Ravage, my main Antagonists in my story (RPGM3)Battle-Axe Dragon.

                      Comment


                        #12
                        Re: Variable Discussion - What can we do with variables?

                        He must be a picky eater

                        Here I come Pav, like the Kool-Aid man barging into a funeral! Oh yeah!

                        Comment


                          #13
                          Re: Variable Discussion - What can we do with variables?

                          Cut and pasted from this thread.


                          You change variable values under Propery Control, and use modify, increase, or decrease variable values here.

                          Basically, let's say an NPC wants you to find three magical pieces of raccoon fecal matter for him. You would first make a Val Cond branch, under Control, and make it have four branches. Select a variable you want to use (you can use either shared or internal...there really is no benefit to using one over the other, besides maybe organizing things for yourself-write down all variables you use and what they do in a notebook!!! I cannot stress this enough!!!); let's say you're going to use Shared Variable 1. Then, in the branch, make Shared Variable 1 equal to 0, 1, 2, and 3.

                          Now let's go to the events where you find the fecal matter. Let's say you find it in a barrel. Make a barrel a button event, and when you click on it, have the dialogue box say something like, "You have acquired the mystical powers of the raccoon feces!" or whatever, and then in another line of code within that mode, go to Property Control, under Increase Shared Variable, and select Shared Variable 1. Then set the value to 1 (meaning it will increase by one). Now Shared Variable 1 should equal 1.

                          Go to the next event, say an NPC. Do the same thing. Make a dialogue box saying you have received the exalted poop, and then increase the variable again using the method discussed above. Now Shared Variable 1 should equal 2. Do this a third time, and now the variable will equal 3.

                          Now go back to the Val Cond branch at the beginning. Remember you made 4 branches, with Shared Variable 1 equalling 0, 1, 2, and 3? These represent how many pieces of feces you have found. Under Shared Variable=0, type a dialogue box saying something like, "You have not found any fecal matter yet. Begone with you!" Under Shared Variable=1, make a dialogue box saying, "You've only found a single solitary piece of raccoon droppings. Come back when you have two more." Under Shared Variable 1=2, do the same thing, but say something about needing to come back after finding one more. Then after Shared Variable 1=3, say, "You have found all that I have asked of you. Due to your pockets reeking after having carried all that fecal matter around the countryside with you, I will reward you with this treasure item." or whatever. If you want, you can make another variable at this point if you need to "prove" that you have received the NPCs blessing. Make Shared Variable 2 equal to 1. Then, when you go talk to another NPC or whatever, make a Val Cond branch with two branches. Shared Variable 2=0 or=1. When it's equal to 0, the NPC will know you didn't talk to the first guy after gathering all the feces. When it's equal to 1, that means you've already talked to him and turned in all the feces.




                          Hope that helps.
                          Or dog feces, if you prefer....

                          Comment

                          Working...
                          X