Thoughts about data control

You must understand the Game Editor concepts, before post here.

Re: Thoughts about data control

Postby Bee-Ant » Wed Jun 03, 2009 11:18 pm

Oh, just forgot it...anyway I havent opened GE wiki yet :P
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby DST » Tue Jun 16, 2009 1:30 pm

About transferring variables and cpu usage.

When transferring variables, you are trapped in 3 dimensions.

1 st is the cpu efficiency (and stability) of your code
2 nd is the understandability of it - so you can continue to work on it and improve it.
3 rd is the interface of game editor.

When you make redundant calculations, you can eat up your cpu cycles really fast. But if you make sure to avoid such mistakes, then you are left with the option of either using local variables and translating them via functions, or using global variables and just accessing them directly.

So you add global variables with reasonable names, like "blackknightappear" or "demofinish". You can access variables easily and help rule out uncertainty. But then you end up with a long list in the editor - eventually your actor and variable lists become too long to easily manage.

So that's when you move over to arrays. But then you have to remember what the array cells hold, and there's no way to see that in ge except by actual code notation.

So then perhaps, you try to start using actors, calling them by name, automating their ai to handle events on their own and output as few variables as possible; then using functions to move and operate these variables. You start using int i; more.
You start using Actor * more.


I have a suspicion that a full, professional game uses a little of all variable types. Locals, actors, globals, and arrays/structs/hashmaps. Any particular function of a game requires a certain set of variables to work most efficiently.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Thu Jun 25, 2009 5:23 pm

Its unavoidable to use many variables for such big game. I mean a game that has very complex gameplay. For example RPGs. So the easiest way to speed up the game is by disabling the activity of any actor that doesnt need an activity when out of sight. Then, minimalize the Draw Actor and collision usage. Use short code on draw actor. Avoid of using too much of clonning.
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby DST » Fri Oct 09, 2009 4:25 pm

Bee-Ant wrote:I think the top of the mountain is imposible to reach. And we shouldnt reach it. Because we must avoid perfection. Perfection doesnt make us grow. If something is perfect, then theres no room left. Room to dream and make something better. Because youre already at the top, and wont go higher anymore. Thats why lets imagine that the top is unlimited, so that we can go higher, higher and higher...


Ah, you are wise beyond your years!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sat Oct 10, 2009 11:38 am

Im already 20...
Still not old enough ? :P
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby MrJolteon » Sat Oct 10, 2009 5:04 pm

Bee-Ant wrote:I think the top of the mountain is imposible to reach. And we shouldnt reach it. Because we must avoid perfection. Perfection doesnt make us grow. If something is perfect, then theres no room left. Room to dream and make something better. Because youre already at the top, and wont go higher anymore. Thats why lets imagine that the top is unlimited, so that we can go higher, higher and higher...

or the top is limited, but it gets so slippery at 1mile left that you fall down 5miles... wait... that's not right...
Join us on Discord!
(Download and registration not required)
User avatar
MrJolteon
 
Posts: 2266
Joined: Sat Aug 09, 2008 3:25 pm
Location: Page 400 of the interblag
Score: 100 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sat Oct 17, 2009 10:12 pm

MrJolteon wrote:or the top is limited, but it gets so slippery at 1mile left that you fall down 5miles... wait... that's not right...


No that is right.

Fuzzy wrote:The best games you will make will be within your ability to understand. If you find yourself doing something and you dont know why... you shouldnt be doing it that way. That can be depressing, but its true. Learning takes time.


That slippery portion is when you are at the limits of your knowledge. I think its the most fun part of programming.

And the most frustrating! :D

I am struggling with a new language and a new library for that language. Its like learning two at once and it isnt easy, but I love the feeling of the mystery being solved.

I love it more than finishing anything. Thats part of the problem!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby DST » Sun Oct 18, 2009 12:57 am

Philosopher George Santayana defines fanaticism as "redoubling your effort when you have forgotten your aim".

Of course, many of the people who are considered to be 'great philosophers' can be described by that statement.

The purpose is relative to the source; if the source is undefinable, then so is the purpose. It could be that your only purpose on this earth to try everything and finish nothing. Only time will tell.

Best to let it come as it comes. There is no great famine in your country yet? You are not in the middle of any war or great disaster (besides beetles). So go where it leads you. It's your universe, the destination is always the same as the source.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby DST » Sun Oct 18, 2009 2:42 am

Once you learn the basics of programming and controlling actors, controlling data is your next essential step.

