The Usefulness of Values(In Games)
Author: | Kramy
|
Submitted: | 7th August, 2003
|
Views: | 5113
| Rated: |
|
|
Many people don't realize the usefulness of values. This article will describe more complex uses of values, and examine fairly complex examples. You should understand the basic principles of a value, listed below before reading this article...
you can set a value to a number
you can subtract a number from a value
you can add a number to a value
The number can be another value, so you can add/subtract values to/from eachother
The number can be another value, so you can set a value to another.
How to complare values(for example a counter) to a number or another value.
Note: An Event consists of the conditions and the actions. Actions will have a - before them.
Right click an event and select insert to insert a new condition.
First thing you should know is a value is a value, whether it's in an alterable value, a counter, an edit box, or a global value. You may be wondering what one or all of these are, if you haven't had time to familiarize yourself with The Games Factory(TGF) or MMF(Multi-Media Fusion).
A counter is a single object that you insert into a frame(called a level in TGF) that records a single value.
An alterable value is a value stored in a specific object. If you created 20 "monsters" that were all the same object, each one could store an alterable value.
An edit box is especially useful, as you can have the user enter a number in it, and can even convert the number to text. Counters, alterable values, and global values can not do this.
A global value is a value which is "global" to the entire game. What this means is you can go from frame to frame and it will not reset itself.
Now let me outline some of the uses of these values in greater detail.
~Game uses~
The Counter
Counter Commands:
compare counter value to "something"
-subtract ### from value
-add ### to value
-set value to ###
A counter stores a single value, which is exactly the same as an alterable value. The difference between an alterable value and a counter value is counters can have minimum and maximum values. In this way, you can set the minimum value, and avoid using extra events.
Here is an example:
Have the minimum value of the counter set to 5.
Upon "attacking"
-set counter1 to "strength of hero" + "damage of weapon" - "defense of enemy"
-subtract counter1 from "enemy health"
This can be done in 1 line of coding. If an alterable value were used it would appear like this...
Upon "attacking"
-set alterable value A to "strength of hero" + "damage of weapon" - "defense of enemy"
-set alterable value B to 5
alterable value B = 5
alterable value A =< 4 (less or equal)
-set alterable value A to 5
alterable value B = 5
-subtract alterable value A from "enemy health"
-set alterable value B to 1 (or anything different than 5)
Wow, that sure is more complex to get the same effect! The usefulness of this would show up well if you were fighting an enemy with 3 times as much "defense" as you had "attack power". If you didn't include all the evens when using an alterable value, your damage would actually go negative, healing the enemy!
Alterable Values
Alterable Value Commands:
compare alterable value to "something"
-subtract ### from value
-add ### to value
-set value to ###
Sounds the same as a counter doesn't it? It basically is the same, except alterable values(as mentioned above) do not have a minimum and maximum value, so a minimum/maximum value will have to be coded in the event editor. Alterable values do have one advantage over a counter though, each object can have its own alterable values.
Here is a fairly complex example...
You want to create bullets when either ctrl or enter is pressed, and you want the bullets created from player 1 when ctrl is pressed, player 2 when enter is pressed, and you don't want the bullets to hurt the players they were created from. Here is how, using alterable values...
ctrl is pressed
-create bullet from player 1
enter is pressed
-create bullet from player 2
Now we need the bullets to shoot in the direction faced...
alterable value a of bullet <> (different) 5
alterable value a of bullet <> (different) 10
bullet is overlapping player 1
-set dir of bullet to player 1
-set speed of bullet to 100
-set alterable value a of bullet to 5
alterable value a of bullet <> (different) 5
alterable value a of bullet <> (different) 10
bullet is overlapping player 2
-set dir of bullet to player 2
-set speed of bullet to 100
-set alterable value a of bullet to 5
Now we need the bullets to enter "hurt" mode.
alterable value a of bullet = 5
bullet not overlapping player 1
bullet not overlapping player 2
-set alterable value a or bullet to 10
Now all that's left is coding the "hurting" part.
alterable value a of bullet = 10
bullet overlapping player 1
-subtract [number here] from player 1 health
-destroy bullet
alterable value a of bullet = 10
bullet overlapping player 2
-subtract [number here] from player 2 health
-destroy bullet
Some things to note about this example...
The bullet must have ball movement.
Right click an event and select "negate" to make an event a "not" event.
This example does not use the "shoot an object" action that all active objects have.
Global Values
Global Value Commands:
compare global value to "something"
-subtract ### from value
-add ### to value
-set value to ###
A global value is similar to a counter aswell. The main difference between a global value and a counter is that global values are global to the entire game. I have also noticed that global values are a safe way to transfer values, while using the "counter global to entire game" option for counters(in TGF) causes the game to crash when the counter is deleted.
Global values are extremely useful in platformers...here is an example.
When the player starts a new game, set global value 1 (health) to 50
Then add these events to every level
Start of level
-Set "health bar" to global value 1
End of level
health bar <> (different) 0
-Set global value 1 to "health bar"
That extra condition in the last event is so that if you die(0 health) and restart the level, it will not load your health to "0". You can also transfer score, or weapons/spells in a similar way.
For weapons/magic, either have each weapon load a different global value, which is equal to that weapon at the start of frame(and if it is say "10", enable the weapon).
Or have 1 global value for the weapons and magic. Then have it so it enables different weapons based on the value(for example, 1 = knife, 2 = knife+sword, 3 = knife+sword+gun) and you get the picture...Global values are definately an asset to have.
Edit Box
The edit box I am not going to go into great depth describing because all the uses it can have would take a long time to describe, and double the size of this article...
I will describe the general use of edit boxes, however.
Edit boxes are different than counters, alterable values, and global values. Edit boxes can store either a value or a string. If you don't know what a string is, a string is a line of characters, or text. If you wanted, you could set an edit box to the string "blah blah blah" and it would show up, or you could set an edit box to the value "49" and it would show up.
Edit boxes have useful features. Right click on one and click setup to examine them...
Scrollbars: Where do you want a scrollbar to appear, or do you want it to automatically scroll when text is added?
Tab Stop: One line string or value. Uncheck this if you want scrolling enabled in your edit box.
MultiLine: Allows "enter" or "return" to create new lines in your edit box.
Password: Turns all characters entered into hidden characters(so typing "RHINO" would create "*****").
Border: Creates a small border around the box.
Read Only: The user can not alter anything in the box.
Hide on Start: Invisible, can not be seen or clicked.
Cases: UPPERCASE, No Change, or lowercase. This can be useful for passwords if your password is all UPPERCASE.
Another useful feature of edit boxes is the ability to "grab" values.
An edit box is considered a "string" object, so to get a value from another object, you must set the text of the edit box to:
STR$( )
where you insert the value...
STR$( value("counter1"))
Likewise, you can take a string and turn it into a value...if the user types in a "6" you can use this code...
VAL( )
to get the value of the string
VAL( edittext("edit box 1"))
Well, that's about all I can type at the moment...I know there's more, lots more, but my fingers are about to fall off, and I still have to spell check this thing.(Which I'm actually not going to do, since I've been typing forever) I hope my article provided some insight into values, for those of you who did not know much about them. My next article will probably cover something like the usefulness of strings(which are actually very useful in professional applications and games) or the usefulness of values in professional applications.
-Kramy
|
|
Kramy
Registered 08/06/2002
Points 1888
|