Variable Types....
Posted:
Thu Apr 26, 2007 7:46 pm
by Jay S.
Greetings!
I'm Jay S. and I have had Game Editor for around two years and have still not started any projects with it yet.
I've learned how to use it very well,
but, however, only shortly ago I finally learned how to use Variables.
I do, though, have a few questions:
1) What exactly
is a Variable "type"? What is the difference between an "integer," "real," and a "string," and how might they apply to a Variable? For example, is a "string" specifically used for a function used in a Variable, while the others would pertain to numerical Variable values?
2) What exactly is an Array?
3) How are saved Variables used? Specifically: can the "loadVars" function be used no matter which level or area you're in, despite if "saveVars" was used in another level? (I'm talking about if your individual levels are different .DAT files included with the game.)
Well, a bit of questions to start, but thank you for your consideration. And Makslane:
thank you for such a great program!
Posted:
Thu Apr 26, 2007 10:40 pm
by pixelpoop
These are very good questions. I recently started learning to program and out of the many ways I began the best was with a book. You should go to a library or buy and intro to programming book. I have heard good things about the Idiots Guide programing books, although I read a different book.
A variable holds data.
an integer variable holds whole numbers ie. 0,1,2,3,-1,-2,-3 etc..
a real variable holds whole numbers plus numbers after a decimal. ei. 3.14159265
a variable string holds a string of letters ei. yourname
an array is more then one chunk of information stored in 1 variable
as for saved variables I haven't worked with them yet, but I think the answer to your question is yes, you can save variables to be called up by other files.
Posted:
Thu Apr 26, 2007 11:45 pm
by Fuzzy
The basic type of variable is the bit. it is either 0 or 1.
A byte is simply a number from 0-255. You dont see it much in C or GE. It is composed of 8 bits. so a byte containing a value of zero is written:
0000 0000
Notice that I put a space in there. that is because there is a little hidden programmer joke, and it also helps make it more readable. The joke is that half a byte(bite) is a nybble (a nibble). You cannot use a nybble directly. So ignore it, other than giggling(gyggle?) about it.
A char is a special byte where the first seven bits hold the number, and the eigth bit represents plus of minus. Because of this, a char represents the value -128 to +127, a range of 255. It is an 8 bit integer.
To make a char into a byte we add 'unsigned' infront of it. like so...
unsigned char FuzzyAge = 34;
Which causes the compiler to discard the +/- and use that space to count. So fuzzy can get no older that 255.
Next we have the word, which is a 16 bit unsigned integer. If you hear people speak of the first nintendo as being 16 bit, this is what they mean. The first computers were too. if we continue the bit/nybble/byte joke, a word is a playte. Thats really getting obscure.
A signed integer ranges from -32768 to 32767. It is called a short int.
short int FuzzyScore;
Now modern computers are 32 bit systems. The joke is "dynner". think of dinner. Now go eat some.
A thirty-two bit variable with a sign (+/-) is called an int, or integer.
You have to be careful of this though, as they change it from operating system to operating system, and as computers get stronger, they raise the bit limit. An integer used to only be 16 bits. Again, they sometimes call this a word too.
The range is −2,147,483,648 to +2,147,483,647
One more type of integer is the long int. Its insanely big. 64 bits. It can handle can handle trillions of values or more.
Whats the silly term? I'm not telling you. That joke is ridiculous. Why do you even want to know? Who would know what you were talking about anyway?
Now... arrays. Arrays are collections of numbers. Think of all the letter boxes at the post office. Each has a column number and a row number. You could even have a depth number, or more. First you pick a number type, that each box will store. then, name the variable, and the in square brackets, [], you put the number of rows. if you need columns, put a second one.
int CoinType[6];
in Canada we have six types of coins. to store the number of pennies, we access the first box like this.
CoinType[0] = 0;
Fuzzy doesnt even have a penny. However, when out walking, he finds a quarter.
CoinType[3] = 1;
I chose int for the array type because it is the smallest size that is practical. If i had used a unsigned char, then I could only ever have 255 of one coin type.
Here is a 2 dimensional array.
int ScreenCopy[640][480];
So that is the integer types. Now for strings.
A string is simply an array of char!
string Name="Fuzzy";
is the same as char Name[5] = {'F','u','z','z','y'};
Thats it for strings!
Now onto floats.
Floats work just like ints, but through a esoteric process, they store the numbers decimal as well. You have float and double to play with. float is 32 bit, and double is 64 bit.
And thats it! Questions?
Posted:
Fri Apr 27, 2007 1:17 am
by Jay S.
Thanks for all the info!!
That's all very helpful; not just to me, but I'm sure also to anyone new at GE to read this. I appreciate all of your time... And, no, as of yet I really don't have a whole lot of questions... (And yes, I have considered buying a C book; and the "
Dummies" book at that.)
In fact, ironically, I've worked with bits and bytes similar to this manner. Or maybe I should say little nybbles...
And as for the "saveVars," I'll probably end up experimenting to see if there's any possible way this can be done. I'll post any more questions and/or discoveries I may find.
Thanks again!!!!
Posted:
Fri Apr 27, 2007 2:32 pm
by Jay S.
HEY,
I just finished experimenting around, and, I have figured out this much: I just created a little program to load and save Variables, and.... IT WORKED!!!
I discovered that the saved Variables themselves are actual FILES saved to your game's directory! So that means you're able to load them up from the .SAV file into the game using loadVars.
Well, thought I'd say somethin', cause this is very useful to know.
THANK YOU, pixelpoop and Fuzzy.
Posted:
Fri Apr 27, 2007 2:36 pm
by Sgt. Sparky
you can also load variables from any game made with GE from those little
files,
my commando man game I made a while back reset the game by loading the level over again after saving the life variable,
and on the create actor event of the view it loaded the life variable,
and if the life variable was 0 it changed it to 3.
also when the player was destroyed it would subtract the life varable and if the life variable was equal to 0 it would set a wooden plank on the winidow that said Game Over,
use space to play again.
Posted:
Fri Apr 27, 2007 2:53 pm
by Jay S.
Really? that's pretty good.
This is opening such a new door for me in Game Editor, because now just knowing how Variables work allows what I make in it to broaden
. This will chances are be invaluable for the project I might make!
(Now I don't need to make dozens of different actors to perform all my actions....
)
Posted:
Fri Apr 27, 2007 6:13 pm
by Sgt. Sparky
variables can also help you with jumping,
make a variable called jump, make it an integer.
on collision on top side of the ground,
- Code: Select all
jump = 1;
and on the key down event of up,
- Code: Select all
if(jump == 1)
{
yvelocity = - 10;
jump = 0;
}
and you can adjust jump to your liking.
Posted:
Fri Apr 27, 2007 11:46 pm
by Jay S.
I know it; this is another great use for Variables. Believe me, you wouldn't believe some of the things I did just to make a decent jump like this in my beginning days with GE. If I can recall correctly, just to do so I think once I made two or maybe even three actors controlling a jump.
(Even just to get actual decent collisions...) So any info in this area is very useful, if not encouraging...
I'll most certainly be asking more questions once I actually get started on something with GE. Right now, I'm coming up with what I actually am going to make... Either a strategy game like Myst or an RPG.
Oops, I forgot something.... Why is it when I have two "If" functions in the Draw Actor event for an actor, the frame rate of the game becomes like molasses and then freezes? This is what I did:
- Code: Select all
if (variable == 0)
{
CreateActor (All the other info here....)
}
if (variable == 1)
{
DestroyActor (All the other info here....)
}
Would anyone know why this happened? This also resulted in having two seperate Draw Actor events... Would I have to use the Global Script editor?
Posted:
Sat Apr 28, 2007 1:03 am
by makslane
Jay S. wrote:Oops, I forgot something.... Why is it when I have two "If" functions in the Draw Actor event for an actor, the frame rate of the game becomes like molasses and then freezes?
In each Draw Actor call you are creating a new actor.
Posted:
Sat Apr 28, 2007 1:57 am
by Jay S.
OH! I SEE!
No wonder!!
Now that I think about it, I'm surprised I didn't notice that before.... Because since the Variable = 0 the whole time, each time it's creating it....
What a paradox!!!!!
THANKS, Makslane. As usual, you save the day.
Instead of creating the actor, perhaps I can just make it visible.
Posted:
Sat Apr 28, 2007 3:13 am
by Sgt. Sparky
Jay S. wrote:Instead of creating the actor, perhaps I can just make it visible.
just change your code to somthing like,
- Code: Select all
if (variable == 0)
{
CreateActor (All the other info here....)
variable = 1;
}
if (variable == 2)
{
DestroyActor (All the other info here....)
}
Posted:
Sat Apr 28, 2007 2:41 pm
by Jay S.
Ah, I see what your code means. That's another good idea.
Thanks for all your help...
Posted:
Sat Apr 28, 2007 10:23 pm
by Sgt. Sparky
your welcome...
even though I did not do much. xD