There are two keys to controlling data that are required in order to reduce the complexity of your projects:

1. Using mathematics instead of IF statements

2. Using functions.


Using intelligent mathematics is uber important, but much simpler than you might think.

For instance, instead of asking what the main actor is doing, you can simply use an integer that not only describes the action, but also can be used to decide the outcome. One example is a character walking speed; You could ask 'is the character ducking?" on a keypress>left, and say if yes, xvelocity=0, or if not, then xvelocity =-5;

However, if your ducking variable is an integer, and you set it to 0 on duck, or 1 on normal standing, then you could say, on keypress>left "xvelocity=-5*duck;" And the character could only move when not ducking. Its several lines of code when described by 'IF' statements, but only one short line of code when turned into a mathematical equation.



Functions are probably the most important aspect of writing a professional game. If you think of your code as a script written on a scroll, how long can the scroll get? Will you write small codes on the backs of napkins?

Functions are the equivalent of Books. After your information has reached a certain point, you need books to store the information. Not only are books easier to sort and move, but also much easier to find what you need.

As in Blargh's post, where he looked up all the ge 'how to's" and listed them in one post is a book of howto's, really, so that's what you need to do by using functions.


Function Logic
Let me explain some of the function logic for those of you who just see it as a 'global script window', as i once did.

All scripts work in the following way:

1. declare variables (reserves actual physical memory)

2. assign values to variables and setup the environment

3. perform the simulation based on the variables.

Now any script you bring inside another script is, literally, inside that script. For example:

player>timer>
Code: Select all
float i;
i=.5;
transp=i;


is the same as

player>timer>
Code: Select all
itransp(.5);


and in the global window,

Code: Select all
void itransp(float i){
transp=i;
}



The itransp code has been inserted into the script it was called in. It has its own variable and its own syntax and declarations, but beyond that, when you said 'itransp(.5); the program simply inserted that code into the draw actor you called it from.

Thus you can say things like 'changeanimation("Event actor", blah, blah); inside a function; but when you call that function, its exactly the same ,codewise, as just saying changeanimation normally.


So windows(or linux) is a script that is running function GE(); inside of it; and inside ge, its running function yourgame(); and inside your game, you're running function player(); and player is running function draw actor(). And so you can keep nesting functions inside that too. They're all pretty much the same, except they are optimized to do their specific task.
Code: Select all
void Ubuntu(ge){
  void ge(mygame){
    void mygame(player){
       void player(draw actor){
          void draw actor(....etc. etc. etc.
}
  }
    }
      }
        }


So remember, if you have 30 enemy types that all explode on death, you can write 30 DestroyAction functions (with 30 CreateActor("explosion etc) inside of them), or you can simply have one explode() function;

And if they have different explosion animations, that's no problem at all.

Code: Select all
void explode(int type){
switch(type){
case 0;
CreateActor("Smallboom");
break;
case 1:
CreateActor("mediumboom);
break;
case 2:
CreateActor("largeboom");
break;
}
}


Now functions are slightly slower than direct script; but that is irrelevant. Pretty much all programs rely on functions, because its the most logical way, just as books in a library are organized into shelves etc.

So any speed you lose from using a function script is more than returned when you arrange your game in a sensible way; Once you have a library full of books, you can read all day long, day after day. It never gets too complicated for you.

But if you have a neverending scroll, you have a problem. For starters, a library on a single scroll is a scroll 600 miles long that weighs 21,000 lbs. What are you gonna do with that?
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sun Oct 18, 2009 3:13 am

For that different explosion, you can shorter the code by sorting the explode animindex position and name from the smallest to the biggest as the type. And use the following code :
Code: Select all
char str[32];
sprintf(str,"explosion%i",type);
CreateActor("ExplosionActor",str);

Instead of using long-lined code of switch-case :D
(str is used to define the animation name)
Last edited by Bee-Ant on Sun Oct 18, 2009 3:17 am, edited 1 time in total.
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby DST » Sun Oct 18, 2009 3:16 am

Thanks, Bee! i was going to use that for an example but strings are something i'm not good with, and didn't know if i'd get the syntax right! But you showed it done in three lines, which is exactly the kind of thing i was talking about!

Simplicity is the key!

I think it's very important that new users be taught to use functions as soon as possible. They're the only way to effectively maintain control over your game and reduce the amount of redundant code you have to script. It doesn't matter if you're using Visual Studio or GE, if you don't code it properly it'll end up being a mess!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sun Oct 18, 2009 3:28 am

You're welcome :D
Struggling with the strings so many times on WB2 to my limit made me more experienced :P
Simplicity is the key huh?I dont know when that habit of yours take over my brain. Im now thinking the exact thing !
(this is because that bald dude)
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sun Oct 18, 2009 3:54 am

This isnt how I would do the function. Its done this way to make it clear to new people what it does. I would not use if(big surprise!). I will show how I would do it at the end.

Code: Select all
int isEven(int number)
{
    int result = 1;
    if((number % 2) == 0)
    {
        result = 0;
    }
    return result;
}


In this code, the first int is called the return type. You will give the function a number, and It will give one back. int number is what you are giving it, and you actually use that as a place holder, putting a real variable in there. Inside the function, the computer will pretend that number is your variable.

isEven is just the name of the function. It is just like naming a variable. Make it something is memorable, something that makes it clear what it does.

The next part is (int number) and as I said, its a place holder. You are meant to substitute you own variable, but it has to be of type integer.

After that we have an int called result, and it is given a default value of 1. this is a variable to hold our result, and the variable only exists in the function. You cannot use it anywhere else.

Next is the famous if statement, which divides the number by 2 and checks the remainder. % means divide but tell me the remainder instead of the answer. Since the remainder has to be one or zero, we know if the answer is even or not. Since it is true, the section in curly braces causes result to equal 0.nd

If it were not even, the default value of 1 persists.

The last line of our function is called the return, and it sends the value in result outside the function, to the rest of the program. That first int means that return has to be an int as well.

As DST said, this function definition will be typed into the global code. Once it is there it can be used in the program, and it even appears in the function list!

To use it, we would place this in an event under script.

Code: Select all
int friends = 57;
numberOfFriends = isEven(friends);


Yeah. thats pretty lame. I just cant think of a use for that function, buts a handy one to have. You can also use it like this.

Code: Select all
if (isEven(health))
{
    do something;
}


Another lame example. You can do better than me, right?

In the beginning I said that I would not do the function like that. Especially in the second use, its like to IFs when only one is needed. Here is the way I would form the function. It is identical in effect and used the same way in code.

Code: Select all
int isEven(int number){ return number % 2;}


We do not need the temp variable called result at all. And we dont need the if because if actually returns a one(true) or 0(false) and so does our formula "number % 2". The if is redundant.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sun Oct 18, 2009 4:23 am

If you ever begin using other programming languages, you will find that things are not in a nice neat list of functions and variables. There is a very easy way to keep track of which is which. It will even let you reuse one name several times.

What you do is give the name of the function or variable a letter that says what it really is. The name is actually called the label.

For instance, if I have a health variable, and it is an int, I call it iHealth. One look tells me that it is a integer variable.

For a float you could use r for real, but its better to use d for decimal or double.

int ihealth;
double dShields;
char[] sName;

See? You can eaily see that sName is a string.

so you would use f for functions(instead of float)

fTakeHealth() lets me know that TakeHealth() is a function. It might be a good idea to use two letters for functions to explain the return type.

fiTakeHealth like so. This function takes integer values away from health. Its up to you if you want to indicate the return type. Notice that you could use ifTakeHealth and easily cause an error with a false if.

I'm a little bit obsessed with if, arent I?

You will notice one other thing that I do in these. The names use upper case letters for words. some people like the underscore, but I dont. What I use is called camelCase. The uppercase letter forms a bump like on a camel. It makes it easier to read without extra characters. First letter is always lowercase just like the last one.

Since you were good and paid attention, I will give you my function. But I am going to change the name so that its better.

Code: Select all
int fChangeHealth(int hp, int amount) { return hp += amount; }


So you can say

Code: Select all
ihealth = fChangeHealth(ihealth, -5);

if you want damage, or...

Code: Select all
ihealth = fChangeHealth(ihealth, 5);


if you want to heal.

if you just gained a new level you can do this

Code: Select all
ihealth = fChangeHealth(ilevel*10, 0);


assuming that you get 10 hp per level.

I dont indicate the return type in my function name.

I'm done. Who is next with a trick?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sun Oct 18, 2009 6:50 pm

I want to share more, but what?
I can only share something when people ask me or when somebody post something that I could fix.
My little brain isnt capable to think what to post :P
So, anybody want to know how I done something, please let me know :D
User avatar
Bee-Ant
 
Posts: 3717
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 210 Give a positive score

PreviousNext

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron